1 # Bison Regressions. -*- Autotest -*-
2 # Copyright (C) 2001, 2002, 2003, 2004 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.]])
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],
317 void yyerror (const char *s);
320 [%token MYEOF 0 "end of file"
329 AT_CHECK([bison -o input.c input.y])
330 AT_COMPILE([input.o], [-c input.c])
335 ## -------------------- ##
336 ## Characters Escapes. ##
337 ## -------------------- ##
340 AT_SETUP([Characters Escapes])
342 AT_DATA_GRAMMAR([input.y],
344 void yyerror (const char *s);
354 # Pacify font-lock-mode: "
356 AT_CHECK([bison -o input.c input.y])
357 AT_COMPILE([input.o], [-c input.c])
366 # The generation of the reduction was once wrong in Bison, and made it
367 # miss some reductions. In the following test case, the reduction on
368 # `undef_id_tok' in state 1 was missing. This is stripped down from
369 # the actual web2c.y.
371 AT_SETUP([Web2c Report])
373 AT_KEYWORDS([report])
376 [[%token undef_id_tok const_id_tok
378 %start CONST_DEC_PART
387 | CONST_DEC_LIST CONST_DEC
391 { } undef_id_tok '=' const_id_tok ';'
396 AT_CHECK([bison -v input.y])
397 AT_CHECK([cat input.output], 0,
400 0 $accept: CONST_DEC_PART $end
402 1 CONST_DEC_PART: CONST_DEC_LIST
404 2 CONST_DEC_LIST: CONST_DEC
405 3 | CONST_DEC_LIST CONST_DEC
409 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
412 Terminals, with rules where they appear
422 Nonterminals, with rules where they appear
427 on left: 1, on right: 0
429 on left: 2 3, on right: 1 3
431 on left: 5, on right: 2 3
433 on left: 4, on right: 5
438 0 $accept: . CONST_DEC_PART $end
440 $default reduce using rule 4 (@1)
442 CONST_DEC_PART go to state 1
443 CONST_DEC_LIST go to state 2
444 CONST_DEC go to state 3
450 0 $accept: CONST_DEC_PART . $end
452 $end shift, and go to state 5
457 1 CONST_DEC_PART: CONST_DEC_LIST .
458 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
460 undef_id_tok reduce using rule 4 (@1)
461 $default reduce using rule 1 (CONST_DEC_PART)
463 CONST_DEC go to state 6
469 2 CONST_DEC_LIST: CONST_DEC .
471 $default reduce using rule 2 (CONST_DEC_LIST)
476 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
478 undef_id_tok shift, and go to state 7
483 0 $accept: CONST_DEC_PART $end .
490 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
492 $default reduce using rule 3 (CONST_DEC_LIST)
497 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
499 '=' shift, and go to state 8
504 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
506 const_id_tok shift, and go to state 9
511 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
513 ';' shift, and go to state 10
518 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
520 $default reduce using rule 5 (CONST_DEC)
526 ## --------------- ##
528 ## --------------- ##
530 # The generation of the mapping `state -> action' was once wrong in
531 # extremely specific situations. web2c.y exhibits this situation.
532 # Below is a stripped version of the grammar. It looks like one can
533 # simplify it further, but just don't: it is tuned to exhibit a bug,
534 # which disapears when applying sane grammar transformations.
536 # It used to be wrong on yydefact only:
538 # static const short int yydefact[] =
540 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
541 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
545 # but let's check all the tables.
548 AT_SETUP([Web2c Actions])
550 AT_KEYWORDS([report])
554 statement: struct_stat;
555 struct_stat: /* empty. */ | if else;
556 if: "if" "const" "then" statement;
557 else: "else" statement;
561 AT_CHECK([bison -v -o input.c input.y])
563 # Check only the tables. We don't use --no-parser, because it is
564 # still to be implemented in the experimental branch of Bison.
565 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
567 AT_CHECK([[cat tables.c]], 0,
568 [[static const unsigned char yytranslate[] =
570 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
571 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
572 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
573 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
574 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
575 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
576 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
577 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
578 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
579 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
580 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
581 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
582 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
583 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
584 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
585 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
586 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
587 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
588 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
589 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
590 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
591 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
592 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
593 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
594 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
595 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
598 static const unsigned char yyprhs[] =
602 static const yysigned_char yyrhs[] =
604 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
605 4, 5, 8, -1, 6, 8, -1
607 static const unsigned char yyrline[] =
611 static const char *const yytname[] =
613 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
614 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
616 static const unsigned short int yytoknum[] =
618 0, 256, 257, 258, 259, 260, 261
620 static const unsigned char yyr1[] =
622 0, 7, 8, 9, 9, 10, 11
624 static const unsigned char yyr2[] =
628 static const unsigned char yydefact[] =
630 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
633 static const yysigned_char yydefgoto[] =
637 static const yysigned_char yypact[] =
639 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
642 static const yysigned_char yypgoto[] =
646 static const unsigned char yytable[] =
648 10, 1, 11, 5, 6, 0, 7, 9
650 static const yysigned_char yycheck[] =
652 7, 3, 9, 4, 0, -1, 6, 5
654 static const unsigned char yystos[] =
656 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
664 ## ------------------------- ##
665 ## yycheck Bound Violation. ##
666 ## ------------------------- ##
669 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
670 # --------------------------------
671 # The following grammar, taken from Andrew Suffield's GPL'd implementation
672 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
673 # yycheck's bounds where issuing a verbose error message. Keep this test
674 # so that possible bound checking compilers could check all the skeletons.
675 m4_define([_AT_DATA_DANCER_Y],
676 [AT_DATA_GRAMMAR([dancer.y],
678 static int yylex (AT_LALR1_CC_IF([int *], [void]));
681 static void yyerror (const char *);])
684 %token ARROW INVALID NUMBER STRING DATA
688 /* Grammar follows */
693 header: '<' from ARROW to '>' type ':'
694 | '<' ARROW to '>' type ':'
728 [/* A C++ error reporting function. */
730 yy::Parser::error_ ()
732 std::cerr << message << std::endl;
738 yy::Parser parser (!!YYDEBUG);
739 return parser.parse ();
743 yyerror (const char *s)
745 fprintf (stderr, "%s\n", s);
749 yylex (AT_LALR1_CC_IF([int *lval], [void]))
751 static int toknum = 0;
756 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
757 return tokens[toknum++];
766 ])# _AT_DATA_DANCER_Y
769 # AT_CHECK_DANCER(BISON-OPTIONS)
770 # ------------------------------
771 # Generate the grammar, compile it, run it.
772 m4_define([AT_CHECK_DANCER],
773 [AT_SETUP([Dancer $1])
774 AT_BISON_OPTION_PUSHDEFS([$1])
775 _AT_DATA_DANCER_Y([$1])
776 AT_CHECK([bison -o dancer.c dancer.y])
778 [AT_CHECK([bison -o dancer.cc dancer.y])
779 AT_COMPILE_CXX([dancer])],
780 [AT_CHECK([bison -o dancer.c dancer.y])
781 AT_COMPILE([dancer])])
782 AT_PARSER_CHECK([./dancer], 1, [],
783 [syntax error, unexpected ':'
785 AT_BISON_OPTION_POPDEFS
790 AT_CHECK_DANCER([%glr-parser])
791 AT_CHECK_DANCER([%skeleton "lalr1.cc"])