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])
28 AT_DATA([duplicate.y],
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 duplicate.y -o duplicate.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 4 contains 1 shift/reduce conflict.
74 Terminals, with rules where they appear
82 Nonterminals, with rules where they appear
85 on left: 1 2, on right: 1
90 NUM shift, and go to state 1
100 $default reduce using rule 2 (exp)
106 exp -> exp . OP exp (rule 1)
109 OP shift, and go to state 3
115 exp -> exp OP . exp (rule 1)
117 NUM shift, and go to state 1
125 exp -> exp . OP exp (rule 1)
126 exp -> exp OP exp . (rule 1)
128 OP shift, and go to state 3
130 OP [reduce using rule 1 (exp)]
131 $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 4 between rule 1 and token OP resolved as shift.
174 1 4 exp -> exp OP exp
178 Terminals, with rules where they appear
186 Nonterminals, with rules where they appear
189 on left: 1 2, on right: 1
194 NUM shift, and go to state 1
202 exp -> NUM . (rule 2)
204 $default reduce using rule 2 (exp)
210 exp -> exp . OP exp (rule 1)
213 OP shift, and go to state 3
219 exp -> exp OP . exp (rule 1)
221 NUM shift, and go to state 1
229 exp -> exp . OP exp (rule 1)
230 exp -> exp OP exp . (rule 1)
232 OP shift, and go to state 3
234 $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 1 2 @1 -> /* empty */
300 2 2 expr -> 'a' @1 'b'
301 3 15 @2 -> /* empty */
305 Terminals, with rules where they appear
314 Nonterminals, with rules where they appear
319 on left: 1, on right: 2
321 on left: 3, on right: 4
326 'a' shift, and go to state 1
328 $default reduce using rule 3 (@2)
337 expr -> 'a' . @1 'b' (rule 2)
339 $default reduce using rule 1 (@1)
347 expr -> @2 . 'c' (rule 4)
349 'c' shift, and go to state 4
355 expr -> 'a' @1 . 'b' (rule 2)
357 'b' shift, and go to state 5
363 expr -> @2 'c' . (rule 4)
365 $default reduce using rule 4 (expr)
371 expr -> 'a' @1 'b' . (rule 2)
373 $default reduce using rule 2 (expr)
400 ## -------------------- ##
401 ## %expect not enough. ##
402 ## -------------------- ##
404 AT_SETUP([%expect not enough])
410 exp: exp OP exp | NUM;
413 AT_CHECK([bison input.y -o input.c], 1, [],
414 [input.y contains 1 shift/reduce conflict.
415 expected 0 shift/reduce conflicts
420 ## --------------- ##
422 ## --------------- ##
424 AT_SETUP([%expect right])
430 exp: exp OP exp | NUM;
433 AT_CHECK([bison input.y -o input.c], 0)
437 ## ------------------ ##
438 ## %expect too much. ##
439 ## ------------------ ##
441 AT_SETUP([%expect too much])
447 exp: exp OP exp | NUM;
450 AT_CHECK([bison input.y -o input.c], 1, [],
451 [input.y contains 1 shift/reduce conflict.
452 expected 2 shift/reduce conflicts
457 ## ---------------------- ##
458 ## Mixing %token styles. ##
459 ## ---------------------- ##
462 AT_SETUP([Mixing %token styles])
464 # Taken from the documentation.
466 [[%token <operator> OR "||"
467 %token <operator> LE 134 "<="
474 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
480 ## ---------------------- ##
481 ## %union and --defines. ##
482 ## ---------------------- ##
485 AT_SETUP([%union and --defines])
497 AT_CHECK([bison --defines union.y])
502 ## --------------------------------------- ##
503 ## Duplicate '/' in C comments in %union ##
504 ## --------------------------------------- ##
507 AT_SETUP([%union and C comments])
509 AT_DATA([union-comment.y],
512 /* The int. */ int integer;
513 /* The string. */ char *string ;
519 AT_CHECK([bison union-comment.y])
520 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
525 ## ----------------- ##
526 ## Invalid input 1. ##
527 ## ----------------- ##
530 AT_SETUP([Invalid input: 1])
537 AT_CHECK([bison input.y], [1], [],
538 [[input.y:2: invalid input: `?'
539 input.y:3: fatal error: no rules in the input grammar
545 ## ----------------- ##
546 ## Invalid input 2. ##
547 ## ----------------- ##
550 AT_SETUP([Invalid input: 2])
557 AT_CHECK([bison input.y], [1], [],
558 [[input.y:2: invalid input: `}'
565 ## -------------------- ##
566 ## Invalid %directive. ##
567 ## -------------------- ##
570 AT_SETUP([Invalid %directive])
576 AT_CHECK([bison input.y], [1], [],
577 [[input.y:1: unrecognized: %invalid
578 input.y:1: Skipping to next %
579 input.y:2: fatal error: no input grammar
586 ## --------------------- ##
587 ## Invalid CPP headers. ##
588 ## --------------------- ##
590 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
591 # -------------------------------------
592 m4_define([AT_TEST_CPP_GUARD_H],
593 [AT_SETUP([Invalid CPP guards: $1])
595 # Possibly create inner directories.
596 dirname=`AS_DIRNAME([$1])`
597 AS_MKDIR_P([$dirname])
604 AT_CHECK([bison --defines=$1.h $1.y])
606 # CPP should be happy with it.
607 AT_CHECK([$CC -E $1.h], 0, [ignore])
612 AT_TEST_CPP_GUARD_H([input/input])
613 AT_TEST_CPP_GUARD_H([9foo])
621 # The generation of the reduction was once wrong in Bison, and made it
622 # miss some reductions. In the following test case, the reduction on
623 # `undef_id_tok' in state 1 was missing. This is stripped down from
624 # the actual web2c.y.
626 AT_SETUP([Web2c Report])
629 [[%token undef_id_tok const_id_tok
631 %start CONST_DEC_PART
640 | CONST_DEC_LIST CONST_DEC
644 { } undef_id_tok '=' const_id_tok ';'
650 AT_CHECK([bison -v input.y])
652 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
655 1 6 CONST_DEC_PART -> CONST_DEC_LIST
656 2 10 CONST_DEC_LIST -> CONST_DEC
657 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
658 4 15 @1 -> /* empty */
659 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
660 Terminals, with rules where they appear
667 Nonterminals, with rules where they appear
671 on left: 2 3, on right: 1 3
673 on left: 5, on right: 2 3
675 on left: 4, on right: 5
677 $default reduce using rule 4 (@1)
678 CONST_DEC_PART go to state 9
679 CONST_DEC_LIST go to state 1
680 CONST_DEC go to state 2
683 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
684 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
685 undef_id_tok reduce using rule 4 (@1)
686 $default reduce using rule 1 (CONST_DEC_PART)
687 CONST_DEC go to state 4
690 CONST_DEC_LIST -> CONST_DEC . (rule 2)
691 $default reduce using rule 2 (CONST_DEC_LIST)
693 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
694 undef_id_tok shift, and go to state 5
696 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
697 $default reduce using rule 3 (CONST_DEC_LIST)
699 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
700 '=' shift, and go to state 6
702 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
703 const_id_tok shift, and go to state 7
705 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
706 ';' shift, and go to state 8
708 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
709 $default reduce using rule 5 (CONST_DEC)
721 ## --------------- ##
723 ## --------------- ##
725 # The generation of the mapping `state -> action' was once wrong in
726 # extremely specific situations. web2c.y exhibits this situation.
727 # Below is a stripped version of the grammar. It looks like one can
728 # simplify it further, but just don't: it is tuned to exhibit a bug,
729 # which disapears when applying sane grammar transformations.
731 # It used to be wrong on yydefact only:
733 # static const short yydefact[] =
735 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
736 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
740 # but let's check all the tables.
743 AT_SETUP([Web2c Actions])
747 statement: struct_stat;
748 struct_stat: /* empty. */ | if else;
749 if: "if" "const" "then" statement;
750 else: "else" statement;
754 AT_CHECK([bison -v input.y -o input.c])
756 # Check only the tables. We don't use --no-parser, because it is
757 # still to be implemented in the experimental branch of Bison.
758 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
759 [[static const char yytranslate[] =
761 0, 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, 2, 2, 2, 2,
786 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
789 static const short yyprhs[] =
793 static const short yyrhs[] =
795 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
798 static const short yyrline[] =
802 static const char *const yytname[] =
804 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
805 "\"else\"", "statement", "struct_stat", "if", "else", NULL
807 static const short yyr1[] =
811 static const short yyr2[] =
815 static const short yydefact[] =
817 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
820 static const short yydefgoto[] =
824 static const short yypact[] =
826 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
829 static const short yypgoto[] =
831 0,-32768,-32768,-32768
833 static const short yytable[] =
835 10, 1, 5, 4, 11, 12, 7, 9
837 static const short yycheck[] =
839 0, 3, 6, 4, 0, 0, 5, 7