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], [],
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 ## Invalid input 1. ##
505 ## ----------------- ##
508 AT_SETUP([Invalid input: 1])
515 AT_CHECK([bison input.y], [1], [],
516 [[input.y:2: invalid input: `?'
517 input.y:3: fatal error: no rules in the input grammar
523 ## ----------------- ##
524 ## Invalid input 2. ##
525 ## ----------------- ##
528 AT_SETUP([Invalid input: 2])
535 AT_CHECK([bison input.y], [1], [],
536 [[input.y:2: invalid input: `}'
543 ## -------------------- ##
544 ## Invalid %directive. ##
545 ## -------------------- ##
548 AT_SETUP([Invalid %directive])
554 AT_CHECK([bison input.y], [1], [],
555 [[input.y:1: unrecognized: %invalid
556 input.y:1: Skipping to next %
557 input.y:2: fatal error: no input grammar
564 ## --------------------- ##
565 ## Invalid CPP headers. ##
566 ## --------------------- ##
568 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
569 # -------------------------------------
570 m4_define([AT_TEST_CPP_GUARD_H],
571 [AT_SETUP([Invalid CPP guards: $1])
573 # Possibly create inner directories.
574 dirname=`AS_DIRNAME([$1])`
575 AS_MKDIR_P([$dirname])
582 AT_CHECK([bison --defines=$1.h $1.y])
584 # CPP should be happy with it.
585 AT_CHECK([$CC -E $1.h], 0, [ignore])
590 AT_TEST_CPP_GUARD_H([input/input])
591 AT_TEST_CPP_GUARD_H([9foo])
599 # The generation of the reduction was once wrong in Bison, and made it
600 # miss some reductions. In the following test case, the reduction on
601 # `undef_id_tok' in state 1 was missing. This is stripped down from
602 # the actual web2c.y.
604 AT_SETUP([Web2c Report])
607 [[%token undef_id_tok const_id_tok
609 %start CONST_DEC_PART
618 | CONST_DEC_LIST CONST_DEC
622 { } undef_id_tok '=' const_id_tok ';'
628 AT_CHECK([bison -v input.y])
630 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
633 0 6 $axiom -> CONST_DEC_PART $
634 1 6 CONST_DEC_PART -> CONST_DEC_LIST
635 2 10 CONST_DEC_LIST -> CONST_DEC
636 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
637 4 15 @1 -> /* empty */
638 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
639 Terminals, with rules where they appear
646 Nonterminals, with rules where they appear
650 on left: 1, on right: 0
652 on left: 2 3, on right: 1 3
654 on left: 5, on right: 2 3
656 on left: 4, on right: 5
658 $default reduce using rule 4 (@1)
659 CONST_DEC_PART go to state 1
660 CONST_DEC_LIST go to state 2
661 CONST_DEC go to state 3
664 $axiom -> CONST_DEC_PART . $ (rule 0)
665 $ shift, and go to state 5
667 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
668 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
669 undef_id_tok reduce using rule 4 (@1)
670 $default reduce using rule 1 (CONST_DEC_PART)
671 CONST_DEC go to state 6
674 CONST_DEC_LIST -> CONST_DEC . (rule 2)
675 $default reduce using rule 2 (CONST_DEC_LIST)
677 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
678 undef_id_tok shift, and go to state 7
680 $axiom -> CONST_DEC_PART $ . (rule 0)
683 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
684 $default reduce using rule 3 (CONST_DEC_LIST)
686 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
687 '=' shift, and go to state 8
689 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
690 const_id_tok shift, and go to state 9
692 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
693 ';' shift, and go to state 10
695 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
696 $default reduce using rule 5 (CONST_DEC)
702 ## --------------- ##
704 ## --------------- ##
706 # The generation of the mapping `state -> action' was once wrong in
707 # extremely specific situations. web2c.y exhibits this situation.
708 # Below is a stripped version of the grammar. It looks like one can
709 # simplify it further, but just don't: it is tuned to exhibit a bug,
710 # which disapears when applying sane grammar transformations.
712 # It used to be wrong on yydefact only:
714 # static const short yydefact[] =
716 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
717 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
721 # but let's check all the tables.
724 AT_SETUP([Web2c Actions])
728 statement: struct_stat;
729 struct_stat: /* empty. */ | if else;
730 if: "if" "const" "then" statement;
731 else: "else" statement;
735 AT_CHECK([bison -v input.y -o input.c])
737 # Check only the tables. We don't use --no-parser, because it is
738 # still to be implemented in the experimental branch of Bison.
739 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
740 [[static const char yytranslate[] =
742 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
743 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
744 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
745 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
746 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
747 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
748 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
749 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
750 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
751 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
752 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
753 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
754 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
755 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
756 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
757 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
758 2, 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, 1, 3, 4, 5,
770 static const short yyprhs[] =
774 static const short yyrhs[] =
776 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
777 4, 5, 8, -1, 6, 8, -1
779 static const short yyrline[] =
783 static const char *const yytname[] =
785 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
786 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", NULL
788 static const short yytoknum[] =
790 0, 256, 2, 257, 258, 259, 260, -1
792 static const short yyr1[] =
794 0, 7, 8, 9, 9, 10, 11
796 static const short yyr2[] =
800 static const short yydefact[] =
802 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
805 static const short yydefgoto[] =
809 static const short yypact[] =
811 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
814 static const short yypgoto[] =
816 -32768, -7,-32768,-32768,-32768
818 static const short yytable[] =
820 10, 1, 11, 5, 6, 0, 7, 9
822 static const short yycheck[] =
824 7, 3, 9, 4, 0, -1, 6, 5