1 # Bison Regressions. -*- Autotest -*-
2 # Copyright (C) 2001, 2002, 2003, 2004, 2005 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., 51 Franklin Street, Fifth Floor, Boston, MA
19 AT_BANNER([[Regression tests.]])
22 ## ------------------------- ##
23 ## Early token definitions. ##
24 ## ------------------------- ##
27 AT_SETUP([Early token definitions])
29 # Found in GCJ: they expect the tokens to be defined before the user
30 # prologue, so that they can use the token definitions in it.
32 AT_DATA_GRAMMAR([input.y],
34 void yyerror (const char *s);
44 # error "MY_TOKEN not defined."
53 AT_CHECK([bison -o input.c input.y])
54 AT_COMPILE([input.o], [-c input.c])
60 ## ---------------- ##
62 ## ---------------- ##
65 AT_SETUP([Braces parsing])
68 [[/* Bison used to swallow the character after `}'. */
71 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
75 AT_CHECK([bison -v -o input.c input.y])
77 AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
82 ## ------------------ ##
83 ## Duplicate string. ##
84 ## ------------------ ##
87 AT_SETUP([Duplicate string])
90 [[/* `Bison -v' used to dump core when two tokens are defined with the same
91 string, as LE and GE below. */
98 exp: '(' exp ')' | NUM ;
102 AT_CHECK([bison -v -o input.c input.y], 0, [],
103 [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
109 ## ------------------- ##
110 ## Rule Line Numbers. ##
111 ## ------------------- ##
113 AT_SETUP([Rule Line Numbers])
115 AT_KEYWORDS([report])
147 AT_CHECK([bison -o input.c -v input.y])
149 # Check the contents of the report.
150 AT_CHECK([cat input.output], [],
164 Terminals, with rules where they appear
173 Nonterminals, with rules where they appear
178 on left: 2 4, on right: 0
180 on left: 1, on right: 2
182 on left: 3, on right: 4
187 0 $accept: . expr $end
189 'a' shift, and go to state 1
191 $default reduce using rule 3 (@2)
201 $default reduce using rule 1 (@1)
208 0 $accept: expr . $end
210 $end shift, and go to state 5
217 'c' shift, and go to state 6
224 'b' shift, and go to state 7
229 0 $accept: expr $end .
238 $default reduce using rule 4 (expr)
245 $default reduce using rule 2 (expr)
252 ## ---------------------- ##
253 ## Mixing %token styles. ##
254 ## ---------------------- ##
257 AT_SETUP([Mixing %token styles])
259 # Taken from the documentation.
261 [[%token <operator> OR "||"
262 %token <operator> LE 134 "<="
269 AT_CHECK([bison -v -o input.c input.y])
275 ## ---------------- ##
276 ## Invalid inputs. ##
277 ## ---------------- ##
280 AT_SETUP([Invalid inputs])
292 AT_CHECK([bison input.y], [1], [],
293 [[input.y:2.1: invalid character: `?'
294 input.y:3.14: invalid character: `}'
295 input.y:4.1: invalid character: `%'
296 input.y:4.2: invalid character: `&'
297 input.y:5.1-17: invalid directive: `%a-does-not-exist'
298 input.y:6.1: invalid character: `%'
299 input.y:6.2: invalid character: `-'
300 input.y:7.1-8.0: missing `%}' at end of file
306 AT_SETUP([Invalid inputs with {}])
318 AT_CHECK([bison input.y], [1], [],
319 [[input.y:3.1: missing `{' in "%destructor {...}"
320 input.y:4.1: missing `{' in "%initial-action {...}"
321 input.y:4.1: syntax error, unexpected %initial-action {...}, expecting string or identifier
328 ## ------------------- ##
329 ## Token definitions. ##
330 ## ------------------- ##
333 AT_SETUP([Token definitions])
335 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
336 AT_DATA_GRAMMAR([input.y],
339 void yyerror (const char *s);
343 %token MYEOF 0 "end of file"
348 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
350 exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
353 yyerror (char const *s)
355 fprintf (stderr, "%s\n", s);
371 AT_CHECK([bison -o input.c input.y])
374 [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201?\?!", expecting a
376 AT_PARSER_CHECK([./input], 1, [], [experr])
381 ## -------------------- ##
382 ## Characters Escapes. ##
383 ## -------------------- ##
386 AT_SETUP([Characters Escapes])
388 AT_DATA_GRAMMAR([input.y],
390 void yyerror (const char *s);
400 # Pacify font-lock-mode: "
402 AT_CHECK([bison -o input.c input.y])
403 AT_COMPILE([input.o], [-c input.c])
412 # The generation of the reduction was once wrong in Bison, and made it
413 # miss some reductions. In the following test case, the reduction on
414 # `undef_id_tok' in state 1 was missing. This is stripped down from
415 # the actual web2c.y.
417 AT_SETUP([Web2c Report])
419 AT_KEYWORDS([report])
422 [[%token undef_id_tok const_id_tok
424 %start CONST_DEC_PART
433 | CONST_DEC_LIST CONST_DEC
437 { } undef_id_tok '=' const_id_tok ';'
442 AT_CHECK([bison -v input.y])
443 AT_CHECK([cat input.output], 0,
446 0 $accept: CONST_DEC_PART $end
448 1 CONST_DEC_PART: CONST_DEC_LIST
450 2 CONST_DEC_LIST: CONST_DEC
451 3 | CONST_DEC_LIST CONST_DEC
455 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
458 Terminals, with rules where they appear
468 Nonterminals, with rules where they appear
473 on left: 1, on right: 0
475 on left: 2 3, on right: 1 3
477 on left: 5, on right: 2 3
479 on left: 4, on right: 5
484 0 $accept: . CONST_DEC_PART $end
486 $default reduce using rule 4 (@1)
488 CONST_DEC_PART go to state 1
489 CONST_DEC_LIST go to state 2
490 CONST_DEC go to state 3
496 0 $accept: CONST_DEC_PART . $end
498 $end shift, and go to state 5
503 1 CONST_DEC_PART: CONST_DEC_LIST .
504 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
506 undef_id_tok reduce using rule 4 (@1)
507 $default reduce using rule 1 (CONST_DEC_PART)
509 CONST_DEC go to state 6
515 2 CONST_DEC_LIST: CONST_DEC .
517 $default reduce using rule 2 (CONST_DEC_LIST)
522 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
524 undef_id_tok shift, and go to state 7
529 0 $accept: CONST_DEC_PART $end .
536 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
538 $default reduce using rule 3 (CONST_DEC_LIST)
543 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
545 '=' shift, and go to state 8
550 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
552 const_id_tok shift, and go to state 9
557 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
559 ';' shift, and go to state 10
564 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
566 $default reduce using rule 5 (CONST_DEC)
572 ## --------------- ##
574 ## --------------- ##
576 # The generation of the mapping `state -> action' was once wrong in
577 # extremely specific situations. web2c.y exhibits this situation.
578 # Below is a stripped version of the grammar. It looks like one can
579 # simplify it further, but just don't: it is tuned to exhibit a bug,
580 # which disapears when applying sane grammar transformations.
582 # It used to be wrong on yydefact only:
584 # static const short int yydefact[] =
586 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
587 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
591 # but let's check all the tables.
594 AT_SETUP([Web2c Actions])
596 AT_KEYWORDS([report])
600 statement: struct_stat;
601 struct_stat: /* empty. */ | if else;
602 if: "if" "const" "then" statement;
603 else: "else" statement;
607 AT_CHECK([bison -v -o input.c input.y])
609 # Check only the tables. We don't use --no-parser, because it is
610 # still to be implemented in the experimental branch of Bison.
611 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
613 AT_CHECK([[cat tables.c]], 0,
614 [[static const unsigned char yytranslate[] =
616 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
617 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
618 2, 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, 1, 2, 3, 4,
644 static const unsigned char yyprhs[] =
648 static const yysigned_char yyrhs[] =
650 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
651 4, 5, 8, -1, 6, 8, -1
653 static const unsigned char yyrline[] =
657 static const char *const yytname[] =
659 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
660 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
662 static const unsigned short int yytoknum[] =
664 0, 256, 257, 258, 259, 260, 261
666 static const unsigned char yyr1[] =
668 0, 7, 8, 9, 9, 10, 11
670 static const unsigned char yyr2[] =
674 static const unsigned char yydefact[] =
676 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
679 static const yysigned_char yydefgoto[] =
683 static const yysigned_char yypact[] =
685 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
688 static const yysigned_char yypgoto[] =
692 static const unsigned char yytable[] =
694 10, 1, 11, 5, 6, 0, 7, 9
696 static const yysigned_char yycheck[] =
698 7, 3, 9, 4, 0, -1, 6, 5
700 static const unsigned char yystos[] =
702 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
710 ## ------------------------- ##
711 ## yycheck Bound Violation. ##
712 ## ------------------------- ##
715 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
716 # --------------------------------
717 # The following grammar, taken from Andrew Suffield's GPL'd implementation
718 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
719 # yycheck's bounds where issuing a verbose error message. Keep this test
720 # so that possible bound checking compilers could check all the skeletons.
721 m4_define([_AT_DATA_DANCER_Y],
722 [AT_DATA_GRAMMAR([dancer.y],
724 static int yylex (AT_LALR1_CC_IF([int *], [void]));
727 static void yyerror (const char *);])
730 %token ARROW INVALID NUMBER STRING DATA
734 /* Grammar follows */
739 header: '<' from ARROW to '>' type ':'
740 | '<' ARROW to '>' type ':'
774 [/* A C++ error reporting function. */
776 yy::parser::error (const location&, const std::string& m)
778 std::cerr << m << std::endl;
785 parser.set_debug_level (!!YYDEBUG);
786 return parser.parse ();
790 yyerror (const char *s)
792 fprintf (stderr, "%s\n", s);
796 yylex (AT_LALR1_CC_IF([int *lval], [void]))
798 static int toknum = 0;
803 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
804 return tokens[toknum++];
813 ])# _AT_DATA_DANCER_Y
816 # AT_CHECK_DANCER(BISON-OPTIONS)
817 # ------------------------------
818 # Generate the grammar, compile it, run it.
819 m4_define([AT_CHECK_DANCER],
820 [AT_SETUP([Dancer $1])
821 AT_BISON_OPTION_PUSHDEFS([$1])
822 _AT_DATA_DANCER_Y([$1])
823 AT_CHECK([bison -o dancer.c dancer.y])
825 [AT_CHECK([bison -o dancer.cc dancer.y])
826 AT_COMPILE_CXX([dancer])],
827 [AT_CHECK([bison -o dancer.c dancer.y])
828 AT_COMPILE([dancer])])
829 AT_PARSER_CHECK([./dancer], 1, [],
830 [syntax error, unexpected ':'
832 AT_BISON_OPTION_POPDEFS
837 AT_CHECK_DANCER([%glr-parser])
838 AT_CHECK_DANCER([%skeleton "lalr1.cc"])