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.]])
21 ## ------------------ ##
22 ## Duplicate string. ##
23 ## ------------------ ##
26 AT_SETUP([Duplicate string])
29 [[/* `Bison -v' used to dump core when two tokens are defined with the same
30 string, as LE and GE below. */
37 exp: '(' exp ')' | NUM ;
41 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
46 ## ------------------------- ##
47 ## Unresolved SR Conflicts. ##
48 ## ------------------------- ##
50 AT_SETUP([Unresolved SR Conflicts])
55 exp: exp OP exp | NUM;
58 AT_CHECK([bison input.y -o input.c -v], 0, [],
59 [input.y contains 1 shift/reduce conflict.
62 # Check the contents of the report.
63 AT_CHECK([cat input.output], [],
64 [[State 5 contains 1 shift/reduce conflict.
75 Terminals, with rules where they appear
83 Nonterminals, with rules where they appear
88 on left: 1 2, on right: 0 1
93 NUM shift, and go to state 1
101 exp -> NUM . (rule 2)
103 $default reduce using rule 2 (exp)
109 $axiom -> exp . $ (rule 0)
110 exp -> exp . OP exp (rule 1)
112 $ shift, and go to state 3
113 OP shift, and go to state 4
119 $axiom -> exp $ . (rule 0)
126 exp -> exp OP . exp (rule 1)
128 NUM shift, and go to state 1
136 exp -> exp . OP exp (rule 1)
137 exp -> exp OP exp . (rule 1)
139 OP shift, and go to state 4
141 OP [reduce using rule 1 (exp)]
142 $default reduce using rule 1 (exp)
151 ## --------------------- ##
152 ## Solved SR Conflicts. ##
153 ## --------------------- ##
155 AT_SETUP([Solved SR Conflicts])
161 exp: exp OP exp | NUM;
164 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
166 # Check the contents of the report.
167 AT_CHECK([cat input.output], [],
168 [[Conflict in state 5 between rule 2 and token OP resolved as shift.
175 1 4 exp -> exp OP exp
179 Terminals, with rules where they appear
187 Nonterminals, with rules where they appear
192 on left: 1 2, on right: 0 1
197 NUM shift, and go to state 1
205 exp -> NUM . (rule 2)
207 $default reduce using rule 2 (exp)
213 $axiom -> exp . $ (rule 0)
214 exp -> exp . OP exp (rule 1)
216 $ shift, and go to state 3
217 OP shift, and go to state 4
223 $axiom -> exp $ . (rule 0)
230 exp -> exp OP . exp (rule 1)
232 NUM shift, and go to state 1
240 exp -> exp . OP exp (rule 1)
241 exp -> exp OP exp . (rule 1)
243 OP shift, and go to state 4
245 $default reduce using rule 1 (exp)
256 ## ------------------- ##
257 ## Rule Line Numbers. ##
258 ## ------------------- ##
260 AT_SETUP([Rule Line Numbers])
292 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
294 # Check the contents of the report.
295 AT_CHECK([cat input.output], [],
299 0 28 $axiom -> expr $
300 1 2 @1 -> /* empty */
301 2 2 expr -> 'a' @1 'b'
302 3 15 @2 -> /* empty */
306 Terminals, with rules where they appear
315 Nonterminals, with rules where they appear
320 on left: 2 4, on right: 0
322 on left: 1, on right: 2
324 on left: 3, on right: 4
329 'a' shift, and go to state 1
331 $default reduce using rule 3 (@2)
340 expr -> 'a' . @1 'b' (rule 2)
342 $default reduce using rule 1 (@1)
350 $axiom -> expr . $ (rule 0)
352 $ shift, and go to state 5
358 expr -> @2 . 'c' (rule 4)
360 'c' shift, and go to state 6
366 expr -> 'a' @1 . 'b' (rule 2)
368 'b' shift, and go to state 7
374 $axiom -> expr $ . (rule 0)
381 expr -> @2 'c' . (rule 4)
383 $default reduce using rule 4 (expr)
389 expr -> 'a' @1 'b' . (rule 2)
391 $default reduce using rule 2 (expr)
401 ## -------------------- ##
402 ## %expect not enough. ##
403 ## -------------------- ##
405 AT_SETUP([%expect not enough])
411 exp: exp OP exp | NUM;
414 AT_CHECK([bison input.y -o input.c], 1, [],
415 [input.y contains 1 shift/reduce conflict.
416 expected 0 shift/reduce conflicts
421 ## --------------- ##
423 ## --------------- ##
425 AT_SETUP([%expect right])
431 exp: exp OP exp | NUM;
434 AT_CHECK([bison input.y -o input.c], 0)
438 ## ------------------ ##
439 ## %expect too much. ##
440 ## ------------------ ##
442 AT_SETUP([%expect too much])
448 exp: exp OP exp | NUM;
451 AT_CHECK([bison input.y -o input.c], 1, [],
452 [input.y contains 1 shift/reduce conflict.
453 expected 2 shift/reduce conflicts
458 ## ---------------------- ##
459 ## Mixing %token styles. ##
460 ## ---------------------- ##
463 AT_SETUP([Mixing %token styles])
465 # Taken from the documentation.
467 [[%token <operator> OR "||"
468 %token <operator> LE 134 "<="
475 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
481 ## ---------------------- ##
482 ## %union and --defines. ##
483 ## ---------------------- ##
486 AT_SETUP([%union and --defines])
498 AT_CHECK([bison --defines input.y])
503 ## --------------------------------------- ##
504 ## Duplicate '/' in C comments in %union ##
505 ## --------------------------------------- ##
508 AT_SETUP([%union and C comments])
513 /* The int. */ int integer;
514 /* The string. */ char *string ;
520 AT_CHECK([bison input.y -o input.c])
521 AT_CHECK([fgrep '//*' input.c], [1], [])
526 ## ----------------- ##
527 ## Invalid input 1. ##
528 ## ----------------- ##
531 AT_SETUP([Invalid input: 1])
538 AT_CHECK([bison input.y], [1], [],
539 [[input.y:2: invalid input: `?'
540 input.y:3: fatal error: no rules in the input grammar
546 ## ----------------- ##
547 ## Invalid input 2. ##
548 ## ----------------- ##
551 AT_SETUP([Invalid input: 2])
558 AT_CHECK([bison input.y], [1], [],
559 [[input.y:2: invalid input: `}'
566 ## -------------------- ##
567 ## Invalid %directive. ##
568 ## -------------------- ##
571 AT_SETUP([Invalid %directive])
577 AT_CHECK([bison input.y], [1], [],
578 [[input.y:1: unrecognized: %invalid
579 input.y:1: Skipping to next %
580 input.y:2: fatal error: no input grammar
587 ## --------------------- ##
588 ## Invalid CPP headers. ##
589 ## --------------------- ##
591 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
592 # -------------------------------------
593 m4_define([AT_TEST_CPP_GUARD_H],
594 [AT_SETUP([Invalid CPP guards: $1])
596 # Possibly create inner directories.
597 dirname=`AS_DIRNAME([$1])`
598 AS_MKDIR_P([$dirname])
605 AT_CHECK([bison --defines=$1.h $1.y])
607 # CPP should be happy with it.
608 AT_CHECK([$CC -E $1.h], 0, [ignore])
613 AT_TEST_CPP_GUARD_H([input/input])
614 AT_TEST_CPP_GUARD_H([9foo])
622 # The generation of the reduction was once wrong in Bison, and made it
623 # miss some reductions. In the following test case, the reduction on
624 # `undef_id_tok' in state 1 was missing. This is stripped down from
625 # the actual web2c.y.
627 AT_SETUP([Web2c Report])
630 [[%token undef_id_tok const_id_tok
632 %start CONST_DEC_PART
641 | CONST_DEC_LIST CONST_DEC
645 { } undef_id_tok '=' const_id_tok ';'
651 AT_CHECK([bison -v input.y])
653 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
656 1 6 CONST_DEC_PART -> CONST_DEC_LIST
657 2 10 CONST_DEC_LIST -> CONST_DEC
658 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
659 4 15 @1 -> /* empty */
660 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
661 Terminals, with rules where they appear
668 Nonterminals, with rules where they appear
672 on left: 2 3, on right: 1 3
674 on left: 5, on right: 2 3
676 on left: 4, on right: 5
678 $default reduce using rule 4 (@1)
679 CONST_DEC_PART go to state 9
680 CONST_DEC_LIST go to state 1
681 CONST_DEC go to state 2
684 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
685 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
686 undef_id_tok reduce using rule 4 (@1)
687 $default reduce using rule 1 (CONST_DEC_PART)
688 CONST_DEC go to state 4
691 CONST_DEC_LIST -> CONST_DEC . (rule 2)
692 $default reduce using rule 2 (CONST_DEC_LIST)
694 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
695 undef_id_tok shift, and go to state 5
697 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
698 $default reduce using rule 3 (CONST_DEC_LIST)
700 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
701 '=' shift, and go to state 6
703 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
704 const_id_tok shift, and go to state 7
706 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
707 ';' shift, and go to state 8
709 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
710 $default reduce using rule 5 (CONST_DEC)
712 $ shift, and go to state 10
720 ## --------------- ##
722 ## --------------- ##
724 # The generation of the mapping `state -> action' was once wrong in
725 # extremely specific situations. web2c.y exhibits this situation.
726 # Below is a stripped version of the grammar. It looks like one can
727 # simplify it further, but just don't: it is tuned to exhibit a bug,
728 # which disapears when applying sane grammar transformations.
730 # It used to be wrong on yydefact only:
732 # static const short yydefact[] =
734 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
735 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
739 # but let's check all the tables.
742 AT_SETUP([Web2c Actions])
746 statement: struct_stat;
747 struct_stat: /* empty. */ | if else;
748 if: "if" "const" "then" statement;
749 else: "else" statement;
753 AT_CHECK([bison -v input.y -o input.c])
755 # Check only the tables. We don't use --no-parser, because it is
756 # still to be implemented in the experimental branch of Bison.
757 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
758 [[static const char yytranslate[] =
760 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
761 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
763 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
764 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
765 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
766 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
767 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
768 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
769 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
770 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
771 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
772 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
773 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
774 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
775 2, 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, 1, 3, 4, 5,
788 static const short yyprhs[] =
792 static const short yyrhs[] =
794 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
797 static const short yyrline[] =
801 static const char *const yytname[] =
803 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
804 "\"else\"", "statement", "struct_stat", "if", "else", NULL
806 static const short yytoknum[] =
808 0, 256, 2, 257, 258, 259, 260, -1
810 static const short yyr1[] =
814 static const short yyr2[] =
818 static const short yydefact[] =
820 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
823 static const short yydefgoto[] =
827 static const short yypact[] =
829 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
832 static const short yypgoto[] =
834 0,-32768,-32768,-32768
836 static const short yytable[] =
838 10, 1, 5, 4, 11, 0, 7, 9
840 static const short yycheck[] =
842 0, 3, 6, 4, 0, -1, 5, 7