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 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)
108 $ shift, and go to state 5
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)
137 $ shift, and go to state 6
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)
212 $ shift, and go to state 5
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)
240 $ shift, and go to state 6
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)
379 $ shift, and go to state 7
394 ## -------------------- ##
395 ## %expect not enough. ##
396 ## -------------------- ##
398 AT_SETUP([%expect not enough])
404 exp: exp OP exp | NUM;
407 AT_CHECK([bison input.y -o input.c], 1, [],
408 [input.y contains 1 shift/reduce conflict.
409 expected 0 shift/reduce conflicts
414 ## --------------- ##
416 ## --------------- ##
418 AT_SETUP([%expect right])
424 exp: exp OP exp | NUM;
427 AT_CHECK([bison input.y -o input.c], 0)
431 ## ------------------ ##
432 ## %expect too much. ##
433 ## ------------------ ##
435 AT_SETUP([%expect too much])
441 exp: exp OP exp | NUM;
444 AT_CHECK([bison input.y -o input.c], 1, [],
445 [input.y contains 1 shift/reduce conflict.
446 expected 2 shift/reduce conflicts
451 ## ---------------------- ##
452 ## Mixing %token styles. ##
453 ## ---------------------- ##
456 AT_SETUP([Mixing %token styles])
458 # Taken from the documentation.
460 [[%token <operator> OR "||"
461 %token <operator> LE 134 "<="
468 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
474 ## ---------------------- ##
475 ## %union and --defines. ##
476 ## ---------------------- ##
479 AT_SETUP([%union and --defines])
491 AT_CHECK([bison --defines input.y])
496 ## --------------------------------------- ##
497 ## Duplicate '/' in C comments in %union ##
498 ## --------------------------------------- ##
501 AT_SETUP([%union and C comments])
506 /* The int. */ int integer;
507 /* The string. */ char *string ;
513 AT_CHECK([bison input.y -o input.c])
514 AT_CHECK([fgrep '//*' input.c], [1], [])
519 ## ----------------- ##
520 ## Invalid input 1. ##
521 ## ----------------- ##
524 AT_SETUP([Invalid input: 1])
531 AT_CHECK([bison input.y], [1], [],
532 [[input.y:2: invalid input: `?'
533 input.y:3: fatal error: no rules in the input grammar
539 ## ----------------- ##
540 ## Invalid input 2. ##
541 ## ----------------- ##
544 AT_SETUP([Invalid input: 2])
551 AT_CHECK([bison input.y], [1], [],
552 [[input.y:2: invalid input: `}'
559 ## -------------------- ##
560 ## Invalid %directive. ##
561 ## -------------------- ##
564 AT_SETUP([Invalid %directive])
570 AT_CHECK([bison input.y], [1], [],
571 [[input.y:1: unrecognized: %invalid
572 input.y:1: Skipping to next %
573 input.y:2: fatal error: no input grammar
580 ## --------------------- ##
581 ## Invalid CPP headers. ##
582 ## --------------------- ##
584 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
585 # -------------------------------------
586 m4_define([AT_TEST_CPP_GUARD_H],
587 [AT_SETUP([Invalid CPP guards: $1])
589 # Possibly create inner directories.
590 dirname=`AS_DIRNAME([$1])`
591 AS_MKDIR_P([$dirname])
598 AT_CHECK([bison --defines=$1.h $1.y])
600 # CPP should be happy with it.
601 AT_CHECK([$CC -E $1.h], 0, [ignore])
606 AT_TEST_CPP_GUARD_H([input/input])
607 AT_TEST_CPP_GUARD_H([9foo])
615 # The generation of the reduction was once wrong in Bison, and made it
616 # miss some reductions. In the following test case, the reduction on
617 # `undef_id_tok' in state 1 was missing. This is stripped down from
618 # the actual web2c.y.
620 AT_SETUP([Web2c Report])
623 [[%token undef_id_tok const_id_tok
625 %start CONST_DEC_PART
634 | CONST_DEC_LIST CONST_DEC
638 { } undef_id_tok '=' const_id_tok ';'
644 AT_CHECK([bison -v input.y])
646 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
649 1 6 CONST_DEC_PART -> CONST_DEC_LIST
650 2 10 CONST_DEC_LIST -> CONST_DEC
651 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
652 4 15 @1 -> /* empty */
653 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
654 Terminals, with rules where they appear
661 Nonterminals, with rules where they appear
665 on left: 2 3, on right: 1 3
667 on left: 5, on right: 2 3
669 on left: 4, on right: 5
671 $default reduce using rule 4 (@1)
672 CONST_DEC_PART go to state 9
673 CONST_DEC_LIST go to state 1
674 CONST_DEC go to state 2
677 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
678 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
679 undef_id_tok reduce using rule 4 (@1)
680 $default reduce using rule 1 (CONST_DEC_PART)
681 CONST_DEC go to state 4
684 CONST_DEC_LIST -> CONST_DEC . (rule 2)
685 $default reduce using rule 2 (CONST_DEC_LIST)
687 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
688 undef_id_tok shift, and go to state 5
690 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
691 $default reduce using rule 3 (CONST_DEC_LIST)
693 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
694 '=' shift, and go to state 6
696 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
697 const_id_tok shift, and go to state 7
699 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
700 ';' shift, and go to state 8
702 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
703 $default reduce using rule 5 (CONST_DEC)
705 $ shift, and go to state 10
713 ## --------------- ##
715 ## --------------- ##
717 # The generation of the mapping `state -> action' was once wrong in
718 # extremely specific situations. web2c.y exhibits this situation.
719 # Below is a stripped version of the grammar. It looks like one can
720 # simplify it further, but just don't: it is tuned to exhibit a bug,
721 # which disapears when applying sane grammar transformations.
723 # It used to be wrong on yydefact only:
725 # static const short yydefact[] =
727 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
728 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
732 # but let's check all the tables.
735 AT_SETUP([Web2c Actions])
739 statement: struct_stat;
740 struct_stat: /* empty. */ | if else;
741 if: "if" "const" "then" statement;
742 else: "else" statement;
746 AT_CHECK([bison -v input.y -o input.c])
748 # Check only the tables. We don't use --no-parser, because it is
749 # still to be implemented in the experimental branch of Bison.
750 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
751 [[static const char yytranslate[] =
753 0, 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, 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, 1, 3, 4, 5,
781 static const short yyprhs[] =
785 static const short yyrhs[] =
787 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
790 static const short yyrline[] =
794 static const char *const yytname[] =
796 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
797 "\"else\"", "statement", "struct_stat", "if", "else", NULL
799 static const short yytoknum[] =
801 0, 256, 2, 257, 258, 259, 260, -1
803 static const short yyr1[] =
807 static const short yyr2[] =
811 static const short yydefact[] =
813 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
816 static const short yydefgoto[] =
820 static const short yypact[] =
822 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
825 static const short yypgoto[] =
827 0,-32768,-32768,-32768
829 static const short yytable[] =
831 10, 1, 5, 4, 11, 0, 7, 9
833 static const short yycheck[] =
835 0, 3, 6, 4, 0, -1, 5, 7