1 # Bison Regressions. -*- Autotest -*-
3 # Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 Free Software
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 AT_BANNER([[Regression tests.]])
24 ## ------------------------- ##
25 ## Early token definitions. ##
26 ## ------------------------- ##
29 AT_SETUP([Early token definitions])
31 # Found in GCJ: they expect the tokens to be defined before the user
32 # prologue, so that they can use the token definitions in it.
34 AT_DATA_GRAMMAR([input.y],
36 void yyerror (const char *s);
46 # error "MY_TOKEN not defined."
55 AT_CHECK([bison -o input.c input.y])
56 AT_COMPILE([input.o], [-c input.c])
62 ## ---------------- ##
64 ## ---------------- ##
67 AT_SETUP([Braces parsing])
70 [[/* Bison used to swallow the character after `}'. */
73 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
77 AT_CHECK([bison -v -o input.c input.y])
79 AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
84 ## ------------------ ##
85 ## Duplicate string. ##
86 ## ------------------ ##
89 AT_SETUP([Duplicate string])
92 [[/* `Bison -v' used to dump core when two tokens are defined with the same
93 string, as LE and GE below. */
100 exp: '(' exp ')' | NUM ;
104 AT_CHECK([bison -v -o input.c input.y], 0, [],
105 [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
111 ## ------------------- ##
112 ## Rule Line Numbers. ##
113 ## ------------------- ##
115 AT_SETUP([Rule Line Numbers])
117 AT_KEYWORDS([report])
149 AT_CHECK([bison -o input.c -v input.y])
151 # Check the contents of the report.
152 AT_CHECK([cat input.output], [],
166 Terminals, with rules where they appear
175 Nonterminals, with rules where they appear
180 on left: 2 4, on right: 0
182 on left: 1, on right: 2
184 on left: 3, on right: 4
189 0 $accept: . expr $end
191 'a' shift, and go to state 1
193 $default reduce using rule 3 (@2)
203 $default reduce using rule 1 (@1)
210 0 $accept: expr . $end
212 $end shift, and go to state 5
219 'c' shift, and go to state 6
226 'b' shift, and go to state 7
231 0 $accept: expr $end .
240 $default reduce using rule 4 (expr)
247 $default reduce using rule 2 (expr)
254 ## ---------------------- ##
255 ## Mixing %token styles. ##
256 ## ---------------------- ##
259 AT_SETUP([Mixing %token styles])
261 # Taken from the documentation.
263 [[%token <operator> OR "||"
264 %token <operator> LE 134 "<="
271 AT_CHECK([bison -v -o input.c input.y])
277 ## ---------------- ##
278 ## Invalid inputs. ##
279 ## ---------------- ##
282 AT_SETUP([Invalid inputs])
294 AT_CHECK([bison input.y], [1], [],
295 [[input.y:2.1: invalid character: `?'
296 input.y:3.14: invalid character: `}'
297 input.y:4.1: invalid character: `%'
298 input.y:4.2: invalid character: `&'
299 input.y:5.1-17: invalid directive: `%a-does-not-exist'
300 input.y:6.1: invalid character: `%'
301 input.y:6.2: invalid character: `-'
302 input.y:7.1-8.0: missing `%}' at end of file
308 AT_SETUP([Invalid inputs with {}])
320 AT_CHECK([bison input.y], [1], [],
321 [[input.y:3.1: missing `{' in "%destructor {...}"
322 input.y:4.1: missing `{' in "%initial-action {...}"
323 input.y:4.1: syntax error, unexpected %initial-action {...}, expecting string or identifier
330 ## ------------------- ##
331 ## Token definitions. ##
332 ## ------------------- ##
335 AT_SETUP([Token definitions])
337 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
338 AT_DATA_GRAMMAR([input.y],
341 void yyerror (const char *s);
345 %token MYEOF 0 "end of file"
350 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
352 exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
355 yyerror (char const *s)
357 fprintf (stderr, "%s\n", s);
373 AT_CHECK([bison -o input.c input.y])
376 [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201?\?!", expecting a
378 AT_PARSER_CHECK([./input], 1, [], [experr])
383 ## -------------------- ##
384 ## Characters Escapes. ##
385 ## -------------------- ##
388 AT_SETUP([Characters Escapes])
390 AT_DATA_GRAMMAR([input.y],
392 void yyerror (const char *s);
402 # Pacify font-lock-mode: "
404 AT_CHECK([bison -o input.c input.y])
405 AT_COMPILE([input.o], [-c input.c])
414 # The generation of the reduction was once wrong in Bison, and made it
415 # miss some reductions. In the following test case, the reduction on
416 # `undef_id_tok' in state 1 was missing. This is stripped down from
417 # the actual web2c.y.
419 AT_SETUP([Web2c Report])
421 AT_KEYWORDS([report])
424 [[%token undef_id_tok const_id_tok
426 %start CONST_DEC_PART
435 | CONST_DEC_LIST CONST_DEC
439 { } undef_id_tok '=' const_id_tok ';'
444 AT_CHECK([bison -v input.y])
445 AT_CHECK([cat input.output], 0,
448 0 $accept: CONST_DEC_PART $end
450 1 CONST_DEC_PART: CONST_DEC_LIST
452 2 CONST_DEC_LIST: CONST_DEC
453 3 | CONST_DEC_LIST CONST_DEC
457 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
460 Terminals, with rules where they appear
470 Nonterminals, with rules where they appear
475 on left: 1, on right: 0
477 on left: 2 3, on right: 1 3
479 on left: 5, on right: 2 3
481 on left: 4, on right: 5
486 0 $accept: . CONST_DEC_PART $end
488 $default reduce using rule 4 (@1)
490 CONST_DEC_PART go to state 1
491 CONST_DEC_LIST go to state 2
492 CONST_DEC go to state 3
498 0 $accept: CONST_DEC_PART . $end
500 $end shift, and go to state 5
505 1 CONST_DEC_PART: CONST_DEC_LIST .
506 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
508 undef_id_tok reduce using rule 4 (@1)
509 $default reduce using rule 1 (CONST_DEC_PART)
511 CONST_DEC go to state 6
517 2 CONST_DEC_LIST: CONST_DEC .
519 $default reduce using rule 2 (CONST_DEC_LIST)
524 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
526 undef_id_tok shift, and go to state 7
531 0 $accept: CONST_DEC_PART $end .
538 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
540 $default reduce using rule 3 (CONST_DEC_LIST)
545 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
547 '=' shift, and go to state 8
552 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
554 const_id_tok shift, and go to state 9
559 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
561 ';' shift, and go to state 10
566 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
568 $default reduce using rule 5 (CONST_DEC)
574 ## --------------- ##
576 ## --------------- ##
578 # The generation of the mapping `state -> action' was once wrong in
579 # extremely specific situations. web2c.y exhibits this situation.
580 # Below is a stripped version of the grammar. It looks like one can
581 # simplify it further, but just don't: it is tuned to exhibit a bug,
582 # which disapears when applying sane grammar transformations.
584 # It used to be wrong on yydefact only:
586 # static const yytype_uint8 yydefact[] =
588 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
589 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
593 # but let's check all the tables.
596 AT_SETUP([Web2c Actions])
598 AT_KEYWORDS([report])
602 statement: struct_stat;
603 struct_stat: /* empty. */ | if else;
604 if: "if" "const" "then" statement;
605 else: "else" statement;
609 AT_CHECK([bison -v -o input.c input.y])
611 # Check only the tables. We don't use --no-parser, because it is
612 # still to be implemented in the experimental branch of Bison.
613 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
615 AT_CHECK([[cat tables.c]], 0,
616 [[static const yytype_uint8 yytranslate[] =
618 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
619 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
620 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
621 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
622 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
623 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
624 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
625 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
626 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
627 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
628 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
629 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
630 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
631 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
632 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
633 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
634 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
635 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
636 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
637 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
638 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
639 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
640 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
641 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
642 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
643 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
646 static const yytype_uint8 yyprhs[] =
650 static const yytype_int8 yyrhs[] =
652 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
653 4, 5, 8, -1, 6, 8, -1
655 static const yytype_uint8 yyrline[] =
659 static const char *const yytname[] =
661 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
662 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
664 static const yytype_uint16 yytoknum[] =
666 0, 256, 257, 258, 259, 260, 261
668 static const yytype_uint8 yyr1[] =
670 0, 7, 8, 9, 9, 10, 11
672 static const yytype_uint8 yyr2[] =
676 static const yytype_uint8 yydefact[] =
678 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
681 static const yytype_int8 yydefgoto[] =
685 static const yytype_int8 yypact[] =
687 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
690 static const yytype_int8 yypgoto[] =
694 static const yytype_uint8 yytable[] =
696 10, 1, 11, 5, 6, 0, 7, 9
698 static const yytype_int8 yycheck[] =
700 7, 3, 9, 4, 0, -1, 6, 5
702 static const yytype_uint8 yystos[] =
704 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
712 ## ------------------------- ##
713 ## yycheck Bound Violation. ##
714 ## ------------------------- ##
717 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
718 # --------------------------------
719 # The following grammar, taken from Andrew Suffield's GPL'd implementation
720 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
721 # yycheck's bounds where issuing a verbose error message. Keep this test
722 # so that possible bound checking compilers could check all the skeletons.
723 m4_define([_AT_DATA_DANCER_Y],
724 [AT_DATA_GRAMMAR([dancer.y],
726 static int yylex (AT_LALR1_CC_IF([int *], [void]));
729 static void yyerror (const char *);])
732 %token ARROW INVALID NUMBER STRING DATA
736 /* Grammar follows */
741 header: '<' from ARROW to '>' type ':'
742 | '<' ARROW to '>' type ':'
776 [/* A C++ error reporting function. */
778 yy::parser::error (const location&, const std::string& m)
780 std::cerr << m << std::endl;
787 parser.set_debug_level (!!YYDEBUG);
788 return parser.parse ();
792 yyerror (const char *s)
794 fprintf (stderr, "%s\n", s);
798 yylex (AT_LALR1_CC_IF([int *lval], [void]))
800 static int toknum = 0;
805 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
806 return tokens[toknum++];
815 ])# _AT_DATA_DANCER_Y
818 # AT_CHECK_DANCER(BISON-OPTIONS)
819 # ------------------------------
820 # Generate the grammar, compile it, run it.
821 m4_define([AT_CHECK_DANCER],
822 [AT_SETUP([Dancer $1])
823 AT_BISON_OPTION_PUSHDEFS([$1])
824 _AT_DATA_DANCER_Y([$1])
825 AT_CHECK([bison -o dancer.c dancer.y])
827 [AT_CHECK([bison -o dancer.cc dancer.y])
828 AT_COMPILE_CXX([dancer])],
829 [AT_CHECK([bison -o dancer.c dancer.y])
830 AT_COMPILE([dancer])])
831 AT_PARSER_CHECK([./dancer], 1, [],
832 [syntax error, unexpected ':'
834 AT_BISON_OPTION_POPDEFS
839 AT_CHECK_DANCER([%glr-parser])
840 AT_CHECK_DANCER([%skeleton "lalr1.cc"])