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
307 ## ------------------- ##
308 ## Token definitions. ##
309 ## ------------------- ##
312 AT_SETUP([Token definitions])
314 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
315 AT_DATA_GRAMMAR([input.y],
318 void yyerror (const char *s);
322 %token MYEOF 0 "end of file"
327 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\377\x001\x0000ff??!"
329 exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\377\x001\x0000ff??!";
332 yyerror (char const *s)
334 fprintf (stderr, "%s\n", s);
350 AT_CHECK([bison -o input.c input.y])
352 AT_PARSER_CHECK([./input], 1, [],
353 [syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\377\001\377?\?!", expecting a
359 ## -------------------- ##
360 ## Characters Escapes. ##
361 ## -------------------- ##
364 AT_SETUP([Characters Escapes])
366 AT_DATA_GRAMMAR([input.y],
368 void yyerror (const char *s);
378 # Pacify font-lock-mode: "
380 AT_CHECK([bison -o input.c input.y])
381 AT_COMPILE([input.o], [-c input.c])
390 # The generation of the reduction was once wrong in Bison, and made it
391 # miss some reductions. In the following test case, the reduction on
392 # `undef_id_tok' in state 1 was missing. This is stripped down from
393 # the actual web2c.y.
395 AT_SETUP([Web2c Report])
397 AT_KEYWORDS([report])
400 [[%token undef_id_tok const_id_tok
402 %start CONST_DEC_PART
411 | CONST_DEC_LIST CONST_DEC
415 { } undef_id_tok '=' const_id_tok ';'
420 AT_CHECK([bison -v input.y])
421 AT_CHECK([cat input.output], 0,
424 0 $accept: CONST_DEC_PART $end
426 1 CONST_DEC_PART: CONST_DEC_LIST
428 2 CONST_DEC_LIST: CONST_DEC
429 3 | CONST_DEC_LIST CONST_DEC
433 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
436 Terminals, with rules where they appear
446 Nonterminals, with rules where they appear
451 on left: 1, on right: 0
453 on left: 2 3, on right: 1 3
455 on left: 5, on right: 2 3
457 on left: 4, on right: 5
462 0 $accept: . CONST_DEC_PART $end
464 $default reduce using rule 4 (@1)
466 CONST_DEC_PART go to state 1
467 CONST_DEC_LIST go to state 2
468 CONST_DEC go to state 3
474 0 $accept: CONST_DEC_PART . $end
476 $end shift, and go to state 5
481 1 CONST_DEC_PART: CONST_DEC_LIST .
482 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
484 undef_id_tok reduce using rule 4 (@1)
485 $default reduce using rule 1 (CONST_DEC_PART)
487 CONST_DEC go to state 6
493 2 CONST_DEC_LIST: CONST_DEC .
495 $default reduce using rule 2 (CONST_DEC_LIST)
500 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
502 undef_id_tok shift, and go to state 7
507 0 $accept: CONST_DEC_PART $end .
514 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
516 $default reduce using rule 3 (CONST_DEC_LIST)
521 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
523 '=' shift, and go to state 8
528 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
530 const_id_tok shift, and go to state 9
535 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
537 ';' shift, and go to state 10
542 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
544 $default reduce using rule 5 (CONST_DEC)
550 ## --------------- ##
552 ## --------------- ##
554 # The generation of the mapping `state -> action' was once wrong in
555 # extremely specific situations. web2c.y exhibits this situation.
556 # Below is a stripped version of the grammar. It looks like one can
557 # simplify it further, but just don't: it is tuned to exhibit a bug,
558 # which disapears when applying sane grammar transformations.
560 # It used to be wrong on yydefact only:
562 # static const short int yydefact[] =
564 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
565 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
569 # but let's check all the tables.
572 AT_SETUP([Web2c Actions])
574 AT_KEYWORDS([report])
578 statement: struct_stat;
579 struct_stat: /* empty. */ | if else;
580 if: "if" "const" "then" statement;
581 else: "else" statement;
585 AT_CHECK([bison -v -o input.c input.y])
587 # Check only the tables. We don't use --no-parser, because it is
588 # still to be implemented in the experimental branch of Bison.
589 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
591 AT_CHECK([[cat tables.c]], 0,
592 [[static const unsigned char yytranslate[] =
594 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
595 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
596 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
597 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
598 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
599 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
600 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
601 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
602 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
603 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
604 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
605 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
606 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
607 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
608 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
609 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
610 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
611 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
612 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
613 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
614 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
615 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
616 2, 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, 1, 2, 3, 4,
622 static const unsigned char yyprhs[] =
626 static const yysigned_char yyrhs[] =
628 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
629 4, 5, 8, -1, 6, 8, -1
631 static const unsigned char yyrline[] =
635 static const char *const yytname[] =
637 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
638 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
640 static const unsigned short int yytoknum[] =
642 0, 256, 257, 258, 259, 260, 261
644 static const unsigned char yyr1[] =
646 0, 7, 8, 9, 9, 10, 11
648 static const unsigned char yyr2[] =
652 static const unsigned char yydefact[] =
654 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
657 static const yysigned_char yydefgoto[] =
661 static const yysigned_char yypact[] =
663 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
666 static const yysigned_char yypgoto[] =
670 static const unsigned char yytable[] =
672 10, 1, 11, 5, 6, 0, 7, 9
674 static const yysigned_char yycheck[] =
676 7, 3, 9, 4, 0, -1, 6, 5
678 static const unsigned char yystos[] =
680 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
688 ## ------------------------- ##
689 ## yycheck Bound Violation. ##
690 ## ------------------------- ##
693 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
694 # --------------------------------
695 # The following grammar, taken from Andrew Suffield's GPL'd implementation
696 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
697 # yycheck's bounds where issuing a verbose error message. Keep this test
698 # so that possible bound checking compilers could check all the skeletons.
699 m4_define([_AT_DATA_DANCER_Y],
700 [AT_DATA_GRAMMAR([dancer.y],
702 static int yylex (AT_LALR1_CC_IF([int *], [void]));
705 static void yyerror (const char *);])
708 %token ARROW INVALID NUMBER STRING DATA
712 /* Grammar follows */
717 header: '<' from ARROW to '>' type ':'
718 | '<' ARROW to '>' type ':'
752 [/* A C++ error reporting function. */
754 yy::parser::error (const location&, const std::string& m)
756 std::cerr << m << std::endl;
763 parser.set_debug_level (!!YYDEBUG);
764 return parser.parse ();
768 yyerror (const char *s)
770 fprintf (stderr, "%s\n", s);
774 yylex (AT_LALR1_CC_IF([int *lval], [void]))
776 static int toknum = 0;
781 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
782 return tokens[toknum++];
791 ])# _AT_DATA_DANCER_Y
794 # AT_CHECK_DANCER(BISON-OPTIONS)
795 # ------------------------------
796 # Generate the grammar, compile it, run it.
797 m4_define([AT_CHECK_DANCER],
798 [AT_SETUP([Dancer $1])
799 AT_BISON_OPTION_PUSHDEFS([$1])
800 _AT_DATA_DANCER_Y([$1])
801 AT_CHECK([bison -o dancer.c dancer.y])
803 [AT_CHECK([bison -o dancer.cc dancer.y])
804 AT_COMPILE_CXX([dancer])],
805 [AT_CHECK([bison -o dancer.c dancer.y])
806 AT_COMPILE([dancer])])
807 AT_PARSER_CHECK([./dancer], 1, [],
808 [syntax error, unexpected ':'
810 AT_BISON_OPTION_POPDEFS
815 AT_CHECK_DANCER([%glr-parser])
816 AT_CHECK_DANCER([%skeleton "lalr1.cc"])