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])
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 input.y -o input.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 5 contains 1 shift/reduce conflict.
169 1 3 exp -> exp OP exp
173 Terminals, with rules where they appear
181 Nonterminals, with rules where they appear
186 on left: 1 2, on right: 0 1
191 NUM shift, and go to state 1
199 exp -> NUM . (rule 2)
201 $default reduce using rule 2 (exp)
207 $axiom -> exp . $ (rule 0)
208 exp -> exp . OP exp (rule 1)
210 $ shift, and go to state 3
211 OP shift, and go to state 4
217 $axiom -> exp $ . (rule 0)
224 exp -> exp OP . exp (rule 1)
226 NUM shift, and go to state 1
234 exp -> exp . OP exp (rule 1)
235 exp -> exp OP exp . (rule 1)
237 OP shift, and go to state 4
239 OP [reduce using rule 1 (exp)]
240 $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 5 between rule 2 and token OP resolved as shift.
273 1 4 exp -> exp OP exp
277 Terminals, with rules where they appear
285 Nonterminals, with rules where they appear
290 on left: 1 2, on right: 0 1
295 NUM shift, and go to state 1
303 exp -> NUM . (rule 2)
305 $default reduce using rule 2 (exp)
311 $axiom -> exp . $ (rule 0)
312 exp -> exp . OP exp (rule 1)
314 $ shift, and go to state 3
315 OP shift, and go to state 4
321 $axiom -> exp $ . (rule 0)
328 exp -> exp OP . exp (rule 1)
330 NUM shift, and go to state 1
338 exp -> exp . OP exp (rule 1)
339 exp -> exp OP exp . (rule 1)
341 OP shift, and go to state 4
343 $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], [],
398 1 2 @1 -> /* empty */
399 2 2 expr -> 'a' @1 'b'
400 3 15 @2 -> /* empty */
404 Terminals, with rules where they appear
413 Nonterminals, with rules where they appear
418 on left: 2 4, on right: 0
420 on left: 1, on right: 2
422 on left: 3, on right: 4
427 'a' shift, and go to state 1
429 $default reduce using rule 3 (@2)
438 expr -> 'a' . @1 'b' (rule 2)
440 $default reduce using rule 1 (@1)
448 $axiom -> expr . $ (rule 0)
450 $ shift, and go to state 5
456 expr -> @2 . 'c' (rule 4)
458 'c' shift, and go to state 6
464 expr -> 'a' @1 . 'b' (rule 2)
466 'b' shift, and go to state 7
472 $axiom -> expr $ . (rule 0)
479 expr -> @2 'c' . (rule 4)
481 $default reduce using rule 4 (expr)
487 expr -> 'a' @1 'b' . (rule 2)
489 $default reduce using rule 2 (expr)
499 ## -------------------- ##
500 ## %expect not enough. ##
501 ## -------------------- ##
503 AT_SETUP([%expect not enough])
509 exp: exp OP exp | NUM;
512 AT_CHECK([bison input.y -o input.c], 1, [],
513 [input.y contains 1 shift/reduce conflict.
514 expected 0 shift/reduce conflicts
519 ## --------------- ##
521 ## --------------- ##
523 AT_SETUP([%expect right])
529 exp: exp OP exp | NUM;
532 AT_CHECK([bison input.y -o input.c], 0)
536 ## ------------------ ##
537 ## %expect too much. ##
538 ## ------------------ ##
540 AT_SETUP([%expect too much])
546 exp: exp OP exp | NUM;
549 AT_CHECK([bison input.y -o input.c], 1, [],
550 [input.y contains 1 shift/reduce conflict.
551 expected 2 shift/reduce conflicts
556 ## ---------------------- ##
557 ## Mixing %token styles. ##
558 ## ---------------------- ##
561 AT_SETUP([Mixing %token styles])
563 # Taken from the documentation.
565 [[%token <operator> OR "||"
566 %token <operator> LE 134 "<="
573 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
579 ## ---------------- ##
580 ## Invalid inputs. ##
581 ## ---------------- ##
584 AT_SETUP([Invalid inputs])
596 AT_CHECK([bison input.y], [1], [],
597 [[input.y:2: invalid input: `?'
598 input.y:3: invalid input: `}'
599 input.y:4: invalid input: `%{'
600 input.y:5: invalid input: `%&'
601 input.y:6: invalid input: `%a'
602 input.y:7: invalid input: `%-'
609 ## -------------------- ##
610 ## Invalid %directive. ##
611 ## -------------------- ##
614 AT_SETUP([Invalid %directive])
620 AT_CHECK([bison input.y], [1], [],
621 [[input.y:1: unrecognized: %invalid
622 input.y:1: Skipping to next %
623 input.y:2: fatal error: no input grammar
634 # The generation of the reduction was once wrong in Bison, and made it
635 # miss some reductions. In the following test case, the reduction on
636 # `undef_id_tok' in state 1 was missing. This is stripped down from
637 # the actual web2c.y.
639 AT_SETUP([Web2c Report])
642 [[%token undef_id_tok const_id_tok
644 %start CONST_DEC_PART
653 | CONST_DEC_LIST CONST_DEC
657 { } undef_id_tok '=' const_id_tok ';'
663 AT_CHECK([bison -v input.y])
665 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
668 0 6 $axiom -> CONST_DEC_PART $
669 1 6 CONST_DEC_PART -> CONST_DEC_LIST
670 2 10 CONST_DEC_LIST -> CONST_DEC
671 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
672 4 15 @1 -> /* empty */
673 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
674 Terminals, with rules where they appear
681 Nonterminals, with rules where they appear
685 on left: 1, on right: 0
687 on left: 2 3, on right: 1 3
689 on left: 5, on right: 2 3
691 on left: 4, on right: 5
693 $default reduce using rule 4 (@1)
694 CONST_DEC_PART go to state 1
695 CONST_DEC_LIST go to state 2
696 CONST_DEC go to state 3
699 $axiom -> CONST_DEC_PART . $ (rule 0)
700 $ shift, and go to state 5
702 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
703 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
704 undef_id_tok reduce using rule 4 (@1)
705 $default reduce using rule 1 (CONST_DEC_PART)
706 CONST_DEC go to state 6
709 CONST_DEC_LIST -> CONST_DEC . (rule 2)
710 $default reduce using rule 2 (CONST_DEC_LIST)
712 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
713 undef_id_tok shift, and go to state 7
715 $axiom -> CONST_DEC_PART $ . (rule 0)
718 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
719 $default reduce using rule 3 (CONST_DEC_LIST)
721 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
722 '=' shift, and go to state 8
724 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
725 const_id_tok shift, and go to state 9
727 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
728 ';' shift, and go to state 10
730 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
731 $default reduce using rule 5 (CONST_DEC)
737 ## --------------- ##
739 ## --------------- ##
741 # The generation of the mapping `state -> action' was once wrong in
742 # extremely specific situations. web2c.y exhibits this situation.
743 # Below is a stripped version of the grammar. It looks like one can
744 # simplify it further, but just don't: it is tuned to exhibit a bug,
745 # which disapears when applying sane grammar transformations.
747 # It used to be wrong on yydefact only:
749 # static const short yydefact[] =
751 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
752 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
756 # but let's check all the tables.
759 AT_SETUP([Web2c Actions])
763 statement: struct_stat;
764 struct_stat: /* empty. */ | if else;
765 if: "if" "const" "then" statement;
766 else: "else" statement;
770 AT_CHECK([bison -v input.y -o input.c])
772 # Check only the tables. We don't use --no-parser, because it is
773 # still to be implemented in the experimental branch of Bison.
774 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
775 [[static const char yytranslate[] =
777 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
778 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
779 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
780 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
781 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
782 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
783 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
784 2, 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, 1, 3, 4, 5,
805 static const short yyprhs[] =
809 static const short yyrhs[] =
811 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
812 4, 5, 8, -1, 6, 8, -1
814 static const short yyrline[] =
818 static const char *const yytname[] =
820 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
821 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", NULL
823 static const short yytoknum[] =
825 0, 256, 2, 257, 258, 259, 260, -1
827 static const short yyr1[] =
829 0, 7, 8, 9, 9, 10, 11
831 static const short yyr2[] =
835 static const short yydefact[] =
837 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
840 static const short yydefgoto[] =
844 static const short yypact[] =
846 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
849 static const short yypgoto[] =
851 -32768, -7,-32768,-32768,-32768
853 static const short yytable[] =
855 10, 1, 11, 5, 6, 0, 7, 9
857 static const short yycheck[] =
859 7, 3, 9, 4, 0, -1, 6, 5