Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
|
|
@ -0,0 +1,65 @@
|
|||
// Literal
|
||||
rascal>123 := 123
|
||||
bool: true
|
||||
|
||||
// VariableDeclaration
|
||||
rascal>if(str S := "abc")
|
||||
>>>>>>> println("Match succeeds, S == \"<S>\"");
|
||||
Match succeeds, S == "abc"
|
||||
ok
|
||||
|
||||
// MultiVariable
|
||||
rascal>if([10, N*, 50] := [10, 20, 30, 40, 50])
|
||||
>>>>>>> println("Match succeeds, N == <N>");
|
||||
Match succeeds, N == [20,30,40]
|
||||
ok
|
||||
|
||||
// Variable
|
||||
rascal>N = 10;
|
||||
int: 10
|
||||
rascal>N := 10;
|
||||
bool: true
|
||||
rascal>N := 20;
|
||||
bool: false
|
||||
|
||||
// Set and List
|
||||
rascal>if({10, set[int] S, 50} := {50, 40, 30, 20, 10})
|
||||
>>>>>>> println("Match succeeded, S = <S>");
|
||||
Match succeeded, S = {30,40,20}
|
||||
ok
|
||||
|
||||
rascal>for([L1*, L2*] := [10, 20, 30, 40, 50])
|
||||
>>>>>>> println("<L1> and <L2>");
|
||||
[] and [10,20,30,40,50]
|
||||
[10] and [20,30,40,50]
|
||||
[10,20] and [30,40,50]
|
||||
[10,20,30] and [40,50]
|
||||
[10,20,30,40] and [50]
|
||||
[10,20,30,40,50] and []
|
||||
list[void]: []
|
||||
|
||||
// Descendant
|
||||
rascal>T = red(red(black(leaf(1), leaf(2)), black(leaf(3), leaf(4))), black(leaf(5), leaf(4)));
|
||||
rascal>for(/black(_,leaf(4)) := T)
|
||||
>>>>>>> println("Match!");
|
||||
Match!
|
||||
Match!
|
||||
list[void]: []
|
||||
|
||||
rascal>for(/black(_,leaf(int N)) := T)
|
||||
>>>>>>> println("Match <N>");
|
||||
Match 2
|
||||
Match 4
|
||||
Match 4
|
||||
list[void]: []
|
||||
|
||||
rascal>for(/int N := T)
|
||||
>>>>>>> append N;
|
||||
list[int]: [1,2,3,4,5,4]
|
||||
|
||||
// Labelled
|
||||
rascal>for(/M:black(_,leaf(4)) := T)
|
||||
>>>>>>> println("Match <M>");
|
||||
Match black(leaf(3),leaf(4))
|
||||
Match black(leaf(5),leaf(4))
|
||||
list[void]: []
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
// Quoted pattern
|
||||
` Token1 Token2 ... Tokenn `
|
||||
// A typed quoted pattern
|
||||
(Symbol) ` Token1 Token2 ... TokenN `
|
||||
// A typed variable pattern
|
||||
<Type Var>
|
||||
// A variable pattern
|
||||
<Var>
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
// Define ColoredTrees with red and black nodes and integer leaves
|
||||
data ColoredTree = leaf(int N)
|
||||
| red(ColoredTree left, ColoredTree right)
|
||||
| black(ColoredTree left, ColoredTree right);
|
||||
|
||||
// Count the number of black nodes
|
||||
public int cntBlack(ColoredTree t){
|
||||
int c = 0;
|
||||
visit(t) {
|
||||
case black(_,_): c += 1;
|
||||
};
|
||||
return c;
|
||||
}
|
||||
|
||||
// Returns if a tree is balanced
|
||||
public bool balance(ColoredTree t){
|
||||
visit(t){
|
||||
case black(a,b): if (cntBlack(a) == cntBlack(b)) true; else return false;
|
||||
case red(a,b): if (cntBlack(a) == cntBlack(b)) true; else return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Compute the sum of all integer leaves
|
||||
public int addLeaves(ColoredTree t){
|
||||
int c = 0;
|
||||
visit(t) {
|
||||
case leaf(int N): c += N;
|
||||
};
|
||||
return c;
|
||||
}
|
||||
|
||||
// Add green nodes to ColoredTree
|
||||
data ColoredTree = green(ColoredTree left, ColoredTree right);
|
||||
|
||||
// Transform red nodes into green nodes
|
||||
public ColoredTree makeGreen(ColoredTree t){
|
||||
return visit(t) {
|
||||
case red(l, r) => green(l, r)
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
rascal>/XX/i := "some xx";
|
||||
bool: true
|
||||
rascal>/a.c/ := "abc";
|
||||
bool: true
|
||||
Loading…
Add table
Add a link
Reference in a new issue