checkpoint
[sbp.git] / tests / regression.tc
1 //testcase {
2 //    input  "x";
3 //    output "a1:{x}";
4 //
5 //    s ::= a        => a1
6 //    a ::= s        => s1
7 //    a ::= ^"x"
8 //}
9 //
10 //testcase {
11 //    input  "x";
12 //    output "x";
13 //    output "s2:{s2:{s0 s0} x}";
14 //    output "s2:{s0 x}";
15 //
16 //
17 //    s ::= s s      => s2
18 //    s ::= ^"x"
19 //    s ::= ()       => s0
20 //}
21
22 //tibcase {
23 //    input "
24 //  hello 
25 //    there
26 //    how
27 //     { are }
28 //";
29 //
30 //    s        ::= ws S ws
31 //    ws      !::= w*
32 //    S        ::= { Hello }
33 //    Hello    ::= "hello" { "there" "how" { "are" } }
34 //}
35
36 testcase {
37     input "ab c";
38     output "1:{{a b} {c}}";
39
40     s   ::= ids
41     ids ::= id (" " ids &~ id [~]*) => "1"
42           | id (    ids &~ id [~]*) => "2"
43           | id
44     id  ::= [a-z]++
45 }
46
47 testcase {
48     input "ab c";
49
50     output "2:{{a} 1:{{b} {c}}}";
51     output "1:{{a b} {c}}";
52
53     s   ::= ids
54     ids ::= id " " ids => "1"
55           | id     ids => "2"
56           | id
57     id  ::= [a-z]+
58 }
59
60 testcase {
61     input "aaabbbccc";
62     output "";
63
64     s   ::= ab & dc
65     ab  ::= a b
66     dc  ::= d c
67     a   ::= "a" a     | ()
68     b   ::= "b" b "c" | ()
69     c   ::= "c" c     | ()
70     d   ::= "a" d "b" | ()
71 }
72
73 testcase {
74     input "aaabbbbccc";
75
76     s   ::= ab & dc
77     ab !::= a b
78     dc !::= d c
79     a   ::= "a" a     | ()
80     b   ::= "b" b "c" | ()
81     c   ::= "c" c     | ()
82     d   ::= "a" d "b" | ()
83 }
84
85 testcase {
86     input "12111211";
87     output "ac:{{2 1 2 1}}";
88     //output "a:{{2 1 2 1}}";
89     //output "c:{{c:{1 1} c:{1 1}}}";
90
91     s ::= ab => "ab"
92         | ac => "ac"
93         | bc => "bc"
94         //| a  =>  "a"
95         //| b  =>  "b"
96         //| c  =>  "c"
97     ab ::= a & b
98     ac ::= a & c
99     bc ::= b & c
100     a ::= ("1" x)*
101     b ::= (x "2" => "b")*
102     c ::= (x "2" x "1" => "c")*
103     x ::= [123]
104 }
105
106 testcase {
107     input  "xbambambam";
108     output "bam:{a bam:{a bam:{a x}}}";
109
110     s ::= a s ^"bam"
111     s ::= ^"x"
112     a ::= ()       => "a"
113 }
114
115 testcase {
116     input  "baaaa";
117     output "s2:{b0 a:{a:{epsilon}}}";
118     output "b:{a:{a:{epsilon}} epsilon}";
119     s ::= b t        => "s2"
120         | ^"b" t b
121     t ::= ^"a" t "a"
122         | ()         => "epsilon"
123     b ::= "b"        => "b0"
124         | ()         => "epsilon"
125 }
126
127 testcase {
128     input  "qaq";
129     output "q:{a:{s1:{epsilon}}}";
130
131     s ::= ^"q" x "q"
132     x ::= ^"a" a
133     x ::= ()        => "epsilon"
134     a ::= x         => "s1"
135 }
136
137 testcase {
138     input "baa";
139     output "s1:{a2:{a2:{a0 b0} b0}}";
140
141     s ::= "b" a     => "s1"
142     a ::= "a" a b   => "a2"
143         | ()        => "a0"
144     b ::= ()        => "b0"
145 }
146
147 testcase {
148     input  "aaa";
149
150     output "s3:{s3:{epsilon a0 epsilon epsilon} epsilon epsilon epsilon}";
151     output "s3:{s3:{epsilon epsilon epsilon epsilon} a0 epsilon epsilon}";
152     output "s3:{s3:{epsilon epsilon a0 epsilon} epsilon epsilon epsilon}";
153     output "s3:{s3:{epsilon epsilon epsilon a0} epsilon epsilon epsilon}";
154     output "s3:{epsilon epsilon a0 a0}";
155     output "s3:{s3:{s3:{epsilon epsilon epsilon epsilon} epsilon epsilon epsilon} epsilon epsilon epsilon}";
156     output "s3:{s3:{epsilon epsilon epsilon epsilon} epsilon epsilon a0}";
157     output "s3:{s3:{epsilon epsilon epsilon epsilon} epsilon a0 epsilon}";
158     output "s3:{epsilon a0 epsilon a0}";
159     output "s3:{epsilon a0 a0 epsilon}";
160
161     s ::= "a" s a a a => "s3"
162         | ()          => "epsilon"
163     a ::= "a"         => "a0"
164         | ()          => "epsilon"
165 }
166
167 testcase {
168     input "aa";
169     output "poo:{poo:{poox poox} poox}";
170     output "poo:{poox poo:{poox poox}}";
171     s ::= s s "a"  => "poo"
172         | ()       => "poox"
173 }
174
175 testcase {
176     input "baa";
177     output "s:{aa:{aa:{a b} b}}";
178     s ::= "b" a      => "s"
179     a ::= "a" a b    => "aa"
180     a ::= ()         => "a"
181     b ::= ()         => "b"
182 }
183
184 testcase {
185     input "aaab";
186     output "sx:{b aa:{aa:{b b} b}}";
187     s ::= b d "a" "b"  => "sx"
188     s ::= "a" d "a" d  => "sy"
189     d ::= "a" a b      => "aa"
190     a ::= "a" b b      => "aa"
191     a ::= ()           => "a"
192     b ::= ()           => "b"
193 }
194
195 testcase {
196     input "a+(b*c)";
197     output "+:{{a} *:{{b} {c}}}";
198
199     s   ::= r
200     r   ::= id
201           | r ^"*" r
202           | r ^"+" r
203           | "(" r ")"
204     id  ::= [a-z]++
205 }
206
207 testcase {
208     input "a+b-d*c";
209     output "plus:{stringify:{{a}} minus:{stringify:{{b}} times:{stringify:{{d}} stringify:{{c}}}}}";
210     output "times:{plus:{stringify:{{a}} minus:{stringify:{{b}} stringify:{{d}}}} stringify:{{c}}}";
211     output "plus:{stringify:{{a}} times:{minus:{stringify:{{b}} stringify:{{d}}} stringify:{{c}}}}";
212     output "times:{minus:{plus:{stringify:{{a}} stringify:{{b}}} stringify:{{d}}} stringify:{{c}}}";
213     output "minus:{plus:{stringify:{{a}} stringify:{{b}}} times:{stringify:{{d}} stringify:{{c}}}}";
214     w  ::= " "
215     l  ::= id
216     s  ::= l "=" q  => "assign"
217          | q
218     q  ::= id
219          | l "=" q       => "assign"
220          | q "-" q       => "minus"
221          | q "+" q       => "plus"
222          | q "*" q       => "times"
223          | "(" q ")"
224     id   ::= idl++       => "stringify"
225     idl  ::= [a-d]
226 }
227
228 testcase {
229     input "a*b*c";
230     output "times:{stringify:{{a}} times:{stringify:{{b}} stringify:{{c}}}}";
231     w  ::= " "
232     l  ::= id
233     s  ::= l "=" r  => "assign"
234          | r
235     r  ::= l
236          | l "=" r       => "assign"
237          | r "+" r       => "plus"
238          | (r) "*" r       => "times"
239          | "(" r ")"
240          | r r           => "times"
241     id   ::= idl++       => "stringify"
242     idl  ::= [a-d]
243 }
244
245 testcase {
246     input "a+b*c";
247     output "plus:{stringify:{{a}} times:{stringify:{{b}} stringify:{{c}}}}";
248     w  ::= " "
249     l  ::= id
250     s  ::= l "=" r  => "assign"
251          | r
252     r  ::= l
253          | l "=" r       => "assign"
254          | r "+" r       => "plus"
255          > r "*" r       => "times"
256          | "(" r ")"
257          | r r           => "times"
258     id   ::= idl++       => "stringify"
259     idl  ::= [a-d]
260 }
261
262 testcase {
263
264     input "
265
266
267  while x>0
268    while y>0
269     foo()
270      bar()
271
272  while x>0
273    while y>0
274     foo()
275    bar()
276
277
278 ";
279     output "smt:{while:{>:{{x} {0}} while:{>:{{y} {0}} sbb:{{f o o} {b a r}}}}}";
280     output "smt:{while:{>:{{x} {0}} sbb:{while:{>:{{y} {0}} {f o o}} {b a r}}}}";
281
282 indent  !::= ww
283 outdent !::= " "  outdent " "
284            | " "  ([~]*)  "\n"
285
286 any      !::= [~]*
287 s         ::= !any "\n\n" !ww statement !ww "\n\n" !any => smt
288 ww        ::= sp*
289 ws       !::= sp**
290 sp        ::= " "
291
292 block     ::= "\n" !indent  blockBody
293            &~ "\n" outdent [~\ ] [~]*
294
295 blockBody ::= statement
296             > statement blockBody /ws => "sbb"
297
298 statement ::= call
299             | ^"while" expr block /ws
300
301 expr      ::= ident
302             | call
303             | expr ^">" expr   /ws
304             | num
305
306 call      ::= expr "()"        /ws
307
308 num       ::= [0-9]++
309
310 ident     ::= [a-z]++ &~ keyword
311 keyword   ::= "if" | "then" | "else" | "while"
312
313 w         ::= " " | "\n" | "\r"
314 ws        ::= w*
315
316
317 }