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])
35 #define YYERROR_VERBOSE 1
36 #define yyerror(Msg) \
38 fprintf (stderr, "%s\n", Msg); \
42 /* The current argument. */
43 static const char *input = NULL;
48 /* No token stands for end of file. */
66 main (int argc, const char *argv[])
74 # Specify the output files to avoid problems on different file systems.
75 AT_CHECK([bison input.y -o input.c])
76 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore])
78 AT_CHECK([./input '0<0'])
79 # FIXME: This is an actual bug, but a new one, in the sense that
80 # no one has ever spotted it! The messages are *wrong*: there should
81 # be nothing there, it should be expected eof.
82 AT_CHECK([./input '0<0<0'], [1], [],
83 [parse error, unexpected '<', expecting '<' or '>'
86 AT_CHECK([./input '0>0'])
87 AT_CHECK([./input '0>0>0'], [1], [],
88 [parse error, unexpected '>', expecting '<' or '>'
91 AT_CHECK([./input '0<0>0'], [1], [],
92 [parse error, unexpected '>', expecting '<' or '>'
97 ## ---------------- ##
99 ## ---------------- ##
102 AT_SETUP([braces parsing])
105 [[/* Bison used to swallow the character after `}'. */
108 exp: { tests = {{{{{{{{{{}}}}}}}}}}; }
112 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
114 AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
119 ## ------------------ ##
120 ## Duplicate string. ##
121 ## ------------------ ##
124 AT_SETUP([Duplicate string])
126 AT_DATA([duplicate.y],
127 [[/* `Bison -v' used to dump core when two tokens are defined with the same
128 string, as LE and GE below. */
135 exp: '(' exp ')' | NUM ;
139 AT_CHECK([bison -v duplicate.y -o duplicate.c], 0, ignore, ignore)
144 ## ------------------------- ##
145 ## Unresolved SR Conflicts. ##
146 ## ------------------------- ##
148 AT_SETUP([Unresolved SR Conflicts])
153 exp: exp OP exp | NUM;
156 AT_CHECK([bison input.y -o input.c -v], 0, [],
157 [input.y contains 1 shift/reduce conflict.
160 # Check the contents of the report.
161 AT_CHECK([cat input.output], [],
162 [[State 4 contains 1 shift/reduce conflict.
168 1 3 exp -> exp OP exp
172 Terminals, with rules where they appear
180 Nonterminals, with rules where they appear
183 on left: 1 2, on right: 1
188 NUM shift, and go to state 1
196 exp -> NUM . (rule 2)
198 $default reduce using rule 2 (exp)
204 exp -> exp . OP exp (rule 1)
207 OP shift, and go to state 3
213 exp -> exp OP . exp (rule 1)
215 NUM shift, and go to state 1
223 exp -> exp . OP exp (rule 1)
224 exp -> exp OP exp . (rule 1)
226 OP shift, and go to state 3
228 OP [reduce using rule 1 (exp)]
229 $default reduce using rule 1 (exp)
249 ## --------------------- ##
250 ## Solved SR Conflicts. ##
251 ## --------------------- ##
253 AT_SETUP([Solved SR Conflicts])
259 exp: exp OP exp | NUM;
262 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
264 # Check the contents of the report.
265 AT_CHECK([cat input.output], [],
266 [[Conflict in state 4 between rule 1 and token OP resolved as shift.
272 1 4 exp -> exp OP exp
276 Terminals, with rules where they appear
284 Nonterminals, with rules where they appear
287 on left: 1 2, on right: 1
292 NUM shift, and go to state 1
300 exp -> NUM . (rule 2)
302 $default reduce using rule 2 (exp)
308 exp -> exp . OP exp (rule 1)
311 OP shift, and go to state 3
317 exp -> exp OP . exp (rule 1)
319 NUM shift, and go to state 1
327 exp -> exp . OP exp (rule 1)
328 exp -> exp OP exp . (rule 1)
330 OP shift, and go to state 3
332 $default reduce using rule 1 (exp)
354 ## ------------------- ##
355 ## Rule Line Numbers. ##
356 ## ------------------- ##
358 AT_SETUP([Rule Line Numbers])
390 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
392 # Check the contents of the report.
393 AT_CHECK([cat input.output], [],
397 1 2 @1 -> /* empty */
398 2 2 expr -> 'a' @1 'b'
399 3 15 @2 -> /* empty */
403 Terminals, with rules where they appear
412 Nonterminals, with rules where they appear
417 on left: 1, on right: 2
419 on left: 3, on right: 4
424 'a' shift, and go to state 1
426 $default reduce using rule 3 (@2)
435 expr -> 'a' . @1 'b' (rule 2)
437 $default reduce using rule 1 (@1)
445 expr -> @2 . 'c' (rule 4)
447 'c' shift, and go to state 4
453 expr -> 'a' @1 . 'b' (rule 2)
455 'b' shift, and go to state 5
461 expr -> @2 'c' . (rule 4)
463 $default reduce using rule 4 (expr)
469 expr -> 'a' @1 'b' . (rule 2)
471 $default reduce using rule 2 (expr)
498 ## -------------------- ##
499 ## %expect not enough. ##
500 ## -------------------- ##
502 AT_SETUP([%expect not enough])
508 exp: exp OP exp | NUM;
511 AT_CHECK([bison input.y -o input.c], 1, [],
512 [input.y contains 1 shift/reduce conflict.
513 expected 0 shift/reduce conflicts
518 ## --------------- ##
520 ## --------------- ##
522 AT_SETUP([%expect right])
528 exp: exp OP exp | NUM;
531 AT_CHECK([bison input.y -o input.c], 0)
535 ## ------------------ ##
536 ## %expect too much. ##
537 ## ------------------ ##
539 AT_SETUP([%expect too much])
545 exp: exp OP exp | NUM;
548 AT_CHECK([bison input.y -o input.c], 1, [],
549 [input.y contains 1 shift/reduce conflict.
550 expected 2 shift/reduce conflicts
555 ## ---------------------- ##
556 ## Mixing %token styles. ##
557 ## ---------------------- ##
560 AT_SETUP([Mixing %token styles])
562 # Taken from the documentation.
564 [[%token <operator> OR "||"
565 %token <operator> LE 134 "<="
572 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
578 ## ---------------------- ##
579 ## %union and --defines. ##
580 ## ---------------------- ##
583 AT_SETUP([%union and --defines])
595 AT_CHECK([bison --defines union.y])
600 ## --------------------------------------- ##
601 ## Duplicate '/' in C comments in %union ##
602 ## --------------------------------------- ##
605 AT_SETUP([%union and C comments])
607 AT_DATA([union-comment.y],
610 /* The int. */ int integer;
611 /* The string. */ char *string ;
617 AT_CHECK([bison union-comment.y])
618 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
623 ## ---------------- ##
624 ## Invalid inputs. ##
625 ## ---------------- ##
628 AT_SETUP([Invalid inputs])
640 AT_CHECK([bison input.y], [1], [],
641 [[input.y:2: invalid input: `?'
642 input.y:3: invalid input: `}'
643 input.y:4: invalid input: `%{'
644 input.y:5: invalid input: `%&'
645 input.y:6: invalid input: `%a'
646 input.y:7: invalid input: `%-'
653 ## -------------------- ##
654 ## Invalid %directive. ##
655 ## -------------------- ##
658 AT_SETUP([Invalid %directive])
664 AT_CHECK([bison input.y], [1], [],
665 [[input.y:1: unrecognized: %invalid
666 input.y:1: Skipping to next %
667 input.y:2: fatal error: no input grammar
678 # The generation of the reduction was once wrong in Bison, and made it
679 # miss some reductions. In the following test case, the reduction on
680 # `undef_id_tok' in state 1 was missing. This is stripped down from
681 # the actual web2c.y.
683 AT_SETUP([Web2c Report])
686 [[%token undef_id_tok const_id_tok
688 %start CONST_DEC_PART
697 | CONST_DEC_LIST CONST_DEC
701 { } undef_id_tok '=' const_id_tok ';'
707 AT_CHECK([bison -v input.y])
709 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
712 1 6 CONST_DEC_PART -> CONST_DEC_LIST
713 2 10 CONST_DEC_LIST -> CONST_DEC
714 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
715 4 15 @1 -> /* empty */
716 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
717 Terminals, with rules where they appear
724 Nonterminals, with rules where they appear
728 on left: 2 3, on right: 1 3
730 on left: 5, on right: 2 3
732 on left: 4, on right: 5
734 $default reduce using rule 4 (@1)
735 CONST_DEC_PART go to state 9
736 CONST_DEC_LIST go to state 1
737 CONST_DEC go to state 2
740 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
741 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
742 undef_id_tok reduce using rule 4 (@1)
743 $default reduce using rule 1 (CONST_DEC_PART)
744 CONST_DEC go to state 4
747 CONST_DEC_LIST -> CONST_DEC . (rule 2)
748 $default reduce using rule 2 (CONST_DEC_LIST)
750 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
751 undef_id_tok shift, and go to state 5
753 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
754 $default reduce using rule 3 (CONST_DEC_LIST)
756 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
757 '=' shift, and go to state 6
759 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
760 const_id_tok shift, and go to state 7
762 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
763 ';' shift, and go to state 8
765 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
766 $default reduce using rule 5 (CONST_DEC)
778 ## --------------- ##
780 ## --------------- ##
782 # The generation of the mapping `state -> action' was once wrong in
783 # extremely specific situations. web2c.y exhibits this situation.
784 # Below is a stripped version of the grammar. It looks like one can
785 # simplify it further, but just don't: it is tuned to exhibit a bug,
786 # which disapears when applying sane grammar transformations.
788 # It used to be wrong on yydefact only:
790 # static const short yydefact[] =
792 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
793 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
797 # but let's check all the tables.
800 AT_SETUP([Web2c Actions])
804 statement: struct_stat;
805 struct_stat: /* empty. */ | if else;
806 if: "if" "const" "then" statement;
807 else: "else" statement;
811 AT_CHECK([bison -v input.y -o input.c])
813 # Check only the tables. We don't use --no-parser, because it is
814 # still to be implemented in the experimental branch of Bison.
815 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
816 [[static const char yytranslate[] =
818 0, 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, 2, 2, 2, 2,
842 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
843 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
846 static const short yyprhs[] =
850 static const short yyrhs[] =
852 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
855 static const short yyrline[] =
859 static const char *const yytname[] =
861 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
862 "\"else\"", "statement", "struct_stat", "if", "else", NULL
864 static const short yyr1[] =
868 static const short yyr2[] =
872 static const short yydefact[] =
874 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
877 static const short yydefgoto[] =
881 static const short yypact[] =
883 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
886 static const short yypgoto[] =
888 0,-32768,-32768,-32768
890 static const short yytable[] =
892 10, 1, 5, 4, 11, 12, 7, 9
894 static const short yycheck[] =
896 0, 3, 6, 4, 0, 0, 5, 7