]>
Commit | Line | Data |
---|---|---|
342b8b6e | 1 | # Bison Regressions. -*- Autotest -*- |
3c31a486 | 2 | # Copyright 2001, 2002 Free Software Foundation, Inc. |
c95f2d78 | 3 | |
342b8b6e AD |
4 | # This program is free software; you can redistribute it and/or modify |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2, or (at your option) | |
7 | # any later version. | |
c95f2d78 | 8 | |
342b8b6e AD |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
c95f2d78 | 13 | |
342b8b6e AD |
14 | # You should have received a copy of the GNU General Public License |
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
17 | # 02111-1307, USA. | |
c95f2d78 | 18 | |
342b8b6e | 19 | AT_BANNER([[Regression tests.]]) |
c95f2d78 | 20 | |
2b25d624 AD |
21 | |
22 | ## ---------------- ## | |
23 | ## Braces parsing. ## | |
24 | ## ---------------- ## | |
25 | ||
26 | ||
27 | AT_SETUP([braces parsing]) | |
28 | ||
29 | AT_DATA([input.y], | |
30 | [[/* Bison used to swallow the character after `}'. */ | |
31 | ||
32 | %% | |
bfcf1f3a | 33 | exp: { tests = {{{{{{{{{{}}}}}}}}}}; }; |
2b25d624 AD |
34 | %% |
35 | ]]) | |
36 | ||
37 | AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore) | |
38 | ||
39 | AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore]) | |
40 | ||
41 | AT_CLEANUP | |
42 | ||
43 | ||
c95f2d78 AD |
44 | ## ------------------ ## |
45 | ## Duplicate string. ## | |
46 | ## ------------------ ## | |
47 | ||
48 | ||
49 | AT_SETUP([Duplicate string]) | |
50 | ||
f499b062 | 51 | AT_DATA([input.y], |
c95f2d78 AD |
52 | [[/* `Bison -v' used to dump core when two tokens are defined with the same |
53 | string, as LE and GE below. */ | |
54 | ||
55 | %token NUM | |
56 | %token LE "<=" | |
57 | %token GE "<=" | |
58 | ||
59 | %% | |
60 | exp: '(' exp ')' | NUM ; | |
61 | %% | |
62 | ]]) | |
63 | ||
f499b062 | 64 | AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore) |
c95f2d78 | 65 | |
d803322e | 66 | AT_CLEANUP |
c95f2d78 AD |
67 | |
68 | ||
2ca209c1 AD |
69 | ## ------------------- ## |
70 | ## Rule Line Numbers. ## | |
71 | ## ------------------- ## | |
72 | ||
73 | AT_SETUP([Rule Line Numbers]) | |
74 | ||
75 | AT_DATA([input.y], | |
76 | [[%% | |
77 | expr: | |
78 | 'a' | |
79 | ||
80 | { | |
81 | ||
82 | } | |
83 | ||
84 | 'b' | |
85 | ||
86 | { | |
87 | ||
88 | } | |
89 | ||
90 | | | |
91 | ||
92 | ||
93 | { | |
94 | ||
95 | ||
96 | } | |
97 | ||
98 | 'c' | |
99 | ||
100 | { | |
101 | ||
bfcf1f3a | 102 | }; |
2ca209c1 AD |
103 | ]]) |
104 | ||
105 | AT_CHECK([bison input.y -o input.c -v], 0, [], []) | |
106 | ||
107 | # Check the contents of the report. | |
108 | AT_CHECK([cat input.output], [], | |
d2d1b42b | 109 | [[Grammar |
2ca209c1 AD |
110 | |
111 | Number, Line, Rule | |
ff442794 | 112 | 0 2 $axiom -> expr $ |
2ca209c1 AD |
113 | 1 2 @1 -> /* empty */ |
114 | 2 2 expr -> 'a' @1 'b' | |
115 | 3 15 @2 -> /* empty */ | |
116 | 4 15 expr -> @2 'c' | |
117 | ||
d2d1b42b | 118 | |
2ca209c1 AD |
119 | Terminals, with rules where they appear |
120 | ||
b365aa05 | 121 | $ (0) 0 |
2ca209c1 AD |
122 | 'a' (97) 2 |
123 | 'b' (98) 2 | |
124 | 'c' (99) 4 | |
125 | error (256) | |
126 | ||
d2d1b42b | 127 | |
2ca209c1 AD |
128 | Nonterminals, with rules where they appear |
129 | ||
b365aa05 AD |
130 | $axiom (6) |
131 | on left: 0 | |
132 | expr (7) | |
133 | on left: 2 4, on right: 0 | |
134 | @1 (8) | |
2ca209c1 | 135 | on left: 1, on right: 2 |
b365aa05 | 136 | @2 (9) |
2ca209c1 AD |
137 | on left: 3, on right: 4 |
138 | ||
139 | ||
140 | state 0 | |
141 | ||
142 | 'a' shift, and go to state 1 | |
143 | ||
610ab194 AD |
144 | $default reduce using rule 3 (@2) |
145 | ||
b365aa05 AD |
146 | expr go to state 2 |
147 | @2 go to state 3 | |
2ca209c1 AD |
148 | |
149 | ||
150 | ||
151 | state 1 | |
152 | ||
153 | expr -> 'a' . @1 'b' (rule 2) | |
154 | ||
155 | $default reduce using rule 1 (@1) | |
156 | ||
b365aa05 | 157 | @1 go to state 4 |
2ca209c1 AD |
158 | |
159 | ||
160 | ||
161 | state 2 | |
162 | ||
b365aa05 | 163 | $axiom -> expr . $ (rule 0) |
2ca209c1 | 164 | |
b365aa05 | 165 | $ shift, and go to state 5 |
2ca209c1 AD |
166 | |
167 | ||
168 | ||
169 | state 3 | |
170 | ||
b365aa05 | 171 | expr -> @2 . 'c' (rule 4) |
2ca209c1 | 172 | |
b365aa05 | 173 | 'c' shift, and go to state 6 |
2ca209c1 AD |
174 | |
175 | ||
176 | ||
177 | state 4 | |
178 | ||
b365aa05 | 179 | expr -> 'a' @1 . 'b' (rule 2) |
2ca209c1 | 180 | |
b365aa05 | 181 | 'b' shift, and go to state 7 |
2ca209c1 AD |
182 | |
183 | ||
184 | ||
185 | state 5 | |
186 | ||
b365aa05 | 187 | $axiom -> expr $ . (rule 0) |
2ca209c1 | 188 | |
b365aa05 | 189 | $default accept |
2ca209c1 AD |
190 | |
191 | ||
192 | state 6 | |
193 | ||
b365aa05 AD |
194 | expr -> @2 'c' . (rule 4) |
195 | ||
196 | $default reduce using rule 4 (expr) | |
2ca209c1 AD |
197 | |
198 | ||
199 | ||
200 | state 7 | |
201 | ||
b365aa05 AD |
202 | expr -> 'a' @1 'b' . (rule 2) |
203 | ||
204 | $default reduce using rule 2 (expr) | |
205 | ||
d2d1b42b AD |
206 | |
207 | ||
2ca209c1 AD |
208 | ]]) |
209 | ||
210 | AT_CLEANUP | |
211 | ||
212 | ||
213 | ||
cd5aafcf AD |
214 | ## ---------------------- ## |
215 | ## Mixing %token styles. ## | |
216 | ## ---------------------- ## | |
217 | ||
218 | ||
219 | AT_SETUP([Mixing %token styles]) | |
220 | ||
221 | # Taken from the documentation. | |
222 | AT_DATA([input.y], | |
223 | [[%token <operator> OR "||" | |
224 | %token <operator> LE 134 "<=" | |
225 | %left OR "<=" | |
226 | %% | |
227 | exp: ; | |
228 | %% | |
229 | ]]) | |
230 | ||
231 | AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore) | |
232 | ||
d803322e | 233 | AT_CLEANUP |
cd5aafcf AD |
234 | |
235 | ||
236 | ||
29ae55f1 AD |
237 | ## ---------------- ## |
238 | ## Invalid inputs. ## | |
239 | ## ---------------- ## | |
561f9a30 AD |
240 | |
241 | ||
29ae55f1 | 242 | AT_SETUP([Invalid inputs]) |
561f9a30 AD |
243 | |
244 | AT_DATA([input.y], | |
245 | [[%% | |
246 | ? | |
561f9a30 | 247 | default: 'a' } |
29ae55f1 AD |
248 | %{ |
249 | %& | |
250 | %a | |
251 | %- | |
561f9a30 AD |
252 | ]]) |
253 | ||
254 | AT_CHECK([bison input.y], [1], [], | |
29ae55f1 AD |
255 | [[input.y:2: invalid input: `?' |
256 | input.y:3: invalid input: `}' | |
257 | input.y:4: invalid input: `%{' | |
258 | input.y:5: invalid input: `%&' | |
259 | input.y:6: invalid input: `%a' | |
260 | input.y:7: invalid input: `%-' | |
e0c40012 AD |
261 | ]]) |
262 | ||
263 | AT_CLEANUP | |
264 | ||
265 | ||
266 | ||
267 | ## -------------------- ## | |
268 | ## Invalid %directive. ## | |
269 | ## -------------------- ## | |
270 | ||
271 | ||
272 | AT_SETUP([Invalid %directive]) | |
273 | ||
274 | AT_DATA([input.y], | |
275 | [[%invalid | |
276 | ]]) | |
277 | ||
278 | AT_CHECK([bison input.y], [1], [], | |
279 | [[input.y:1: unrecognized: %invalid | |
280 | input.y:1: Skipping to next % | |
281 | input.y:2: fatal error: no input grammar | |
282 | ]]) | |
561f9a30 AD |
283 | |
284 | AT_CLEANUP | |
285 | ||
286 | ||
270a173c | 287 | |
b9752825 AD |
288 | ## -------------- ## |
289 | ## Web2c Report. ## | |
290 | ## -------------- ## | |
776209d6 AD |
291 | |
292 | # The generation of the reduction was once wrong in Bison, and made it | |
293 | # miss some reductions. In the following test case, the reduction on | |
294 | # `undef_id_tok' in state 1 was missing. This is stripped down from | |
295 | # the actual web2c.y. | |
296 | ||
b9752825 | 297 | AT_SETUP([Web2c Report]) |
776209d6 AD |
298 | |
299 | AT_DATA([input.y], | |
300 | [[%token undef_id_tok const_id_tok | |
301 | ||
302 | %start CONST_DEC_PART | |
303 | \f | |
304 | %% | |
305 | CONST_DEC_PART: | |
306 | CONST_DEC_LIST | |
307 | ; | |
308 | ||
309 | CONST_DEC_LIST: | |
310 | CONST_DEC | |
311 | | CONST_DEC_LIST CONST_DEC | |
312 | ; | |
313 | ||
314 | CONST_DEC: | |
315 | { } undef_id_tok '=' const_id_tok ';' | |
316 | ; | |
317 | %% | |
318 | ||
319 | ]]) | |
320 | ||
321 | AT_CHECK([bison -v input.y]) | |
322 | ||
323 | AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0, | |
324 | [[Grammar | |
325 | Number, Line, Rule | |
78d5bae9 | 326 | 0 6 $axiom -> CONST_DEC_PART $ |
776209d6 AD |
327 | 1 6 CONST_DEC_PART -> CONST_DEC_LIST |
328 | 2 10 CONST_DEC_LIST -> CONST_DEC | |
329 | 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC | |
330 | 4 15 @1 -> /* empty */ | |
331 | 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' | |
332 | Terminals, with rules where they appear | |
78d5bae9 | 333 | $ (0) 0 |
776209d6 AD |
334 | ';' (59) 5 |
335 | '=' (61) 5 | |
336 | error (256) | |
337 | undef_id_tok (257) 5 | |
338 | const_id_tok (258) 5 | |
339 | Nonterminals, with rules where they appear | |
78d5bae9 AD |
340 | $axiom (7) |
341 | on left: 0 | |
342 | CONST_DEC_PART (8) | |
343 | on left: 1, on right: 0 | |
344 | CONST_DEC_LIST (9) | |
776209d6 | 345 | on left: 2 3, on right: 1 3 |
78d5bae9 | 346 | CONST_DEC (10) |
776209d6 | 347 | on left: 5, on right: 2 3 |
78d5bae9 | 348 | @1 (11) |
776209d6 AD |
349 | on left: 4, on right: 5 |
350 | state 0 | |
351 | $default reduce using rule 4 (@1) | |
78d5bae9 AD |
352 | CONST_DEC_PART go to state 1 |
353 | CONST_DEC_LIST go to state 2 | |
354 | CONST_DEC go to state 3 | |
355 | @1 go to state 4 | |
776209d6 | 356 | state 1 |
78d5bae9 AD |
357 | $axiom -> CONST_DEC_PART . $ (rule 0) |
358 | $ shift, and go to state 5 | |
359 | state 2 | |
776209d6 AD |
360 | CONST_DEC_PART -> CONST_DEC_LIST . (rule 1) |
361 | CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3) | |
362 | undef_id_tok reduce using rule 4 (@1) | |
363 | $default reduce using rule 1 (CONST_DEC_PART) | |
78d5bae9 AD |
364 | CONST_DEC go to state 6 |
365 | @1 go to state 4 | |
366 | state 3 | |
776209d6 AD |
367 | CONST_DEC_LIST -> CONST_DEC . (rule 2) |
368 | $default reduce using rule 2 (CONST_DEC_LIST) | |
776209d6 | 369 | state 4 |
78d5bae9 AD |
370 | CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5) |
371 | undef_id_tok shift, and go to state 7 | |
372 | state 5 | |
373 | $axiom -> CONST_DEC_PART $ . (rule 0) | |
374 | $default accept | |
375 | state 6 | |
776209d6 AD |
376 | CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3) |
377 | $default reduce using rule 3 (CONST_DEC_LIST) | |
78d5bae9 | 378 | state 7 |
776209d6 | 379 | CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5) |
78d5bae9 AD |
380 | '=' shift, and go to state 8 |
381 | state 8 | |
776209d6 | 382 | CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5) |
78d5bae9 AD |
383 | const_id_tok shift, and go to state 9 |
384 | state 9 | |
776209d6 | 385 | CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5) |
78d5bae9 AD |
386 | ';' shift, and go to state 10 |
387 | state 10 | |
776209d6 AD |
388 | CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5) |
389 | $default reduce using rule 5 (CONST_DEC) | |
776209d6 AD |
390 | ]]) |
391 | ||
392 | AT_CLEANUP | |
b9752825 AD |
393 | |
394 | ||
395 | ## --------------- ## | |
396 | ## Web2c Actions. ## | |
397 | ## --------------- ## | |
398 | ||
399 | # The generation of the mapping `state -> action' was once wrong in | |
400 | # extremely specific situations. web2c.y exhibits this situation. | |
401 | # Below is a stripped version of the grammar. It looks like one can | |
402 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
403 | # which disapears when applying sane grammar transformations. | |
404 | # | |
405 | # It used to be wrong on yydefact only: | |
406 | # | |
407 | # static const short yydefact[] = | |
408 | # { | |
409 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
410 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
411 | # 0, 0 | |
412 | # }; | |
413 | # | |
414 | # but let's check all the tables. | |
415 | ||
416 | ||
417 | AT_SETUP([Web2c Actions]) | |
418 | ||
419 | AT_DATA([input.y], | |
420 | [[%% | |
421 | statement: struct_stat; | |
422 | struct_stat: /* empty. */ | if else; | |
423 | if: "if" "const" "then" statement; | |
424 | else: "else" statement; | |
425 | %% | |
426 | ]]) | |
427 | ||
428 | AT_CHECK([bison -v input.y -o input.c]) | |
429 | ||
430 | # Check only the tables. We don't use --no-parser, because it is | |
431 | # still to be implemented in the experimental branch of Bison. | |
432 | AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0, | |
433 | [[static const char yytranslate[] = | |
434 | { | |
435 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
436 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
437 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
438 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
439 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
440 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
441 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
442 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
443 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
444 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
445 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
446 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
447 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
448 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
449 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
450 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
451 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
452 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
453 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
454 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
455 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
456 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
457 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
458 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
459 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
460 | 2, 2, 2, 2, 2, 2, 1, 3, 4, 5, | |
461 | 6 | |
462 | }; | |
463 | static const short yyprhs[] = | |
464 | { | |
e7b8bef1 | 465 | 0, 0, 3, 5, 6, 9, 14 |
b9752825 AD |
466 | }; |
467 | static const short yyrhs[] = | |
468 | { | |
e7b8bef1 AD |
469 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, |
470 | 4, 5, 8, -1, 6, 8, -1 | |
b9752825 AD |
471 | }; |
472 | static const short yyrline[] = | |
473 | { | |
e7b8bef1 | 474 | 0, 2, 2, 3, 3, 4, 5 |
b9752825 AD |
475 | }; |
476 | static const char *const yytname[] = | |
477 | { | |
478 | "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"", | |
80cce3da | 479 | "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0 |
b9752825 AD |
480 | }; |
481 | static const short yytoknum[] = | |
482 | { | |
483 | 0, 256, 2, 257, 258, 259, 260, -1 | |
484 | }; | |
485 | static const short yyr1[] = | |
486 | { | |
e7b8bef1 | 487 | 0, 7, 8, 9, 9, 10, 11 |
b9752825 AD |
488 | }; |
489 | static const short yyr2[] = | |
490 | { | |
e7b8bef1 | 491 | 0, 2, 1, 0, 2, 4, 2 |
b9752825 AD |
492 | }; |
493 | static const short yydefact[] = | |
494 | { | |
e7b8bef1 AD |
495 | 3, 0, 0, 2, 0, 0, 0, 3, 4, 3, |
496 | 6, 5 | |
b9752825 AD |
497 | }; |
498 | static const short yydefgoto[] = | |
499 | { | |
e7b8bef1 | 500 | -1, 2, 3, 4, 8 |
b9752825 AD |
501 | }; |
502 | static const short yypact[] = | |
503 | { | |
e7b8bef1 AD |
504 | -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2, |
505 | -32768,-32768 | |
b9752825 AD |
506 | }; |
507 | static const short yypgoto[] = | |
508 | { | |
e7b8bef1 | 509 | -32768, -7,-32768,-32768,-32768 |
b9752825 AD |
510 | }; |
511 | static const short yytable[] = | |
512 | { | |
e7b8bef1 | 513 | 10, 1, 11, 5, 6, 0, 7, 9 |
b9752825 AD |
514 | }; |
515 | static const short yycheck[] = | |
516 | { | |
e7b8bef1 | 517 | 7, 3, 9, 4, 0, -1, 6, 5 |
b9752825 AD |
518 | }; |
519 | ]]) | |
520 | ||
521 | AT_CLEANUP |