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 "\\\'\?\"\n\t??!"
329 exp: "a" "\\\'\?\"\n\t??!";
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 \'?"
360 ## -------------------- ##
361 ## Characters Escapes. ##
362 ## -------------------- ##
365 AT_SETUP([Characters Escapes])
367 AT_DATA_GRAMMAR([input.y],
369 void yyerror (const char *s);
379 # Pacify font-lock-mode: "
381 AT_CHECK([bison -o input.c input.y])
382 AT_COMPILE([input.o], [-c input.c])
391 # The generation of the reduction was once wrong in Bison, and made it
392 # miss some reductions. In the following test case, the reduction on
393 # `undef_id_tok' in state 1 was missing. This is stripped down from
394 # the actual web2c.y.
396 AT_SETUP([Web2c Report])
398 AT_KEYWORDS([report])
401 [[%token undef_id_tok const_id_tok
403 %start CONST_DEC_PART
412 | CONST_DEC_LIST CONST_DEC
416 { } undef_id_tok '=' const_id_tok ';'
421 AT_CHECK([bison -v input.y])
422 AT_CHECK([cat input.output], 0,
425 0 $accept: CONST_DEC_PART $end
427 1 CONST_DEC_PART: CONST_DEC_LIST
429 2 CONST_DEC_LIST: CONST_DEC
430 3 | CONST_DEC_LIST CONST_DEC
434 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
437 Terminals, with rules where they appear
447 Nonterminals, with rules where they appear
452 on left: 1, on right: 0
454 on left: 2 3, on right: 1 3
456 on left: 5, on right: 2 3
458 on left: 4, on right: 5
463 0 $accept: . CONST_DEC_PART $end
465 $default reduce using rule 4 (@1)
467 CONST_DEC_PART go to state 1
468 CONST_DEC_LIST go to state 2
469 CONST_DEC go to state 3
475 0 $accept: CONST_DEC_PART . $end
477 $end shift, and go to state 5
482 1 CONST_DEC_PART: CONST_DEC_LIST .
483 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
485 undef_id_tok reduce using rule 4 (@1)
486 $default reduce using rule 1 (CONST_DEC_PART)
488 CONST_DEC go to state 6
494 2 CONST_DEC_LIST: CONST_DEC .
496 $default reduce using rule 2 (CONST_DEC_LIST)
501 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
503 undef_id_tok shift, and go to state 7
508 0 $accept: CONST_DEC_PART $end .
515 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
517 $default reduce using rule 3 (CONST_DEC_LIST)
522 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
524 '=' shift, and go to state 8
529 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
531 const_id_tok shift, and go to state 9
536 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
538 ';' shift, and go to state 10
543 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
545 $default reduce using rule 5 (CONST_DEC)
551 ## --------------- ##
553 ## --------------- ##
555 # The generation of the mapping `state -> action' was once wrong in
556 # extremely specific situations. web2c.y exhibits this situation.
557 # Below is a stripped version of the grammar. It looks like one can
558 # simplify it further, but just don't: it is tuned to exhibit a bug,
559 # which disapears when applying sane grammar transformations.
561 # It used to be wrong on yydefact only:
563 # static const short int yydefact[] =
565 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
566 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
570 # but let's check all the tables.
573 AT_SETUP([Web2c Actions])
575 AT_KEYWORDS([report])
579 statement: struct_stat;
580 struct_stat: /* empty. */ | if else;
581 if: "if" "const" "then" statement;
582 else: "else" statement;
586 AT_CHECK([bison -v -o input.c input.y])
588 # Check only the tables. We don't use --no-parser, because it is
589 # still to be implemented in the experimental branch of Bison.
590 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
592 AT_CHECK([[cat tables.c]], 0,
593 [[static const unsigned char yytranslate[] =
595 0, 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, 2, 2, 2, 2,
620 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
623 static const unsigned char yyprhs[] =
627 static const yysigned_char yyrhs[] =
629 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
630 4, 5, 8, -1, 6, 8, -1
632 static const unsigned char yyrline[] =
636 static const char *const yytname[] =
638 "$end", "error", "$undefined", "if", "const", "then", "else", "$accept",
639 "statement", "struct_stat", "if", "else", 0
641 static const unsigned short int yytoknum[] =
643 0, 256, 257, 258, 259, 260, 261
645 static const unsigned char yyr1[] =
647 0, 7, 8, 9, 9, 10, 11
649 static const unsigned char yyr2[] =
653 static const unsigned char yydefact[] =
655 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
658 static const yysigned_char yydefgoto[] =
662 static const yysigned_char yypact[] =
664 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
667 static const yysigned_char yypgoto[] =
671 static const unsigned char yytable[] =
673 10, 1, 11, 5, 6, 0, 7, 9
675 static const yysigned_char yycheck[] =
677 7, 3, 9, 4, 0, -1, 6, 5
679 static const unsigned char yystos[] =
681 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
689 ## ------------------------- ##
690 ## yycheck Bound Violation. ##
691 ## ------------------------- ##
694 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
695 # --------------------------------
696 # The following grammar, taken from Andrew Suffield's GPL'd implementation
697 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
698 # yycheck's bounds where issuing a verbose error message. Keep this test
699 # so that possible bound checking compilers could check all the skeletons.
700 m4_define([_AT_DATA_DANCER_Y],
701 [AT_DATA_GRAMMAR([dancer.y],
703 static int yylex (AT_LALR1_CC_IF([int *], [void]));
706 static void yyerror (const char *);])
709 %token ARROW INVALID NUMBER STRING DATA
713 /* Grammar follows */
718 header: '<' from ARROW to '>' type ':'
719 | '<' ARROW to '>' type ':'
753 [/* A C++ error reporting function. */
755 yy::parser::error (const location&, const std::string& m)
757 std::cerr << m << std::endl;
764 parser.set_debug_level (!!YYDEBUG);
765 return parser.parse ();
769 yyerror (const char *s)
771 fprintf (stderr, "%s\n", s);
775 yylex (AT_LALR1_CC_IF([int *lval], [void]))
777 static int toknum = 0;
782 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
783 return tokens[toknum++];
792 ])# _AT_DATA_DANCER_Y
795 # AT_CHECK_DANCER(BISON-OPTIONS)
796 # ------------------------------
797 # Generate the grammar, compile it, run it.
798 m4_define([AT_CHECK_DANCER],
799 [AT_SETUP([Dancer $1])
800 AT_BISON_OPTION_PUSHDEFS([$1])
801 _AT_DATA_DANCER_Y([$1])
802 AT_CHECK([bison -o dancer.c dancer.y])
804 [AT_CHECK([bison -o dancer.cc dancer.y])
805 AT_COMPILE_CXX([dancer])],
806 [AT_CHECK([bison -o dancer.c dancer.y])
807 AT_COMPILE([dancer])])
808 AT_PARSER_CHECK([./dancer], 1, [],
809 [syntax error, unexpected ':'
811 AT_BISON_OPTION_POPDEFS
816 AT_CHECK_DANCER([%glr-parser])
817 AT_CHECK_DANCER([%skeleton "lalr1.cc"])