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])
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 input.y -o input.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 5 contains 1 shift/reduce conflict.
167 1 3 exp -> exp OP exp
171 Terminals, with rules where they appear
179 Nonterminals, with rules where they appear
184 on left: 1 2, on right: 0 1
189 NUM shift, and go to state 1
197 exp -> NUM . (rule 2)
199 $default reduce using rule 2 (exp)
205 $axiom -> exp . $ (rule 0)
206 exp -> exp . OP exp (rule 1)
208 $ shift, and go to state 3
209 OP shift, and go to state 4
215 $axiom -> exp $ . (rule 0)
222 exp -> exp OP . exp (rule 1)
224 NUM shift, and go to state 1
232 exp -> exp . OP exp (rule 1)
233 exp -> exp OP exp . (rule 1)
235 OP shift, and go to state 4
237 OP [reduce using rule 1 (exp)]
238 $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 5 between rule 2 and token OP resolved as shift.
271 1 4 exp -> exp OP exp
275 Terminals, with rules where they appear
283 Nonterminals, with rules where they appear
288 on left: 1 2, on right: 0 1
293 NUM shift, and go to state 1
301 exp -> NUM . (rule 2)
303 $default reduce using rule 2 (exp)
309 $axiom -> exp . $ (rule 0)
310 exp -> exp . OP exp (rule 1)
312 $ shift, and go to state 3
313 OP shift, and go to state 4
319 $axiom -> exp $ . (rule 0)
326 exp -> exp OP . exp (rule 1)
328 NUM shift, and go to state 1
336 exp -> exp . OP exp (rule 1)
337 exp -> exp OP exp . (rule 1)
339 OP shift, and go to state 4
341 $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], [],
396 1 2 @1 -> /* empty */
397 2 2 expr -> 'a' @1 'b'
398 3 15 @2 -> /* empty */
402 Terminals, with rules where they appear
411 Nonterminals, with rules where they appear
416 on left: 2 4, on right: 0
418 on left: 1, on right: 2
420 on left: 3, on right: 4
425 'a' shift, and go to state 1
427 $default reduce using rule 3 (@2)
436 expr -> 'a' . @1 'b' (rule 2)
438 $default reduce using rule 1 (@1)
446 $axiom -> expr . $ (rule 0)
448 $ shift, and go to state 5
454 expr -> @2 . 'c' (rule 4)
456 'c' shift, and go to state 6
462 expr -> 'a' @1 . 'b' (rule 2)
464 'b' shift, and go to state 7
470 $axiom -> expr $ . (rule 0)
477 expr -> @2 'c' . (rule 4)
479 $default reduce using rule 4 (expr)
485 expr -> 'a' @1 'b' . (rule 2)
487 $default reduce using rule 2 (expr)
497 ## -------------------- ##
498 ## %expect not enough. ##
499 ## -------------------- ##
501 AT_SETUP([%expect not enough])
507 exp: exp OP exp | NUM;
510 AT_CHECK([bison input.y -o input.c], 1, [],
511 [input.y contains 1 shift/reduce conflict.
512 expected 0 shift/reduce conflicts
517 ## --------------- ##
519 ## --------------- ##
521 AT_SETUP([%expect right])
527 exp: exp OP exp | NUM;
530 AT_CHECK([bison input.y -o input.c], 0)
534 ## ------------------ ##
535 ## %expect too much. ##
536 ## ------------------ ##
538 AT_SETUP([%expect too much])
544 exp: exp OP exp | NUM;
547 AT_CHECK([bison input.y -o input.c], 1, [],
548 [input.y contains 1 shift/reduce conflict.
549 expected 2 shift/reduce conflicts
554 ## ---------------------- ##
555 ## Mixing %token styles. ##
556 ## ---------------------- ##
559 AT_SETUP([Mixing %token styles])
561 # Taken from the documentation.
563 [[%token <operator> OR "||"
564 %token <operator> LE 134 "<="
571 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
577 ## ---------------- ##
578 ## Invalid inputs. ##
579 ## ---------------- ##
582 AT_SETUP([Invalid inputs])
594 AT_CHECK([bison input.y], [1], [],
595 [[input.y:2: invalid input: `?'
596 input.y:3: invalid input: `}'
597 input.y:4: invalid input: `%{'
598 input.y:5: invalid input: `%&'
599 input.y:6: invalid input: `%a'
600 input.y:7: invalid input: `%-'
607 ## -------------------- ##
608 ## Invalid %directive. ##
609 ## -------------------- ##
612 AT_SETUP([Invalid %directive])
618 AT_CHECK([bison input.y], [1], [],
619 [[input.y:1: unrecognized: %invalid
620 input.y:1: Skipping to next %
621 input.y:2: fatal error: no input grammar
632 # The generation of the reduction was once wrong in Bison, and made it
633 # miss some reductions. In the following test case, the reduction on
634 # `undef_id_tok' in state 1 was missing. This is stripped down from
635 # the actual web2c.y.
637 AT_SETUP([Web2c Report])
640 [[%token undef_id_tok const_id_tok
642 %start CONST_DEC_PART
651 | CONST_DEC_LIST CONST_DEC
655 { } undef_id_tok '=' const_id_tok ';'
661 AT_CHECK([bison -v input.y])
663 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
666 0 6 $axiom -> CONST_DEC_PART $
667 1 6 CONST_DEC_PART -> CONST_DEC_LIST
668 2 10 CONST_DEC_LIST -> CONST_DEC
669 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
670 4 15 @1 -> /* empty */
671 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
672 Terminals, with rules where they appear
679 Nonterminals, with rules where they appear
683 on left: 1, on right: 0
685 on left: 2 3, on right: 1 3
687 on left: 5, on right: 2 3
689 on left: 4, on right: 5
691 $default reduce using rule 4 (@1)
692 CONST_DEC_PART go to state 1
693 CONST_DEC_LIST go to state 2
694 CONST_DEC go to state 3
697 $axiom -> CONST_DEC_PART . $ (rule 0)
698 $ shift, and go to state 5
700 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
701 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
702 undef_id_tok reduce using rule 4 (@1)
703 $default reduce using rule 1 (CONST_DEC_PART)
704 CONST_DEC go to state 6
707 CONST_DEC_LIST -> CONST_DEC . (rule 2)
708 $default reduce using rule 2 (CONST_DEC_LIST)
710 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
711 undef_id_tok shift, and go to state 7
713 $axiom -> CONST_DEC_PART $ . (rule 0)
716 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
717 $default reduce using rule 3 (CONST_DEC_LIST)
719 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
720 '=' shift, and go to state 8
722 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
723 const_id_tok shift, and go to state 9
725 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
726 ';' shift, and go to state 10
728 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
729 $default reduce using rule 5 (CONST_DEC)
735 ## --------------- ##
737 ## --------------- ##
739 # The generation of the mapping `state -> action' was once wrong in
740 # extremely specific situations. web2c.y exhibits this situation.
741 # Below is a stripped version of the grammar. It looks like one can
742 # simplify it further, but just don't: it is tuned to exhibit a bug,
743 # which disapears when applying sane grammar transformations.
745 # It used to be wrong on yydefact only:
747 # static const short yydefact[] =
749 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
750 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
754 # but let's check all the tables.
757 AT_SETUP([Web2c Actions])
761 statement: struct_stat;
762 struct_stat: /* empty. */ | if else;
763 if: "if" "const" "then" statement;
764 else: "else" statement;
768 AT_CHECK([bison -v input.y -o input.c])
770 # Check only the tables. We don't use --no-parser, because it is
771 # still to be implemented in the experimental branch of Bison.
772 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
773 [[static const char yytranslate[] =
775 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
776 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
777 2, 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, 1, 3, 4, 5,
803 static const short yyprhs[] =
807 static const short yyrhs[] =
809 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
810 4, 5, 8, -1, 6, 8, -1
812 static const short yyrline[] =
816 static const char *const yytname[] =
818 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
819 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
821 static const short yytoknum[] =
823 0, 256, 2, 257, 258, 259, 260, -1
825 static const short yyr1[] =
827 0, 7, 8, 9, 9, 10, 11
829 static const short yyr2[] =
833 static const short yydefact[] =
835 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
838 static const short yydefgoto[] =
842 static const short yypact[] =
844 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
847 static const short yypgoto[] =
849 -32768, -7,-32768,-32768,-32768
851 static const short yytable[] =
853 10, 1, 11, 5, 6, 0, 7, 9
855 static const short yycheck[] =
857 7, 3, 9, 4, 0, -1, 6, 5