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])
51 AT_DATA([duplicate.y],
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 duplicate.y -o duplicate.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 4 contains 1 shift/reduce conflict.
97 Terminals, with rules where they appear
105 Nonterminals, with rules where they appear
108 on left: 1 2, on right: 1
113 NUM shift, and go to state 1
121 exp -> NUM . (rule 2)
123 $default reduce using rule 2 (exp)
129 exp -> exp . OP exp (rule 1)
132 OP shift, and go to state 3
138 exp -> exp OP . exp (rule 1)
140 NUM shift, and go to state 1
148 exp -> exp . OP exp (rule 1)
149 exp -> exp OP exp . (rule 1)
151 OP shift, and go to state 3
153 OP [reduce using rule 1 (exp)]
154 $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 4 between rule 1 and token OP resolved as shift.
197 1 4 exp -> exp OP exp
201 Terminals, with rules where they appear
209 Nonterminals, with rules where they appear
212 on left: 1 2, on right: 1
217 NUM shift, and go to state 1
225 exp -> NUM . (rule 2)
227 $default reduce using rule 2 (exp)
233 exp -> exp . OP exp (rule 1)
236 OP shift, and go to state 3
242 exp -> exp OP . exp (rule 1)
244 NUM shift, and go to state 1
252 exp -> exp . OP exp (rule 1)
253 exp -> exp OP exp . (rule 1)
255 OP shift, and go to state 3
257 $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], [],
322 1 2 @1 -> /* empty */
323 2 2 expr -> 'a' @1 'b'
324 3 15 @2 -> /* empty */
328 Terminals, with rules where they appear
337 Nonterminals, with rules where they appear
342 on left: 1, on right: 2
344 on left: 3, on right: 4
349 'a' shift, and go to state 1
351 $default reduce using rule 3 (@2)
360 expr -> 'a' . @1 'b' (rule 2)
362 $default reduce using rule 1 (@1)
370 expr -> @2 . 'c' (rule 4)
372 'c' shift, and go to state 4
378 expr -> 'a' @1 . 'b' (rule 2)
380 'b' shift, and go to state 5
386 expr -> @2 'c' . (rule 4)
388 $default reduce using rule 4 (expr)
394 expr -> 'a' @1 'b' . (rule 2)
396 $default reduce using rule 2 (expr)
423 ## -------------------- ##
424 ## %expect not enough. ##
425 ## -------------------- ##
427 AT_SETUP([%expect not enough])
433 exp: exp OP exp | NUM;
436 AT_CHECK([bison input.y -o input.c], 1, [],
437 [input.y contains 1 shift/reduce conflict.
438 expected 0 shift/reduce conflicts
443 ## --------------- ##
445 ## --------------- ##
447 AT_SETUP([%expect right])
453 exp: exp OP exp | NUM;
456 AT_CHECK([bison input.y -o input.c], 0)
460 ## ------------------ ##
461 ## %expect too much. ##
462 ## ------------------ ##
464 AT_SETUP([%expect too much])
470 exp: exp OP exp | NUM;
473 AT_CHECK([bison input.y -o input.c], 1, [],
474 [input.y contains 1 shift/reduce conflict.
475 expected 2 shift/reduce conflicts
480 ## ---------------------- ##
481 ## Mixing %token styles. ##
482 ## ---------------------- ##
485 AT_SETUP([Mixing %token styles])
487 # Taken from the documentation.
489 [[%token <operator> OR "||"
490 %token <operator> LE 134 "<="
497 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
503 ## ---------------------- ##
504 ## %union and --defines. ##
505 ## ---------------------- ##
508 AT_SETUP([%union and --defines])
520 AT_CHECK([bison --defines union.y])
525 ## --------------------------------------- ##
526 ## Duplicate '/' in C comments in %union ##
527 ## --------------------------------------- ##
530 AT_SETUP([%union and C comments])
532 AT_DATA([union-comment.y],
535 /* The int. */ int integer;
536 /* The string. */ char *string ;
542 AT_CHECK([bison union-comment.y])
543 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
548 ## ----------------- ##
549 ## Invalid input 1. ##
550 ## ----------------- ##
553 AT_SETUP([Invalid input: 1])
560 AT_CHECK([bison input.y], [1], [],
561 [[input.y:2: invalid input: `?'
562 input.y:3: fatal error: no rules in the input grammar
568 ## ----------------- ##
569 ## Invalid input 2. ##
570 ## ----------------- ##
573 AT_SETUP([Invalid input: 2])
580 AT_CHECK([bison input.y], [1], [],
581 [[input.y:2: invalid input: `}'
588 ## -------------------- ##
589 ## Invalid %directive. ##
590 ## -------------------- ##
593 AT_SETUP([Invalid %directive])
599 AT_CHECK([bison input.y], [1], [],
600 [[input.y:1: unrecognized: %invalid
601 input.y:1: Skipping to next %
602 input.y:2: fatal error: no input grammar
609 ## --------------------- ##
610 ## Invalid CPP headers. ##
611 ## --------------------- ##
613 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
614 # -------------------------------------
615 m4_define([AT_TEST_CPP_GUARD_H],
616 [AT_SETUP([Invalid CPP guards: $1])
618 # Possibly create inner directories.
619 dirname=`AS_DIRNAME([$1])`
620 AS_MKDIR_P([$dirname])
627 AT_CHECK([bison --defines=$1.h $1.y])
629 # CPP should be happy with it.
630 AT_CHECK([$CC -E $1.h], 0, [ignore])
635 AT_TEST_CPP_GUARD_H([input/input])
636 AT_TEST_CPP_GUARD_H([9foo])
644 # The generation of the reduction was once wrong in Bison, and made it
645 # miss some reductions. In the following test case, the reduction on
646 # `undef_id_tok' in state 1 was missing. This is stripped down from
647 # the actual web2c.y.
649 AT_SETUP([Web2c Report])
652 [[%token undef_id_tok const_id_tok
654 %start CONST_DEC_PART
663 | CONST_DEC_LIST CONST_DEC
667 { } undef_id_tok '=' const_id_tok ';'
673 AT_CHECK([bison -v input.y])
675 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
678 1 6 CONST_DEC_PART -> CONST_DEC_LIST
679 2 10 CONST_DEC_LIST -> CONST_DEC
680 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
681 4 15 @1 -> /* empty */
682 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
683 Terminals, with rules where they appear
690 Nonterminals, with rules where they appear
694 on left: 2 3, on right: 1 3
696 on left: 5, on right: 2 3
698 on left: 4, on right: 5
700 $default reduce using rule 4 (@1)
701 CONST_DEC_PART go to state 9
702 CONST_DEC_LIST go to state 1
703 CONST_DEC go to state 2
706 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
707 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
708 undef_id_tok reduce using rule 4 (@1)
709 $default reduce using rule 1 (CONST_DEC_PART)
710 CONST_DEC go to state 4
713 CONST_DEC_LIST -> CONST_DEC . (rule 2)
714 $default reduce using rule 2 (CONST_DEC_LIST)
716 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
717 undef_id_tok shift, and go to state 5
719 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
720 $default reduce using rule 3 (CONST_DEC_LIST)
722 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
723 '=' shift, and go to state 6
725 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
726 const_id_tok shift, and go to state 7
728 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
729 ';' shift, and go to state 8
731 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
732 $default reduce using rule 5 (CONST_DEC)
744 ## --------------- ##
746 ## --------------- ##
748 # The generation of the mapping `state -> action' was once wrong in
749 # extremely specific situations. web2c.y exhibits this situation.
750 # Below is a stripped version of the grammar. It looks like one can
751 # simplify it further, but just don't: it is tuned to exhibit a bug,
752 # which disapears when applying sane grammar transformations.
754 # It used to be wrong on yydefact only:
756 # static const short yydefact[] =
758 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
759 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
763 # but let's check all the tables.
766 AT_SETUP([Web2c Actions])
770 statement: struct_stat;
771 struct_stat: /* empty. */ | if else;
772 if: "if" "const" "then" statement;
773 else: "else" statement;
777 AT_CHECK([bison -v input.y -o input.c])
779 # Check only the tables. We don't use --no-parser, because it is
780 # still to be implemented in the experimental branch of Bison.
781 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
782 [[static const char yytranslate[] =
784 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
785 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
786 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
787 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
788 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
789 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
790 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
791 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
792 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
793 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
794 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
795 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
796 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
797 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
798 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
799 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
800 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
801 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
802 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
803 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
804 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
805 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
806 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
807 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
808 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
809 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
812 static const short yyprhs[] =
816 static const short yyrhs[] =
818 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
821 static const short yyrline[] =
825 static const char *const yytname[] =
827 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
828 "\"else\"", "statement", "struct_stat", "if", "else", NULL
830 static const short yyr1[] =
834 static const short yyr2[] =
838 static const short yydefact[] =
840 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
843 static const short yydefgoto[] =
847 static const short yypact[] =
849 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
852 static const short yypgoto[] =
854 0,-32768,-32768,-32768
856 static const short yytable[] =
858 10, 1, 5, 4, 11, 12, 7, 9
860 static const short yycheck[] =
862 0, 3, 6, 4, 0, 0, 5, 7