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
338 expr -> 'a' . @1 'b' (rule 2)
340 $default reduce using rule 1 (@1)
348 $axiom -> expr . $ (rule 0)
350 $ shift, and go to state 5
356 expr -> @2 . 'c' (rule 4)
358 'c' shift, and go to state 6
364 expr -> 'a' @1 . 'b' (rule 2)
366 'b' shift, and go to state 7
372 $axiom -> expr $ . (rule 0)
379 expr -> @2 'c' . (rule 4)
381 $default reduce using rule 4 (expr)
387 expr -> 'a' @1 'b' . (rule 2)
389 $default reduce using rule 2 (expr)
399 ## -------------------- ##
400 ## %expect not enough. ##
401 ## -------------------- ##
403 AT_SETUP([%expect not enough])
409 exp: exp OP exp | NUM;
412 AT_CHECK([bison input.y -o input.c], 1, [],
413 [input.y contains 1 shift/reduce conflict.
414 expected 0 shift/reduce conflicts
419 ## --------------- ##
421 ## --------------- ##
423 AT_SETUP([%expect right])
429 exp: exp OP exp | NUM;
432 AT_CHECK([bison input.y -o input.c], 0)
436 ## ------------------ ##
437 ## %expect too much. ##
438 ## ------------------ ##
440 AT_SETUP([%expect too much])
446 exp: exp OP exp | NUM;
449 AT_CHECK([bison input.y -o input.c], 1, [],
450 [input.y contains 1 shift/reduce conflict.
451 expected 2 shift/reduce conflicts
456 ## ---------------------- ##
457 ## Mixing %token styles. ##
458 ## ---------------------- ##
461 AT_SETUP([Mixing %token styles])
463 # Taken from the documentation.
465 [[%token <operator> OR "||"
466 %token <operator> LE 134 "<="
473 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
479 ## ---------------------- ##
480 ## %union and --defines. ##
481 ## ---------------------- ##
484 AT_SETUP([%union and --defines])
496 AT_CHECK([bison --defines input.y])
501 ## --------------------------------------- ##
502 ## Duplicate '/' in C comments in %union ##
503 ## --------------------------------------- ##
506 AT_SETUP([%union and C comments])
511 /* The int. */ int integer;
512 /* The string. */ char *string ;
518 AT_CHECK([bison input.y -o input.c])
519 AT_CHECK([fgrep '//*' input.c], [1], [])
524 ## ----------------- ##
525 ## Invalid input 1. ##
526 ## ----------------- ##
529 AT_SETUP([Invalid input: 1])
536 AT_CHECK([bison input.y], [1], [],
537 [[input.y:2: invalid input: `?'
538 input.y:3: fatal error: no rules in the input grammar
544 ## ----------------- ##
545 ## Invalid input 2. ##
546 ## ----------------- ##
549 AT_SETUP([Invalid input: 2])
556 AT_CHECK([bison input.y], [1], [],
557 [[input.y:2: invalid input: `}'
564 ## -------------------- ##
565 ## Invalid %directive. ##
566 ## -------------------- ##
569 AT_SETUP([Invalid %directive])
575 AT_CHECK([bison input.y], [1], [],
576 [[input.y:1: unrecognized: %invalid
577 input.y:1: Skipping to next %
578 input.y:2: fatal error: no input grammar
585 ## --------------------- ##
586 ## Invalid CPP headers. ##
587 ## --------------------- ##
589 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
590 # -------------------------------------
591 m4_define([AT_TEST_CPP_GUARD_H],
592 [AT_SETUP([Invalid CPP guards: $1])
594 # Possibly create inner directories.
595 dirname=`AS_DIRNAME([$1])`
596 AS_MKDIR_P([$dirname])
603 AT_CHECK([bison --defines=$1.h $1.y])
605 # CPP should be happy with it.
606 AT_CHECK([$CC -E $1.h], 0, [ignore])
611 AT_TEST_CPP_GUARD_H([input/input])
612 AT_TEST_CPP_GUARD_H([9foo])
620 # The generation of the reduction was once wrong in Bison, and made it
621 # miss some reductions. In the following test case, the reduction on
622 # `undef_id_tok' in state 1 was missing. This is stripped down from
623 # the actual web2c.y.
625 AT_SETUP([Web2c Report])
628 [[%token undef_id_tok const_id_tok
630 %start CONST_DEC_PART
639 | CONST_DEC_LIST CONST_DEC
643 { } undef_id_tok '=' const_id_tok ';'
649 AT_CHECK([bison -v input.y])
651 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
654 1 6 CONST_DEC_PART -> CONST_DEC_LIST
655 2 10 CONST_DEC_LIST -> CONST_DEC
656 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
657 4 15 @1 -> /* empty */
658 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
659 Terminals, with rules where they appear
666 Nonterminals, with rules where they appear
670 on left: 2 3, on right: 1 3
672 on left: 5, on right: 2 3
674 on left: 4, on right: 5
676 $default reduce using rule 4 (@1)
677 CONST_DEC_PART go to state 9
678 CONST_DEC_LIST go to state 1
679 CONST_DEC go to state 2
682 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
683 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
684 undef_id_tok reduce using rule 4 (@1)
685 $default reduce using rule 1 (CONST_DEC_PART)
686 CONST_DEC go to state 4
689 CONST_DEC_LIST -> CONST_DEC . (rule 2)
690 $default reduce using rule 2 (CONST_DEC_LIST)
692 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
693 undef_id_tok shift, and go to state 5
695 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
696 $default reduce using rule 3 (CONST_DEC_LIST)
698 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
699 '=' shift, and go to state 6
701 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
702 const_id_tok shift, and go to state 7
704 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
705 ';' shift, and go to state 8
707 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
708 $default reduce using rule 5 (CONST_DEC)
710 $ shift, and go to state 10
718 ## --------------- ##
720 ## --------------- ##
722 # The generation of the mapping `state -> action' was once wrong in
723 # extremely specific situations. web2c.y exhibits this situation.
724 # Below is a stripped version of the grammar. It looks like one can
725 # simplify it further, but just don't: it is tuned to exhibit a bug,
726 # which disapears when applying sane grammar transformations.
728 # It used to be wrong on yydefact only:
730 # static const short yydefact[] =
732 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
733 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
737 # but let's check all the tables.
740 AT_SETUP([Web2c Actions])
744 statement: struct_stat;
745 struct_stat: /* empty. */ | if else;
746 if: "if" "const" "then" statement;
747 else: "else" statement;
751 AT_CHECK([bison -v input.y -o input.c])
753 # Check only the tables. We don't use --no-parser, because it is
754 # still to be implemented in the experimental branch of Bison.
755 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
756 [[static const char yytranslate[] =
758 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
759 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
760 2, 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, 1, 3, 4, 5,
786 static const short yyprhs[] =
790 static const short yyrhs[] =
792 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
795 static const short yyrline[] =
799 static const char *const yytname[] =
801 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
802 "\"else\"", "statement", "struct_stat", "if", "else", NULL
804 static const short yytoknum[] =
806 0, 256, 2, 257, 258, 259, 260, -1
808 static const short yyr1[] =
812 static const short yyr2[] =
816 static const short yydefact[] =
818 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
821 static const short yydefgoto[] =
825 static const short yypact[] =
827 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
830 static const short yypgoto[] =
832 0,-32768,-32768,-32768
834 static const short yytable[] =
836 10, 1, 5, 4, 11, 0, 7, 9
838 static const short yycheck[] =
840 0, 3, 6, 4, 0, -1, 5, 7