]> git.saurik.com Git - bison.git/blob - tests/regression.at
* src/getargs.c (AS_FILE_NAME): New.
[bison.git] / tests / regression.at
1 # Bison Regressions. -*- Autotest -*-
2 # Copyright 2001 Free Software Foundation, Inc.
3
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.
8
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.
13
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.
18
19 AT_BANNER([[Regression tests.]])
20
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 %%
33 exp: { tests = {{{{{{{{{{}}}}}}}}}}; }
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
44 ## ------------------ ##
45 ## Duplicate string. ##
46 ## ------------------ ##
47
48
49 AT_SETUP([Duplicate string])
50
51 AT_DATA([input.y],
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
64 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
65
66 AT_CLEANUP
67
68
69 ## ------------------------- ##
70 ## Unresolved SR Conflicts. ##
71 ## ------------------------- ##
72
73 AT_SETUP([Unresolved SR Conflicts])
74
75 AT_DATA([input.y],
76 [[%token NUM OP
77 %%
78 exp: exp OP exp | NUM;
79 ]])
80
81 AT_CHECK([bison input.y -o input.c -v], 0, [],
82 [input.y contains 1 shift/reduce conflict.
83 ])
84
85 # Check the contents of the report.
86 AT_CHECK([cat input.output], [],
87 [[State 5 contains 1 shift/reduce conflict.
88
89
90 Grammar
91
92 Number, Line, Rule
93 0 3 $axiom -> exp $
94 1 3 exp -> exp OP exp
95 2 3 exp -> NUM
96
97
98 Terminals, with rules where they appear
99
100 $ (0) 0
101 error (256)
102 NUM (257) 2
103 OP (258) 1
104
105
106 Nonterminals, with rules where they appear
107
108 $axiom (5)
109 on left: 0
110 exp (6)
111 on left: 1 2, on right: 0 1
112
113
114 state 0
115
116 NUM shift, and go to state 1
117
118 exp go to state 2
119
120
121
122 state 1
123
124 exp -> NUM . (rule 2)
125
126 $default reduce using rule 2 (exp)
127
128
129
130 state 2
131
132 $axiom -> exp . $ (rule 0)
133 exp -> exp . OP exp (rule 1)
134
135 $ shift, and go to state 3
136 OP shift, and go to state 4
137
138
139
140 state 3
141
142 $axiom -> exp $ . (rule 0)
143
144 $default accept
145
146
147 state 4
148
149 exp -> exp OP . exp (rule 1)
150
151 NUM shift, and go to state 1
152
153 exp go to state 5
154
155
156
157 state 5
158
159 exp -> exp . OP exp (rule 1)
160 exp -> exp OP exp . (rule 1)
161
162 OP shift, and go to state 4
163
164 OP [reduce using rule 1 (exp)]
165 $default reduce using rule 1 (exp)
166
167
168
169 ]])
170
171 AT_CLEANUP
172
173
174 ## --------------------- ##
175 ## Solved SR Conflicts. ##
176 ## --------------------- ##
177
178 AT_SETUP([Solved SR Conflicts])
179
180 AT_DATA([input.y],
181 [[%token NUM OP
182 %right OP
183 %%
184 exp: exp OP exp | NUM;
185 ]])
186
187 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
188
189 # Check the contents of the report.
190 AT_CHECK([cat input.output], [],
191 [[Conflict in state 5 between rule 2 and token OP resolved as shift.
192
193
194 Grammar
195
196 Number, Line, Rule
197 0 4 $axiom -> exp $
198 1 4 exp -> exp OP exp
199 2 4 exp -> NUM
200
201
202 Terminals, with rules where they appear
203
204 $ (0) 0
205 error (256)
206 NUM (257) 2
207 OP (258) 1
208
209
210 Nonterminals, with rules where they appear
211
212 $axiom (5)
213 on left: 0
214 exp (6)
215 on left: 1 2, on right: 0 1
216
217
218 state 0
219
220 NUM shift, and go to state 1
221
222 exp go to state 2
223
224
225
226 state 1
227
228 exp -> NUM . (rule 2)
229
230 $default reduce using rule 2 (exp)
231
232
233
234 state 2
235
236 $axiom -> exp . $ (rule 0)
237 exp -> exp . OP exp (rule 1)
238
239 $ shift, and go to state 3
240 OP shift, and go to state 4
241
242
243
244 state 3
245
246 $axiom -> exp $ . (rule 0)
247
248 $default accept
249
250
251 state 4
252
253 exp -> exp OP . exp (rule 1)
254
255 NUM shift, and go to state 1
256
257 exp go to state 5
258
259
260
261 state 5
262
263 exp -> exp . OP exp (rule 1)
264 exp -> exp OP exp . (rule 1)
265
266 OP shift, and go to state 4
267
268 $default reduce using rule 1 (exp)
269
270
271
272 ]])
273
274 AT_CLEANUP
275
276
277
278
279 ## ------------------- ##
280 ## Rule Line Numbers. ##
281 ## ------------------- ##
282
283 AT_SETUP([Rule Line Numbers])
284
285 AT_DATA([input.y],
286 [[%%
287 expr:
288 'a'
289
290 {
291
292 }
293
294 'b'
295
296 {
297
298 }
299
300 |
301
302
303 {
304
305
306 }
307
308 'c'
309
310 {
311
312 }
313 ]])
314
315 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
316
317 # Check the contents of the report.
318 AT_CHECK([cat input.output], [],
319 [[Grammar
320
321 Number, Line, Rule
322 0 2 $axiom -> expr $
323 1 2 @1 -> /* empty */
324 2 2 expr -> 'a' @1 'b'
325 3 15 @2 -> /* empty */
326 4 15 expr -> @2 'c'
327
328
329 Terminals, with rules where they appear
330
331 $ (0) 0
332 'a' (97) 2
333 'b' (98) 2
334 'c' (99) 4
335 error (256)
336
337
338 Nonterminals, with rules where they appear
339
340 $axiom (6)
341 on left: 0
342 expr (7)
343 on left: 2 4, on right: 0
344 @1 (8)
345 on left: 1, on right: 2
346 @2 (9)
347 on left: 3, on right: 4
348
349
350 state 0
351
352 'a' shift, and go to state 1
353
354 $default reduce using rule 3 (@2)
355
356 expr go to state 2
357 @2 go to state 3
358
359
360
361 state 1
362
363 expr -> 'a' . @1 'b' (rule 2)
364
365 $default reduce using rule 1 (@1)
366
367 @1 go to state 4
368
369
370
371 state 2
372
373 $axiom -> expr . $ (rule 0)
374
375 $ shift, and go to state 5
376
377
378
379 state 3
380
381 expr -> @2 . 'c' (rule 4)
382
383 'c' shift, and go to state 6
384
385
386
387 state 4
388
389 expr -> 'a' @1 . 'b' (rule 2)
390
391 'b' shift, and go to state 7
392
393
394
395 state 5
396
397 $axiom -> expr $ . (rule 0)
398
399 $default accept
400
401
402 state 6
403
404 expr -> @2 'c' . (rule 4)
405
406 $default reduce using rule 4 (expr)
407
408
409
410 state 7
411
412 expr -> 'a' @1 'b' . (rule 2)
413
414 $default reduce using rule 2 (expr)
415
416
417
418 ]])
419
420 AT_CLEANUP
421
422
423
424 ## -------------------- ##
425 ## %expect not enough. ##
426 ## -------------------- ##
427
428 AT_SETUP([%expect not enough])
429
430 AT_DATA([input.y],
431 [[%token NUM OP
432 %expect 0
433 %%
434 exp: exp OP exp | NUM;
435 ]])
436
437 AT_CHECK([bison input.y -o input.c], 1, [],
438 [input.y contains 1 shift/reduce conflict.
439 expected 0 shift/reduce conflicts
440 ])
441 AT_CLEANUP
442
443
444 ## --------------- ##
445 ## %expect right. ##
446 ## --------------- ##
447
448 AT_SETUP([%expect right])
449
450 AT_DATA([input.y],
451 [[%token NUM OP
452 %expect 1
453 %%
454 exp: exp OP exp | NUM;
455 ]])
456
457 AT_CHECK([bison input.y -o input.c], 0)
458 AT_CLEANUP
459
460
461 ## ------------------ ##
462 ## %expect too much. ##
463 ## ------------------ ##
464
465 AT_SETUP([%expect too much])
466
467 AT_DATA([input.y],
468 [[%token NUM OP
469 %expect 2
470 %%
471 exp: exp OP exp | NUM;
472 ]])
473
474 AT_CHECK([bison input.y -o input.c], 1, [],
475 [input.y contains 1 shift/reduce conflict.
476 expected 2 shift/reduce conflicts
477 ])
478 AT_CLEANUP
479
480
481 ## ---------------------- ##
482 ## Mixing %token styles. ##
483 ## ---------------------- ##
484
485
486 AT_SETUP([Mixing %token styles])
487
488 # Taken from the documentation.
489 AT_DATA([input.y],
490 [[%token <operator> OR "||"
491 %token <operator> LE 134 "<="
492 %left OR "<="
493 %%
494 exp: ;
495 %%
496 ]])
497
498 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
499
500 AT_CLEANUP
501
502
503
504 ## ----------------- ##
505 ## Invalid input 1. ##
506 ## ----------------- ##
507
508
509 AT_SETUP([Invalid input: 1])
510
511 AT_DATA([input.y],
512 [[%%
513 ?
514 ]])
515
516 AT_CHECK([bison input.y], [1], [],
517 [[input.y:2: invalid input: `?'
518 input.y:3: fatal error: no rules in the input grammar
519 ]])
520
521 AT_CLEANUP
522
523
524 ## ----------------- ##
525 ## Invalid input 2. ##
526 ## ----------------- ##
527
528
529 AT_SETUP([Invalid input: 2])
530
531 AT_DATA([input.y],
532 [[%%
533 default: 'a' }
534 ]])
535
536 AT_CHECK([bison input.y], [1], [],
537 [[input.y:2: invalid input: `}'
538 ]])
539
540 AT_CLEANUP
541
542
543
544 ## -------------------- ##
545 ## Invalid %directive. ##
546 ## -------------------- ##
547
548
549 AT_SETUP([Invalid %directive])
550
551 AT_DATA([input.y],
552 [[%invalid
553 ]])
554
555 AT_CHECK([bison input.y], [1], [],
556 [[input.y:1: unrecognized: %invalid
557 input.y:1: Skipping to next %
558 input.y:2: fatal error: no input grammar
559 ]])
560
561 AT_CLEANUP
562
563
564
565 ## -------------- ##
566 ## Web2c Report. ##
567 ## -------------- ##
568
569 # The generation of the reduction was once wrong in Bison, and made it
570 # miss some reductions. In the following test case, the reduction on
571 # `undef_id_tok' in state 1 was missing. This is stripped down from
572 # the actual web2c.y.
573
574 AT_SETUP([Web2c Report])
575
576 AT_DATA([input.y],
577 [[%token undef_id_tok const_id_tok
578
579 %start CONST_DEC_PART
580 \f
581 %%
582 CONST_DEC_PART:
583 CONST_DEC_LIST
584 ;
585
586 CONST_DEC_LIST:
587 CONST_DEC
588 | CONST_DEC_LIST CONST_DEC
589 ;
590
591 CONST_DEC:
592 { } undef_id_tok '=' const_id_tok ';'
593 ;
594 %%
595
596 ]])
597
598 AT_CHECK([bison -v input.y])
599
600 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
601 [[Grammar
602 Number, Line, Rule
603 0 6 $axiom -> CONST_DEC_PART $
604 1 6 CONST_DEC_PART -> CONST_DEC_LIST
605 2 10 CONST_DEC_LIST -> CONST_DEC
606 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
607 4 15 @1 -> /* empty */
608 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
609 Terminals, with rules where they appear
610 $ (0) 0
611 ';' (59) 5
612 '=' (61) 5
613 error (256)
614 undef_id_tok (257) 5
615 const_id_tok (258) 5
616 Nonterminals, with rules where they appear
617 $axiom (7)
618 on left: 0
619 CONST_DEC_PART (8)
620 on left: 1, on right: 0
621 CONST_DEC_LIST (9)
622 on left: 2 3, on right: 1 3
623 CONST_DEC (10)
624 on left: 5, on right: 2 3
625 @1 (11)
626 on left: 4, on right: 5
627 state 0
628 $default reduce using rule 4 (@1)
629 CONST_DEC_PART go to state 1
630 CONST_DEC_LIST go to state 2
631 CONST_DEC go to state 3
632 @1 go to state 4
633 state 1
634 $axiom -> CONST_DEC_PART . $ (rule 0)
635 $ shift, and go to state 5
636 state 2
637 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
638 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
639 undef_id_tok reduce using rule 4 (@1)
640 $default reduce using rule 1 (CONST_DEC_PART)
641 CONST_DEC go to state 6
642 @1 go to state 4
643 state 3
644 CONST_DEC_LIST -> CONST_DEC . (rule 2)
645 $default reduce using rule 2 (CONST_DEC_LIST)
646 state 4
647 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
648 undef_id_tok shift, and go to state 7
649 state 5
650 $axiom -> CONST_DEC_PART $ . (rule 0)
651 $default accept
652 state 6
653 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
654 $default reduce using rule 3 (CONST_DEC_LIST)
655 state 7
656 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
657 '=' shift, and go to state 8
658 state 8
659 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
660 const_id_tok shift, and go to state 9
661 state 9
662 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
663 ';' shift, and go to state 10
664 state 10
665 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
666 $default reduce using rule 5 (CONST_DEC)
667 ]])
668
669 AT_CLEANUP
670
671
672 ## --------------- ##
673 ## Web2c Actions. ##
674 ## --------------- ##
675
676 # The generation of the mapping `state -> action' was once wrong in
677 # extremely specific situations. web2c.y exhibits this situation.
678 # Below is a stripped version of the grammar. It looks like one can
679 # simplify it further, but just don't: it is tuned to exhibit a bug,
680 # which disapears when applying sane grammar transformations.
681 #
682 # It used to be wrong on yydefact only:
683 #
684 # static const short yydefact[] =
685 # {
686 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
687 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
688 # 0, 0
689 # };
690 #
691 # but let's check all the tables.
692
693
694 AT_SETUP([Web2c Actions])
695
696 AT_DATA([input.y],
697 [[%%
698 statement: struct_stat;
699 struct_stat: /* empty. */ | if else;
700 if: "if" "const" "then" statement;
701 else: "else" statement;
702 %%
703 ]])
704
705 AT_CHECK([bison -v input.y -o input.c])
706
707 # Check only the tables. We don't use --no-parser, because it is
708 # still to be implemented in the experimental branch of Bison.
709 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
710 [[static const char yytranslate[] =
711 {
712 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
713 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
714 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
715 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
716 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
717 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
718 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
719 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
720 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
721 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
722 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
723 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
724 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
725 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
726 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
727 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
728 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
729 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
730 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
731 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
732 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
733 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
734 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
735 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
736 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
737 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
738 6
739 };
740 static const short yyprhs[] =
741 {
742 0, 0, 3, 5, 6, 9, 14
743 };
744 static const short yyrhs[] =
745 {
746 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
747 4, 5, 8, -1, 6, 8, -1
748 };
749 static const short yyrline[] =
750 {
751 0, 2, 2, 3, 3, 4, 5
752 };
753 static const char *const yytname[] =
754 {
755 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
756 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", NULL
757 };
758 static const short yytoknum[] =
759 {
760 0, 256, 2, 257, 258, 259, 260, -1
761 };
762 static const short yyr1[] =
763 {
764 0, 7, 8, 9, 9, 10, 11
765 };
766 static const short yyr2[] =
767 {
768 0, 2, 1, 0, 2, 4, 2
769 };
770 static const short yydefact[] =
771 {
772 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
773 6, 5
774 };
775 static const short yydefgoto[] =
776 {
777 -1, 2, 3, 4, 8
778 };
779 static const short yypact[] =
780 {
781 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
782 -32768,-32768
783 };
784 static const short yypgoto[] =
785 {
786 -32768, -7,-32768,-32768,-32768
787 };
788 static const short yytable[] =
789 {
790 10, 1, 11, 5, 6, 0, 7, 9
791 };
792 static const short yycheck[] =
793 {
794 7, 3, 9, 4, 0, -1, 6, 5
795 };
796 ]])
797
798 AT_CLEANUP