17 | 17 |
Sequence.
|
18 | 18 |
|
19 | 19 |
Goal ::= "f" "o" "o";
|
20 | |
===> Grammar [("Goal",[],Alt [Seq [Terminal 'f',Terminal 'o',Terminal 'o']])]
|
|
20 |
===> Goal ::= (("f" "o" "o"));
|
21 | 21 |
|
22 | 22 |
Multi-character terminals.
|
23 | 23 |
|
24 | 24 |
Goal ::= "foo" "bar";
|
25 | |
===> Grammar [("Goal",[],Alt [Seq [Terminal 'f',Terminal 'o',Terminal 'o',Terminal 'b',Terminal 'a',Terminal 'r']])]
|
|
25 |
===> Goal ::= (("f" "o" "o" "b" "a" "r"));
|
26 | 26 |
|
27 | 27 |
Alternation and recursion.
|
28 | 28 |
|
29 | 29 |
Goal ::= "(" Goal ")" | "0";
|
30 | |
===> Grammar [("Goal",[],Alt [Seq [Terminal '(',NonTerminal "Goal" [],Terminal ')'],Seq [Terminal '0']])]
|
|
30 |
===> Goal ::= (("(" Goal ")") | ("0"));
|
31 | 31 |
|
32 | 32 |
Repetition.
|
33 | 33 |
|
34 | 34 |
Goal ::= "(" {"0"} ")";
|
35 | |
===> Grammar [("Goal",[],Alt [Seq [Terminal '(',Loop (Alt [Seq [Terminal '0']]) [],Terminal ')']])]
|
|
35 |
===> Goal ::= (("(" {(("0"))} ")"));
|
36 | 36 |
|
37 | 37 |
Constraints.
|
38 | 38 |
|
|
41 | 41 |
<. b = 0 .> { "b" <. b += 1 .> } <. b = n .>
|
42 | 42 |
<. c = 0 .> { "c" <. c += 1 .> } <. c = n .>
|
43 | 43 |
;
|
44 | |
===> Grammar [("Goal",[],Alt [Seq [Constraint (UnifyConst (Var "a") 0),Loop (Alt [Seq [Terminal 'a',Constraint (Inc (Var "a") (CInt 1))]]) [],Constraint (UnifyVar (Var "a") (Var "n")),Constraint (UnifyConst (Var "b") 0),Loop (Alt [Seq [Terminal 'b',Constraint (Inc (Var "b") (CInt 1))]]) [],Constraint (UnifyVar (Var "b") (Var "n")),Constraint (UnifyConst (Var "c") 0),Loop (Alt [Seq [Terminal 'c',Constraint (Inc (Var "c") (CInt 1))]]) [],Constraint (UnifyVar (Var "c") (Var "n"))]])]
|
|
44 |
===> Goal ::= ((<. a = 0 .> {(("a" <. a += 1 .>))} <. a = n .> <. b = 0 .> {(("b" <. b += 1 .>))} <. b = n .> <. c = 0 .> {(("c" <. c += 1 .>))} <. c = n .>));
|
45 | 45 |
|
46 | 46 |
Parameters and multiple productions.
|
47 | 47 |
|
48 | 48 |
Goal ::= "Hi" Sp<a> "there" Sp<b> "world" "!";
|
49 | 49 |
Sp<n> ::= <. n = 0 .> { " " <. n += 1 .> } <. n > 0 .>;
|
50 | |
===> Grammar [("Goal",[],Alt [Seq [Terminal 'H',Terminal 'i',NonTerminal "Sp" [Var "a"],Terminal 't',Terminal 'h',Terminal 'e',Terminal 'r',Terminal 'e',NonTerminal "Sp" [Var "b"],Terminal 'w',Terminal 'o',Terminal 'r',Terminal 'l',Terminal 'd',Terminal '!']]),("Sp",[Var "n"],Alt [Seq [Constraint (UnifyConst (Var "n") 0),Loop (Alt [Seq [Terminal ' ',Constraint (Inc (Var "n") (CInt 1))]]) [],Constraint (GreaterThan (Var "n") (CInt 0))]])]
|
|
50 |
===> Goal ::= (("H" "i" Sp<a> "t" "h" "e" "r" "e" Sp<b> "w" "o" "r" "l" "d" "!"));
|
|
51 |
===> Sp<n> ::= ((<. n = 0 .> {((" " <. n += 1 .>))} <. n > 0 .>));
|
51 | 52 |
|
52 | 53 |
Comments.
|
53 | 54 |
|
|
61 | 62 |
//
|
62 | 63 |
// There are many ways to place comments.
|
63 | 64 |
"//";
|
64 | |
===> Grammar [("Goal",[],Alt [Seq [Terminal 'f',Terminal 'o',Terminal 'o']]),("A",[],Alt [Seq [Terminal 'f',Terminal 'o',Terminal '/',Terminal '/']])]
|
|
65 |
===> Goal ::= (("f" "o" "o"));
|
|
66 |
===> A ::= (("f" "o" "/" "/"));
|
65 | 67 |
|
66 | 68 |
Misplaced semicolon is a syntax error.
|
67 | 69 |
|
|
78 | 80 |
Sequence.
|
79 | 81 |
|
80 | 82 |
Goal ::= "f" "o" "o";
|
81 | |
===> Grammar [("Goal",[],Seq [Terminal 'f',Terminal 'o',Terminal 'o'])]
|
|
83 |
===> Goal ::= ("f" "o" "o");
|
82 | 84 |
|
83 | 85 |
Alternation and recursion.
|
84 | 86 |
|
85 | 87 |
Goal ::= "(" Goal ")" | "0";
|
86 | |
===> Grammar [("Goal",[],Alt [Seq [Terminal '(',NonTerminal "Goal" [],Terminal ')'],Seq [Terminal '0']])]
|
|
88 |
===> Goal ::= (("(" Goal ")") | ("0"));
|
87 | 89 |
|
88 | 90 |
Repetition.
|
89 | 91 |
|
90 | 92 |
Goal ::= "(" {"0"} ")";
|
91 | |
===> Grammar [("Goal",[],Seq [Terminal '(',Loop (Seq [Terminal '0']) [],Terminal ')'])]
|
|
93 |
===> Goal ::= ("(" {("0")} ")");
|
92 | 94 |
|
93 | 95 |
Goal ::=
|
94 | 96 |
<. a = 0 .> { "a" <. a += 1 .> } <. a = n .>
|
95 | 97 |
<. b = 0 .> { "b" <. b += 1 .> } <. b = n .>
|
96 | 98 |
<. c = 0 .> { "c" <. c += 1 .> } <. c = n .>
|
97 | 99 |
;
|
98 | |
===> Grammar [("Goal",[],Seq [Constraint (UnifyConst (Var "a") 0),Loop (Seq [Terminal 'a',Constraint (Inc (Var "a") (CInt 1))]) [UnifyVar (Var "a") (Var "n"),UnifyConst (Var "b") 0],Loop (Seq [Terminal 'b',Constraint (Inc (Var "b") (CInt 1))]) [UnifyVar (Var "b") (Var "n"),UnifyConst (Var "c") 0],Loop (Seq [Terminal 'c',Constraint (Inc (Var "c") (CInt 1))]) [UnifyVar (Var "c") (Var "n")]])]
|
|
100 |
===> Goal ::= (<. a = 0 .> {("a" <. a += 1 .>)} {("b" <. b += 1 .>)} {("c" <. c += 1 .>)});
|