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 ## ------------------- ##
23 ## %nonassoc and eof. ##
24 ## ------------------- ##
26 AT_SETUP([%nonassoc and eof])
33 #define YYERROR_VERBOSE 1
34 #define yyerror(Msg) \
36 fprintf (stderr, "%s\n", Msg); \
40 /* The current argument. */
41 static const char *input = NULL;
46 /* No token stands for end of file. */
64 main (int argc, const char *argv[])
72 # Specify the output files to avoid problems on different file systems.
73 AT_CHECK([bison input.y -o input.c])
74 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
76 AT_CHECK([./input '0<0'])
77 # FIXME: This is an actual bug, but a new one, in the sense that
78 # no one has ever spotted it! The messages are *wrong*: there should
79 # be nothing there, it should be expected eof.
80 AT_CHECK([./input '0<0<0'], [1], [],
81 [parse error, unexpected '<', expecting '<' or '>'
84 AT_CHECK([./input '0>0'])
85 AT_CHECK([./input '0>0>0'], [1], [],
86 [parse error, unexpected '>', expecting '<' or '>'
89 AT_CHECK([./input '0<0>0'], [1], [],
90 [parse error, unexpected '>', expecting '<' or '>'
95 ## ---------------- ##
97 ## ---------------- ##
100 AT_SETUP([braces parsing])
103 [[/* Bison used to swallow the character after `}'. */
106 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
110 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
112 AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
117 ## ------------------ ##
118 ## Duplicate string. ##
119 ## ------------------ ##
122 AT_SETUP([Duplicate string])
124 AT_DATA([duplicate.y],
125 [[/* `Bison -v' used to dump core when two tokens are defined with the same
126 string, as LE and GE below. */
133 exp: '(' exp ')' | NUM ;
137 AT_CHECK([bison -v duplicate.y -o duplicate.c], 0, ignore, ignore)
142 ## ------------------------- ##
143 ## Unresolved SR Conflicts. ##
144 ## ------------------------- ##
146 AT_SETUP([Unresolved SR Conflicts])
151 exp: exp OP exp | NUM;
154 AT_CHECK([bison input.y -o input.c -v], 0, [],
155 [input.y contains 1 shift/reduce conflict.
158 # Check the contents of the report.
159 AT_CHECK([cat input.output], [],
160 [[State 4 contains 1 shift/reduce conflict.
166 1 3 exp -> exp OP exp
170 Terminals, with rules where they appear
178 Nonterminals, with rules where they appear
181 on left: 1 2, on right: 1
186 NUM shift, and go to state 1
194 exp -> NUM . (rule 2)
196 $default reduce using rule 2 (exp)
202 exp -> exp . OP exp (rule 1)
205 OP shift, and go to state 3
211 exp -> exp OP . exp (rule 1)
213 NUM shift, and go to state 1
221 exp -> exp . OP exp (rule 1)
222 exp -> exp OP exp . (rule 1)
224 OP shift, and go to state 3
226 OP [reduce using rule 1 (exp)]
227 $default reduce using rule 1 (exp)
247 ## --------------------- ##
248 ## Solved SR Conflicts. ##
249 ## --------------------- ##
251 AT_SETUP([Solved SR Conflicts])
257 exp: exp OP exp | NUM;
260 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
262 # Check the contents of the report.
263 AT_CHECK([cat input.output], [],
264 [[Conflict in state 4 between rule 1 and token OP resolved as shift.
270 1 4 exp -> exp OP exp
274 Terminals, with rules where they appear
282 Nonterminals, with rules where they appear
285 on left: 1 2, on right: 1
290 NUM shift, and go to state 1
298 exp -> NUM . (rule 2)
300 $default reduce using rule 2 (exp)
306 exp -> exp . OP exp (rule 1)
309 OP shift, and go to state 3
315 exp -> exp OP . exp (rule 1)
317 NUM shift, and go to state 1
325 exp -> exp . OP exp (rule 1)
326 exp -> exp OP exp . (rule 1)
328 OP shift, and go to state 3
330 $default reduce using rule 1 (exp)
352 ## ------------------- ##
353 ## Rule Line Numbers. ##
354 ## ------------------- ##
356 AT_SETUP([Rule Line Numbers])
388 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
390 # Check the contents of the report.
391 AT_CHECK([cat input.output], [],
395 1 2 @1 -> /* empty */
396 2 2 expr -> 'a' @1 'b'
397 3 15 @2 -> /* empty */
401 Terminals, with rules where they appear
410 Nonterminals, with rules where they appear
415 on left: 1, on right: 2
417 on left: 3, on right: 4
422 'a' shift, and go to state 1
424 $default reduce using rule 3 (@2)
433 expr -> 'a' . @1 'b' (rule 2)
435 $default reduce using rule 1 (@1)
443 expr -> @2 . 'c' (rule 4)
445 'c' shift, and go to state 4
451 expr -> 'a' @1 . 'b' (rule 2)
453 'b' shift, and go to state 5
459 expr -> @2 'c' . (rule 4)
461 $default reduce using rule 4 (expr)
467 expr -> 'a' @1 'b' . (rule 2)
469 $default reduce using rule 2 (expr)
496 ## -------------------- ##
497 ## %expect not enough. ##
498 ## -------------------- ##
500 AT_SETUP([%expect not enough])
506 exp: exp OP exp | NUM;
509 AT_CHECK([bison input.y -o input.c], 1, [],
510 [input.y contains 1 shift/reduce conflict.
511 expected 0 shift/reduce conflicts
516 ## --------------- ##
518 ## --------------- ##
520 AT_SETUP([%expect right])
526 exp: exp OP exp | NUM;
529 AT_CHECK([bison input.y -o input.c], 0)
533 ## ------------------ ##
534 ## %expect too much. ##
535 ## ------------------ ##
537 AT_SETUP([%expect too much])
543 exp: exp OP exp | NUM;
546 AT_CHECK([bison input.y -o input.c], 1, [],
547 [input.y contains 1 shift/reduce conflict.
548 expected 2 shift/reduce conflicts
553 ## ---------------------- ##
554 ## Mixing %token styles. ##
555 ## ---------------------- ##
558 AT_SETUP([Mixing %token styles])
560 # Taken from the documentation.
562 [[%token <operator> OR "||"
563 %token <operator> LE 134 "<="
570 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
576 ## ---------------------- ##
577 ## %union and --defines. ##
578 ## ---------------------- ##
581 AT_SETUP([%union and --defines])
593 AT_CHECK([bison --defines union.y])
598 ## --------------------------------------- ##
599 ## Duplicate '/' in C comments in %union ##
600 ## --------------------------------------- ##
603 AT_SETUP([%union and C comments])
605 AT_DATA([union-comment.y],
608 /* The int. */ int integer;
609 /* The string. */ char *string ;
615 AT_CHECK([bison union-comment.y])
616 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
621 ## ---------------- ##
622 ## Invalid inputs. ##
623 ## ---------------- ##
626 AT_SETUP([Invalid inputs])
638 AT_CHECK([bison input.y], [1], [],
639 [[input.y:2: invalid input: `?'
640 input.y:3: invalid input: `}'
641 input.y:4: invalid input: `%{'
642 input.y:5: invalid input: `%&'
643 input.y:6: invalid input: `%a'
644 input.y:7: invalid input: `%-'
651 ## -------------------- ##
652 ## Invalid %directive. ##
653 ## -------------------- ##
656 AT_SETUP([Invalid %directive])
662 AT_CHECK([bison input.y], [1], [],
663 [[input.y:1: unrecognized: %invalid
664 input.y:1: Skipping to next %
665 input.y:2: fatal error: no input grammar
676 # The generation of the reduction was once wrong in Bison, and made it
677 # miss some reductions. In the following test case, the reduction on
678 # `undef_id_tok' in state 1 was missing. This is stripped down from
679 # the actual web2c.y.
681 AT_SETUP([Web2c Report])
684 [[%token undef_id_tok const_id_tok
686 %start CONST_DEC_PART
695 | CONST_DEC_LIST CONST_DEC
699 { } undef_id_tok '=' const_id_tok ';'
705 AT_CHECK([bison -v input.y])
707 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
710 1 6 CONST_DEC_PART -> CONST_DEC_LIST
711 2 10 CONST_DEC_LIST -> CONST_DEC
712 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
713 4 15 @1 -> /* empty */
714 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
715 Terminals, with rules where they appear
722 Nonterminals, with rules where they appear
726 on left: 2 3, on right: 1 3
728 on left: 5, on right: 2 3
730 on left: 4, on right: 5
732 $default reduce using rule 4 (@1)
733 CONST_DEC_PART go to state 9
734 CONST_DEC_LIST go to state 1
735 CONST_DEC go to state 2
738 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
739 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
740 undef_id_tok reduce using rule 4 (@1)
741 $default reduce using rule 1 (CONST_DEC_PART)
742 CONST_DEC go to state 4
745 CONST_DEC_LIST -> CONST_DEC . (rule 2)
746 $default reduce using rule 2 (CONST_DEC_LIST)
748 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
749 undef_id_tok shift, and go to state 5
751 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
752 $default reduce using rule 3 (CONST_DEC_LIST)
754 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
755 '=' shift, and go to state 6
757 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
758 const_id_tok shift, and go to state 7
760 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
761 ';' shift, and go to state 8
763 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
764 $default reduce using rule 5 (CONST_DEC)
776 ## --------------- ##
778 ## --------------- ##
780 # The generation of the mapping `state -> action' was once wrong in
781 # extremely specific situations. web2c.y exhibits this situation.
782 # Below is a stripped version of the grammar. It looks like one can
783 # simplify it further, but just don't: it is tuned to exhibit a bug,
784 # which disapears when applying sane grammar transformations.
786 # It used to be wrong on yydefact only:
788 # static const short yydefact[] =
790 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
791 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
795 # but let's check all the tables.
798 AT_SETUP([Web2c Actions])
802 statement: struct_stat;
803 struct_stat: /* empty. */ | if else;
804 if: "if" "const" "then" statement;
805 else: "else" statement;
809 AT_CHECK([bison -v input.y -o input.c])
811 # Check only the tables. We don't use --no-parser, because it is
812 # still to be implemented in the experimental branch of Bison.
813 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
814 [[static const char yytranslate[] =
816 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
817 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
818 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
819 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
820 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
821 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
822 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
823 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
824 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
825 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
826 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
827 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
828 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
829 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
830 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
831 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
832 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
833 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
834 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
835 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
836 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
837 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
838 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
839 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
840 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
841 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
844 static const short yyprhs[] =
848 static const short yyrhs[] =
850 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
853 static const short yyrline[] =
857 static const char *const yytname[] =
859 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
860 "\"else\"", "statement", "struct_stat", "if", "else", 0
862 static const short yyr1[] =
866 static const short yyr2[] =
870 static const short yydefact[] =
872 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
875 static const short yydefgoto[] =
879 static const short yypact[] =
881 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
884 static const short yypgoto[] =
886 0,-32768,-32768,-32768
888 static const short yytable[] =
890 10, 1, 5, 4, 11, 12, 7, 9
892 static const short yycheck[] =
894 0, 3, 6, 4, 0, 0, 5, 7