1 # Bison Regressions. -*- Autotest -*-
2 # Copyright 2001 Free Software Foundation, Inc.
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)
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.
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
19 AT_BANNER([[Regression tests.]])
22 ## ---------------- ##
24 ## ---------------- ##
27 AT_SETUP([braces parsing])
30 [[/* Bison used to swallow the character after `}'. */
33 exp: { tests = {{{{{{{{{{}}}}}}}}}}; }
37 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
39 AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
44 ## ------------------ ##
45 ## Duplicate string. ##
46 ## ------------------ ##
49 AT_SETUP([Duplicate string])
52 [[/* `Bison -v' used to dump core when two tokens are defined with the same
53 string, as LE and GE below. */
60 exp: '(' exp ')' | NUM ;
64 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
69 ## ------------------------- ##
70 ## Unresolved SR Conflicts. ##
71 ## ------------------------- ##
73 AT_SETUP([Unresolved SR Conflicts])
78 exp: exp OP exp | NUM;
81 AT_CHECK([bison input.y -o input.c -v], 0, [],
82 [input.y contains 1 shift/reduce conflict.
85 # Check the contents of the report.
86 AT_CHECK([cat input.output], [],
87 [[State 5 contains 1 shift/reduce conflict.
98 Terminals, with rules where they appear
106 Nonterminals, with rules where they appear
111 on left: 1 2, on right: 0 1
116 NUM shift, and go to state 1
124 exp -> NUM . (rule 2)
126 $default reduce using rule 2 (exp)
132 $axiom -> exp . $ (rule 0)
133 exp -> exp . OP exp (rule 1)
135 $ shift, and go to state 3
136 OP shift, and go to state 4
142 $axiom -> exp $ . (rule 0)
149 exp -> exp OP . exp (rule 1)
151 NUM shift, and go to state 1
159 exp -> exp . OP exp (rule 1)
160 exp -> exp OP exp . (rule 1)
162 OP shift, and go to state 4
164 OP [reduce using rule 1 (exp)]
165 $default reduce using rule 1 (exp)
174 ## --------------------- ##
175 ## Solved SR Conflicts. ##
176 ## --------------------- ##
178 AT_SETUP([Solved SR Conflicts])
184 exp: exp OP exp | NUM;
187 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
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.
198 1 4 exp -> exp OP exp
202 Terminals, with rules where they appear
210 Nonterminals, with rules where they appear
215 on left: 1 2, on right: 0 1
220 NUM shift, and go to state 1
228 exp -> NUM . (rule 2)
230 $default reduce using rule 2 (exp)
236 $axiom -> exp . $ (rule 0)
237 exp -> exp . OP exp (rule 1)
239 $ shift, and go to state 3
240 OP shift, and go to state 4
246 $axiom -> exp $ . (rule 0)
253 exp -> exp OP . exp (rule 1)
255 NUM shift, and go to state 1
263 exp -> exp . OP exp (rule 1)
264 exp -> exp OP exp . (rule 1)
266 OP shift, and go to state 4
268 $default reduce using rule 1 (exp)
279 ## ------------------- ##
280 ## Rule Line Numbers. ##
281 ## ------------------- ##
283 AT_SETUP([Rule Line Numbers])
315 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
317 # Check the contents of the report.
318 AT_CHECK([cat input.output], [],
323 1 2 @1 -> /* empty */
324 2 2 expr -> 'a' @1 'b'
325 3 15 @2 -> /* empty */
329 Terminals, with rules where they appear
338 Nonterminals, with rules where they appear
343 on left: 2 4, on right: 0
345 on left: 1, on right: 2
347 on left: 3, on right: 4
352 'a' shift, and go to state 1
354 $default reduce using rule 3 (@2)
363 expr -> 'a' . @1 'b' (rule 2)
365 $default reduce using rule 1 (@1)
373 $axiom -> expr . $ (rule 0)
375 $ shift, and go to state 5
381 expr -> @2 . 'c' (rule 4)
383 'c' shift, and go to state 6
389 expr -> 'a' @1 . 'b' (rule 2)
391 'b' shift, and go to state 7
397 $axiom -> expr $ . (rule 0)
404 expr -> @2 'c' . (rule 4)
406 $default reduce using rule 4 (expr)
412 expr -> 'a' @1 'b' . (rule 2)
414 $default reduce using rule 2 (expr)
424 ## -------------------- ##
425 ## %expect not enough. ##
426 ## -------------------- ##
428 AT_SETUP([%expect not enough])
434 exp: exp OP exp | NUM;
437 AT_CHECK([bison input.y -o input.c], 1, [],
438 [input.y contains 1 shift/reduce conflict.
439 expected 0 shift/reduce conflicts
444 ## --------------- ##
446 ## --------------- ##
448 AT_SETUP([%expect right])
454 exp: exp OP exp | NUM;
457 AT_CHECK([bison input.y -o input.c], 0)
461 ## ------------------ ##
462 ## %expect too much. ##
463 ## ------------------ ##
465 AT_SETUP([%expect too much])
471 exp: exp OP exp | NUM;
474 AT_CHECK([bison input.y -o input.c], 1, [],
475 [input.y contains 1 shift/reduce conflict.
476 expected 2 shift/reduce conflicts
481 ## ---------------------- ##
482 ## Mixing %token styles. ##
483 ## ---------------------- ##
486 AT_SETUP([Mixing %token styles])
488 # Taken from the documentation.
490 [[%token <operator> OR "||"
491 %token <operator> LE 134 "<="
498 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
504 ## ----------------- ##
505 ## Invalid input 1. ##
506 ## ----------------- ##
509 AT_SETUP([Invalid input: 1])
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
524 ## ----------------- ##
525 ## Invalid input 2. ##
526 ## ----------------- ##
529 AT_SETUP([Invalid input: 2])
536 AT_CHECK([bison input.y], [1], [],
537 [[input.y:2: invalid input: `}'
544 ## -------------------- ##
545 ## Invalid %directive. ##
546 ## -------------------- ##
549 AT_SETUP([Invalid %directive])
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
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.
574 AT_SETUP([Web2c Report])
577 [[%token undef_id_tok const_id_tok
579 %start CONST_DEC_PART
588 | CONST_DEC_LIST CONST_DEC
592 { } undef_id_tok '=' const_id_tok ';'
598 AT_CHECK([bison -v input.y])
600 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
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
616 Nonterminals, with rules where they appear
620 on left: 1, on right: 0
622 on left: 2 3, on right: 1 3
624 on left: 5, on right: 2 3
626 on left: 4, on right: 5
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
634 $axiom -> CONST_DEC_PART . $ (rule 0)
635 $ shift, and go to state 5
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
644 CONST_DEC_LIST -> CONST_DEC . (rule 2)
645 $default reduce using rule 2 (CONST_DEC_LIST)
647 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
648 undef_id_tok shift, and go to state 7
650 $axiom -> CONST_DEC_PART $ . (rule 0)
653 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
654 $default reduce using rule 3 (CONST_DEC_LIST)
656 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
657 '=' shift, and go to state 8
659 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
660 const_id_tok shift, and go to state 9
662 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
663 ';' shift, and go to state 10
665 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
666 $default reduce using rule 5 (CONST_DEC)
672 ## --------------- ##
674 ## --------------- ##
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.
682 # It used to be wrong on yydefact only:
684 # static const short yydefact[] =
686 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
687 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
691 # but let's check all the tables.
694 AT_SETUP([Web2c Actions])
698 statement: struct_stat;
699 struct_stat: /* empty. */ | if else;
700 if: "if" "const" "then" statement;
701 else: "else" statement;
705 AT_CHECK([bison -v input.y -o input.c])
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[] =
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,
740 static const short yyprhs[] =
744 static const short yyrhs[] =
746 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
747 4, 5, 8, -1, 6, 8, -1
749 static const short yyrline[] =
753 static const char *const yytname[] =
755 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
756 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", NULL
758 static const short yytoknum[] =
760 0, 256, 2, 257, 258, 259, 260, -1
762 static const short yyr1[] =
764 0, 7, 8, 9, 9, 10, 11
766 static const short yyr2[] =
770 static const short yydefact[] =
772 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
775 static const short yydefgoto[] =
779 static const short yypact[] =
781 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
784 static const short yypgoto[] =
786 -32768, -7,-32768,-32768,-32768
788 static const short yytable[] =
790 10, 1, 11, 5, 6, 0, 7, 9
792 static const short yycheck[] =
794 7, 3, 9, 4, 0, -1, 6, 5