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