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