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 ## Invalid input 1. ##
483 ## ----------------- ##
486 AT_SETUP([Invalid input: 1])
493 AT_CHECK([bison input.y], [1], [],
494 [[input.y:2: invalid input: `?'
495 input.y:3: fatal error: no rules in the input grammar
501 ## ----------------- ##
502 ## Invalid input 2. ##
503 ## ----------------- ##
506 AT_SETUP([Invalid input: 2])
513 AT_CHECK([bison input.y], [1], [],
514 [[input.y:2: invalid input: `}'
521 ## -------------------- ##
522 ## Invalid %directive. ##
523 ## -------------------- ##
526 AT_SETUP([Invalid %directive])
532 AT_CHECK([bison input.y], [1], [],
533 [[input.y:1: unrecognized: %invalid
534 input.y:1: Skipping to next %
535 input.y:2: fatal error: no input grammar
546 # The generation of the reduction was once wrong in Bison, and made it
547 # miss some reductions. In the following test case, the reduction on
548 # `undef_id_tok' in state 1 was missing. This is stripped down from
549 # the actual web2c.y.
551 AT_SETUP([Web2c Report])
554 [[%token undef_id_tok const_id_tok
556 %start CONST_DEC_PART
565 | CONST_DEC_LIST CONST_DEC
569 { } undef_id_tok '=' const_id_tok ';'
575 AT_CHECK([bison -v input.y])
577 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
580 0 6 $axiom -> CONST_DEC_PART $
581 1 6 CONST_DEC_PART -> CONST_DEC_LIST
582 2 10 CONST_DEC_LIST -> CONST_DEC
583 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
584 4 15 @1 -> /* empty */
585 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
586 Terminals, with rules where they appear
593 Nonterminals, with rules where they appear
597 on left: 1, on right: 0
599 on left: 2 3, on right: 1 3
601 on left: 5, on right: 2 3
603 on left: 4, on right: 5
605 $default reduce using rule 4 (@1)
606 CONST_DEC_PART go to state 1
607 CONST_DEC_LIST go to state 2
608 CONST_DEC go to state 3
611 $axiom -> CONST_DEC_PART . $ (rule 0)
612 $ shift, and go to state 5
614 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
615 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
616 undef_id_tok reduce using rule 4 (@1)
617 $default reduce using rule 1 (CONST_DEC_PART)
618 CONST_DEC go to state 6
621 CONST_DEC_LIST -> CONST_DEC . (rule 2)
622 $default reduce using rule 2 (CONST_DEC_LIST)
624 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
625 undef_id_tok shift, and go to state 7
627 $axiom -> CONST_DEC_PART $ . (rule 0)
630 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
631 $default reduce using rule 3 (CONST_DEC_LIST)
633 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
634 '=' shift, and go to state 8
636 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
637 const_id_tok shift, and go to state 9
639 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
640 ';' shift, and go to state 10
642 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
643 $default reduce using rule 5 (CONST_DEC)
649 ## --------------- ##
651 ## --------------- ##
653 # The generation of the mapping `state -> action' was once wrong in
654 # extremely specific situations. web2c.y exhibits this situation.
655 # Below is a stripped version of the grammar. It looks like one can
656 # simplify it further, but just don't: it is tuned to exhibit a bug,
657 # which disapears when applying sane grammar transformations.
659 # It used to be wrong on yydefact only:
661 # static const short yydefact[] =
663 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
664 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
668 # but let's check all the tables.
671 AT_SETUP([Web2c Actions])
675 statement: struct_stat;
676 struct_stat: /* empty. */ | if else;
677 if: "if" "const" "then" statement;
678 else: "else" statement;
682 AT_CHECK([bison -v input.y -o input.c])
684 # Check only the tables. We don't use --no-parser, because it is
685 # still to be implemented in the experimental branch of Bison.
686 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
687 [[static const char yytranslate[] =
689 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
690 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
691 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
692 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
693 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
694 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
695 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
696 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
697 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
698 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
699 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
700 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
701 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
702 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
703 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
704 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
705 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
706 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
707 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
708 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
709 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
710 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
711 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
712 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
713 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
714 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
717 static const short yyprhs[] =
721 static const short yyrhs[] =
723 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
724 4, 5, 8, -1, 6, 8, -1
726 static const short yyrline[] =
730 static const char *const yytname[] =
732 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
733 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", NULL
735 static const short yytoknum[] =
737 0, 256, 2, 257, 258, 259, 260, -1
739 static const short yyr1[] =
741 0, 7, 8, 9, 9, 10, 11
743 static const short yyr2[] =
747 static const short yydefact[] =
749 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
752 static const short yydefgoto[] =
756 static const short yypact[] =
758 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
761 static const short yypgoto[] =
763 -32768, -7,-32768,-32768,-32768
765 static const short yytable[] =
767 10, 1, 11, 5, 6, 0, 7, 9
769 static const short yycheck[] =
771 7, 3, 9, 4, 0, -1, 6, 5