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