style: rename stmtMerge as stmt_merge
[bison.git] / tests / regression.at
blob1a796a925c5f14a68cd9b8f9a887b62b7c2d8d82
1 # Bison Regressions.                               -*- Autotest -*-
3 # Copyright (C) 2001-2015, 2018-2021 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program.  If not, see <https://www.gnu.org/licenses/>.
18 AT_BANNER([[Regression tests.]])
21 ## ------------------ ##
22 ## Trivial grammars.  ##
23 ## ------------------ ##
25 AT_SETUP([Trivial grammars])
27 AT_BISON_OPTION_PUSHDEFS
28 AT_DATA_GRAMMAR([input.y],
29 [[%{
30 ]AT_YYERROR_DECLARE_EXTERN[
31 ]AT_YYLEX_DECLARE_EXTERN[
32 #define YYSTYPE int *
35 %define parse.error verbose
39 program: 'x';
40 ]])
41 AT_BISON_OPTION_POPDEFS
43 AT_BISON_CHECK([-o input.c input.y])
44 AT_COMPILE([input.o])
45 AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
47 AT_CLEANUP
51 ## ----------------- ##
52 ## YYSTYPE typedef.  ##
53 ## ----------------- ##
55 AT_SETUP([YYSTYPE typedef])
57 AT_BISON_OPTION_PUSHDEFS
58 AT_DATA_GRAMMAR([input.y],
59 [[%{
60 ]AT_YYERROR_DECLARE_EXTERN[
61 ]AT_YYLEX_DECLARE_EXTERN[
62 typedef union { char const *val; } YYSTYPE;
65 %type <val> program
69 program: { $$ = ""; };
70 ]])
71 AT_BISON_OPTION_POPDEFS
73 AT_BISON_CHECK([-o input.c input.y])
74 AT_COMPILE([input.o])
76 AT_CLEANUP
80 ## ------------------------------------- ##
81 ## Early token definitions with --yacc.  ##
82 ## ------------------------------------- ##
85 AT_SETUP([Early token definitions with --yacc])
87 # Found in GCJ: they expect the tokens to be defined before the user
88 # prologue, so that they can use the token definitions in it.
90 AT_BISON_OPTION_PUSHDEFS([%yacc])
92 # Not AT_DATA_GRAMMAR, which uses %code, which is not supported by Yacc.
93 AT_DATA([input.y],
94 [[%{
95 ]AT_YYERROR_DECLARE_EXTERN[
96 ]AT_YYLEX_DECLARE_EXTERN[
99 %union
101   int val;
104 #ifndef MY_TOKEN
105 # error "MY_TOKEN not defined."
106 #endif
108 %token MY_TOKEN
110 exp: MY_TOKEN;
113 AT_BISON_OPTION_POPDEFS
115 AT_BISON_CHECK([--yacc -o input.c input.y])
116 AT_COMPILE([input.o])
118 AT_CLEANUP
122 ## ---------------------------------------- ##
123 ## Early token definitions without --yacc.  ##
124 ## ---------------------------------------- ##
127 AT_SETUP([Early token definitions without --yacc])
129 # Found in GCJ: they expect the tokens to be defined before the user
130 # prologue, so that they can use the token definitions in it.
132 AT_BISON_OPTION_PUSHDEFS
133 AT_DATA_GRAMMAR([input.y],
134 [[%{
135 ]AT_YYERROR_DECLARE_EXTERN[
136 ]AT_YYLEX_DECLARE_EXTERN[
137 void print_my_token (void);
140 %union
142   int val;
145 #include <stdio.h>
146 void
147 print_my_token (void)
149   enum yytokentype tok1 = MY_TOKEN;
150   yytoken_kind_t   tok2 = MY_TOKEN;
151   printf ("%d, %d\n", tok1, tok2);
154 %token MY_TOKEN
156 exp: MY_TOKEN;
159 AT_BISON_OPTION_POPDEFS
161 AT_BISON_CHECK([-o input.c input.y])
162 AT_COMPILE([input.o])
164 AT_CLEANUP
168 ## ---------------- ##
169 ## Braces parsing.  ##
170 ## ---------------- ##
173 AT_SETUP([Braces parsing])
175 AT_BISON_OPTION_PUSHDEFS
176 AT_DATA([input.y],
177 [[/* Bison used to swallow the character after '}'. */
180 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
183 AT_BISON_OPTION_POPDEFS
185 AT_BISON_CHECK([-v -o input.c input.y])
187 AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
189 AT_CLEANUP
192 ## ------------------- ##
193 ## Rule Line Numbers.  ##
194 ## ------------------- ##
196 AT_SETUP([Rule Line Numbers])
198 AT_KEYWORDS([report])
200 AT_BISON_OPTION_PUSHDEFS
201 AT_DATA([input.y],
202 [[%%
203 expr:
230 AT_BISON_OPTION_POPDEFS
232 AT_BISON_CHECK([-o input.c -v input.y])
234 # Check the contents of the report.
235 AT_CHECK([cat input.output], [],
236 [[Grammar
238     0 $accept: expr $end
240     1 $@1: %empty
242     2 expr: 'a' $@1 'b'
244     3 $@2: %empty
246     4 expr: $@2 'c'
249 Terminals, with rules where they appear
251     $end (0) 0
252     'a' (97) 2
253     'b' (98) 2
254     'c' (99) 4
255     error (256)
258 Nonterminals, with rules where they appear
260     $accept (6)
261         on left: 0
262     expr (7)
263         on left: 2 4
264         on right: 0
265     $@1 (8)
266         on left: 1
267         on right: 2
268     $@2 (9)
269         on left: 3
270         on right: 4
273 State 0
275     0 $accept: . expr $end
277     'a'  shift, and go to state 1
279     $default  reduce using rule 3 ($@2)
281     expr  go to state 2
282     $@2   go to state 3
285 State 1
287     2 expr: 'a' . $@1 'b'
289     $default  reduce using rule 1 ($@1)
291     $@1  go to state 4
294 State 2
296     0 $accept: expr . $end
298     $end  shift, and go to state 5
301 State 3
303     4 expr: $@2 . 'c'
305     'c'  shift, and go to state 6
308 State 4
310     2 expr: 'a' $@1 . 'b'
312     'b'  shift, and go to state 7
315 State 5
317     0 $accept: expr $end .
319     $default  accept
322 State 6
324     4 expr: $@2 'c' .
326     $default  reduce using rule 4 (expr)
329 State 7
331     2 expr: 'a' $@1 'b' .
333     $default  reduce using rule 2 (expr)
336 AT_CLEANUP
340 ## ---------------------- ##
341 ## Mixing %token styles.  ##
342 ## ---------------------- ##
345 AT_SETUP([Mixing %token styles])
347 # Taken from the documentation.
348 AT_DATA([input.y],
349 [[%token  <operator>  OR      "||"
350 %token  <operator>  LE 134  "<="
351 %left  OR  "<="
353 exp: %empty;
357 AT_BISON_CHECK([-v -Wall -o input.c input.y], 0, [],
358 [[input.y:3.1-5: warning: useless precedence and associativity for "||" [-Wprecedence]
359 input.y:3.1-5: warning: useless precedence and associativity for "<=" [-Wprecedence]
362 AT_CLEANUP
366 ## ------------------- ##
367 ## Token definitions.  ##
368 ## ------------------- ##
370 m4_pushdef([AT_TEST],
371 [AT_SETUP([Token definitions: $1])
373 AT_BISON_OPTION_PUSHDEFS([$1])
376 # Clang chokes on some of our comments, because it tries to "parse"
377 # some documentation directives in the comments:
379 # input.c:131:48: error: '\a' command does not have a valid word argument [-Werror,-Wdocumentation]
380 #     SPECIAL = 261                  /* "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!"  */
381 #                                              ~~^
382 AT_DATA_GRAMMAR([input.y],
384 #if defined __clang__ && 10 <= __clang_major__
385 # pragma clang diagnostic ignored "-Wdocumentation"
386 #endif
388 ]AT_YYERROR_DECLARE[
389 ]AT_YYLEX_DECLARE[
392 %token MYEOF 0 "end of file"
393 %token 'a' "a"  // Bison managed, when fed with '%token 'f' "f"' to #define 'f'!
394 %token B_TOKEN "b"
395 %token C_TOKEN 'c'
396 %token 'd' D_TOKEN
397 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
398 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
400 exp: ]AT_ERROR_VERBOSE_IF(["\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"], ["∃¬∩∪∀"])[;
402 ]AT_YYERROR_DEFINE[
403 ]AT_YYLEX_DEFINE(["a"])[
404 ]AT_MAIN_DEFINE[
407 # Checking the warning message guarantees that the trigraph "??!" isn't
408 # unnecessarily escaped here even though it would need to be if encoded in a
409 # C-string literal.  Also notice that unnecessary escaping, such as "\?", from
410 # the user specification is eliminated.
411 AT_BISON_CHECK([-fcaret -o input.c input.y], [[0]], [[]],
412 [[input.y:26.8-14: warning: symbol SPECIAL redeclared [-Wother]
413    26 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
414       |        ^~~~~~~
415 input.y:25.8-14: note: previous declaration
416    25 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
417       |        ^~~~~~~
418 input.y:26.16-63: warning: symbol "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!" used more than once as a literal string [-Wother]
419    26 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
420       |                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
423 AT_COMPILE([input])
425 # Checking the error message here guarantees that yytname, which does contain
426 # C-string literals, does have the trigraph escaped correctly.  Thus, the
427 # symbol name reported by the parser is exactly the same as that reported by
428 # Bison itself.
429 AT_PARSER_CHECK([input], 1, [],
430 [[syntax error, unexpected a, expecting ]AT_ERROR_VERBOSE_IF([["\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"]], [[∃¬∩∪∀]])[
433 AT_BISON_OPTION_POPDEFS
434 AT_CLEANUP
437 AT_TEST([%define parse.error detailed])
438 AT_TEST([%define parse.error verbose])
440 m4_popdef([AT_TEST])
442 ## -------------------- ##
443 ## Characters Escapes.  ##
444 ## -------------------- ##
447 AT_SETUP([Characters Escapes])
449 AT_BISON_OPTION_PUSHDEFS
450 AT_DATA_GRAMMAR([input.y],
452 ]AT_YYERROR_DECLARE_EXTERN[
453 ]AT_YYLEX_DECLARE_EXTERN[
456 exp:
457   '\'' "\'"
458 | '\"' "\""
459 | '"'  "'" /* Pacify font-lock-mode: ". */
463 AT_BISON_OPTION_POPDEFS
465 AT_BISON_CHECK([-o input.c input.y])
466 AT_COMPILE([input.o])
467 AT_CLEANUP
471 ## -------------- ##
472 ## Web2c Report.  ##
473 ## -------------- ##
475 # The generation of the reduction was once wrong in Bison, and made it
476 # miss some reductions.  In the following test case, the reduction on
477 # 'undef_id_tok' in state 1 was missing.  This is stripped down from
478 # the actual web2c.y.
480 AT_SETUP([Web2c Report])
482 AT_KEYWORDS([report])
484 AT_DATA([input.y],
485 [[%token        undef_id_tok const_id_tok
487 %start CONST_DEC_PART
490 CONST_DEC_PART:
491          CONST_DEC_LIST
492         ;
494 CONST_DEC_LIST:
495           CONST_DEC
496         | CONST_DEC_LIST CONST_DEC
497         ;
499 CONST_DEC:
500           { } undef_id_tok '=' const_id_tok ';'
501         ;
505 AT_BISON_CHECK([-v input.y])
506 AT_CHECK([cat input.output], 0,
507 [[Grammar
509     0 $accept: CONST_DEC_PART $end
511     1 CONST_DEC_PART: CONST_DEC_LIST
513     2 CONST_DEC_LIST: CONST_DEC
514     3               | CONST_DEC_LIST CONST_DEC
516     4 $@1: %empty
518     5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';'
521 Terminals, with rules where they appear
523     $end (0) 0
524     ';' (59) 5
525     '=' (61) 5
526     error (256)
527     undef_id_tok (258) 5
528     const_id_tok (259) 5
531 Nonterminals, with rules where they appear
533     $accept (7)
534         on left: 0
535     CONST_DEC_PART (8)
536         on left: 1
537         on right: 0
538     CONST_DEC_LIST (9)
539         on left: 2 3
540         on right: 1 3
541     CONST_DEC (10)
542         on left: 5
543         on right: 2 3
544     $@1 (11)
545         on left: 4
546         on right: 5
549 State 0
551     0 $accept: . CONST_DEC_PART $end
553     $default  reduce using rule 4 ($@1)
555     CONST_DEC_PART  go to state 1
556     CONST_DEC_LIST  go to state 2
557     CONST_DEC       go to state 3
558     $@1             go to state 4
561 State 1
563     0 $accept: CONST_DEC_PART . $end
565     $end  shift, and go to state 5
568 State 2
570     1 CONST_DEC_PART: CONST_DEC_LIST .
571     3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
573     undef_id_tok  reduce using rule 4 ($@1)
574     $default      reduce using rule 1 (CONST_DEC_PART)
576     CONST_DEC  go to state 6
577     $@1        go to state 4
580 State 3
582     2 CONST_DEC_LIST: CONST_DEC .
584     $default  reduce using rule 2 (CONST_DEC_LIST)
587 State 4
589     5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';'
591     undef_id_tok  shift, and go to state 7
594 State 5
596     0 $accept: CONST_DEC_PART $end .
598     $default  accept
601 State 6
603     3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
605     $default  reduce using rule 3 (CONST_DEC_LIST)
608 State 7
610     5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';'
612     '='  shift, and go to state 8
615 State 8
617     5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';'
619     const_id_tok  shift, and go to state 9
622 State 9
624     5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';'
626     ';'  shift, and go to state 10
629 State 10
631     5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' .
633     $default  reduce using rule 5 (CONST_DEC)
636 AT_CLEANUP
639 ## --------------- ##
640 ## Web2c Actions.  ##
641 ## --------------- ##
643 # The generation of the mapping 'state -> action' was once wrong in
644 # extremely specific situations.  web2c.y exhibits this situation.
645 # Below is a stripped version of the grammar.  It looks like one can
646 # simplify it further, but just don't: it is tuned to exhibit a bug,
647 # which disappears when applying sane grammar transformations.
649 # It used to be wrong on yydefact only:
651 # static const yytype_uint8 yydefact[] =
652 #  {
653 # -       2,     0,     1,     0,     0,     2,     3,     2,     5,     4,
654 # +       2,     0,     1,     0,     0,     0,     3,     2,     5,     4,
655 #         0,     0
656 #  };
658 # but let's check all the tables.
661 AT_SETUP([Web2c Actions])
663 AT_KEYWORDS([report])
665 AT_DATA([input.y],
666 [[%%
667 statement:  struct_stat;
668 struct_stat:  %empty | if else;
669 if: "if" "const" "then" statement;
670 else: "else" statement;
674 AT_BISON_CHECK([-v -o input.c input.y])
676 # Check only the tables.
677 [sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p;/#define YY.*NINF/p' input.c >tables.c]
679 AT_CHECK([[cat tables.c]], 0,
680 [[static const yytype_int8 yytranslate[] =
682        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
683        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
684        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
685        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
686        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
687        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
688        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
689        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
690        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
691        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
692        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
693        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
694        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
695        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
696        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
697        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
698        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
699        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
700        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
701        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
702        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
703        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
704        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
705        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
706        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
707        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
708        5,     6
710 static const yytype_int8 yyrline[] =
712        0,     2,     2,     3,     3,     4,     5
714 static const char *const yytname[] =
716   "\"end of file\"", "error", "\"invalid token\"", "\"if\"", "\"const\"",
717   "\"then\"", "\"else\"", "$accept", "statement", "struct_stat", "if",
718   "else", YY_NULLPTR
720 #define YYPACT_NINF (-8)
721 #define YYTABLE_NINF (-1)
722 static const yytype_int8 yypact[] =
724       -2,    -1,     4,    -8,     0,     2,    -8,    -2,    -8,    -2,
725       -8,    -8
727 static const yytype_int8 yydefact[] =
729        3,     0,     0,     2,     0,     0,     1,     3,     4,     3,
730        6,     5
732 static const yytype_int8 yypgoto[] =
734       -8,    -7,    -8,    -8,    -8
736 static const yytype_int8 yydefgoto[] =
738        0,     2,     3,     4,     8
740 static const yytype_int8 yytable[] =
742       10,     1,    11,     5,     6,     0,     7,     9
744 static const yytype_int8 yycheck[] =
746        7,     3,     9,     4,     0,    -1,     6,     5
748 static const yytype_int8 yystos[] =
750        0,     3,     8,     9,    10,     4,     0,     6,    11,     5,
751        8,     8
753 static const yytype_int8 yyr1[] =
755        0,     7,     8,     9,     9,    10,    11
757 static const yytype_int8 yyr2[] =
759        0,     2,     1,     0,     2,     4,     2
763 AT_CLEANUP
766 ## ---------------- ##
767 ## Useless Tokens.  ##
768 ## ---------------- ##
770 # In some extreme situations, with lots of useless tokens, Bison was
771 # numbering them incorrectly, which resulted in a broken grammar.
772 # <https://lists.gnu.org/r/bison-patches/2021-03/msg00001.html>
773 # commit a774839ca873d1082f79ba3c4eecc1e242a28ce1.
775 # To track this failure, compare the tables between an incorrect
776 # version of Bison (e.g., 3.7.5), and a correct one:
778 # LC_ALL=C /usr/local/stow/bison-3.7.5/bin/bison input.y -o old.c &&
779 # LC_ALL=C                                 bison input.y -o new.c &&
780 # sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p' old.c >old.tables &&
781 # sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p' new.c >new.tables &&
782 # diff old.tables new.tables
784 # The following Ruby script normalizes token and nterm names.
786 # #! /usr/bin/env ruby
788 # require 'strscan'
790 # tokens = {}
791 # nterms = {}
793 # ARGV.each do |file|
794 #   s = StringScanner.new File.read(file)
795 #   while !s.eos?
796 #     $stdout <<
797 #       case
798 #       when s.scan(/%\w+/)
799 #         s.matched
800 #       when s.scan(/[A-Z_0-9]+/)
801 #         tokens[s.matched] ||= 'T%02d' % tokens.size
802 #       when s.scan(/[a-z_0-9]+/)
803 #         nterms[s.matched] ||= 'n%02d' % nterms.size
804 #       when s.scan(/.|\n/)
805 #         s.matched
806 #       else
807 #         raise "error: #{s.rest}"
808 #       end
809 #   end
810 # end
812 AT_SETUP([Useless Tokens])
814 AT_DATA([input.y],
815 [[%token
816   T00 T01 T02 T03 T04 T05 T06 T07 T08 T09 T10 T11 T12 T13 T14 T15 T16
817   T17 T18 T19 T20 T21 T22 T23 T24 T25 T26 T27 T28 T29 T30 T31 T32 T33
818   T34 T35 T36 T37 T38 T39 T40 T41 T42 T43 T44 T45 T46 T47 T48 T49 T50
819   T51 T52 T53 T54 T55 T56 T57 T58 T59 T60 T61 T62 T63 T64 T65 T66 T67
820   T68 T69 T70 T71 T72 T73 T74 T75 T76 T77 T78 T79 T80 T81 T82 T83 T84
821   T85 T86 T87 T88 T89 T90
825 n00: T00 n01;
826 n01: T77 T88 n02 T89;
827 n02: n03 n02 | %empty;
828 n03: T16 T88 n04 T89 | T79 T88 n05 T89 | T78 T88 n06 T89 | T81 T88 n07 T89 | T82 T88 n05 T89 | T83 T88 n05 T89 | T84 T88 n05 T89 | T80 T88 n08 T89 | n09;
829 n04: n10 n04 | %empty;
830 n05: T58 | T61;
831 n06: n10
832 n07: n05 | n11;
833 n08: n12;
834 n09: T30 T88 n05 T89;
835 n11: n13 n11 | %empty;
836 n13: T85 T88 n05 T89 | T86 T88 n08 T89;
837 n10: n05;
838 n14: %empty;
839 n15: n16 T90 n15;
840 n16: n17;
841 n18: T58;
842 n17: T07 T88 n19 T89;
843 n19: n20;
844 n20: n21 n20;
845 n21: T13 T88 n22 T89;
846 n22: n23;
847 n24: n25;
848 n25: n26 T90 n25 | n27 T90 n25;
849 n26: n28;
850 n28: T58;
851 n29: n30 T90 n29;
852 n30: T02 T88 n05 T89;
853 n31: T04 T88 n32 T89;
854 n33: n32;
855 n32: n27 T90 n32;
856 n27: T03 T88 n34 T89;
857 n35: n36;
858 n36: T05 T88 n34 T89 | n36 T06 T88 n34 T89;
859 n34: n29 n33 n37;
860 n37: T16 T88 n38 T89 T90;
861 n38: n10 n38;
862 n39: n05 | T58 T88 n05 T89;
863 n40: n39;
864 n41: n40 n41;
865 n42: T48;
866 n43: n42;
867 n44: T59;
868 n45: n44;
869 n23: T59;
870 n46: T60;
871 n47: T60;
872 n48: n05;
873 n49: n05;
874 n50: n49;
875 n51: n49;
876 n52: n05;
877 n12: n05 n12 | %empty;
878 n53: n05;
879 n54: n05;
880 n55: T15 T88 n05 T89;
881 n56: T58;
882 n57: n56;
883 n58: T58;
884 n59: T13 T88 n22 T89;
885 n60: T75 T88 n22 T89;
886 n61: T18 T88 n05 T89;
887 n62: T76 T88 n46 T89;
888 n63: n05 n63;
889 n64: T14 T88 n22 T89;
890 n65: T10 T88 n42 T89;
891 n66: n05 n66;
892 n67: T08 T88 n05 T89;
893 n68: T11 T88 n42 T89;
894 n69: T17 T88 n05 T89;
895 n70: n71 n70;
896 n71: T16 T88 n72 T89;
897 n72: n10 n72;
898 n73: T24 T88 n48 T89;
899 n74: T12 T88 n05 T89;
900 n75: T09 T88 n05 T89;
901 n76: n05 n76;
902 n77: T64 T88 n78 T89;
903 n78: n79 n78;
904 n79: T66 T88 n05 n40 T89;
905 n80: n05 n80;
906 n81: n82 n81;
907 n82: T69 T88 n22 T89;
908 n83: T47 T88 n05 T89;
909 n84: T46 T88 T89;
912 AT_BISON_CHECK([-Wno-other -o input.c input.y])
914 # Check only the tables.
915 [sed -n 's/  *$//;/^static const.*\[\] =/,/^}/p;/#define YY.*NINF/p' input.c >tables.c]
917 AT_CHECK([[cat tables.c]], 0,
918 [[static const yytype_int8 yytranslate[] =
920        0,     2,     2,     2,     2,     2,     2,     2,     2,     2,
921        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
922        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
923        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
924        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
925        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
926        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
927        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
928        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
929        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
930        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
931        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
932        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
933        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
934        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
935        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
936        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
937        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
938        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
939        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
940        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
941        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
942        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
943        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
944        2,     2,     2,     2,     2,     2,     2,     2,     2,     2,
945        2,     2,     2,     2,     2,     2,     1,     2,     3,     4,
946        5,     6,     7,     8,     9,    10,    11,    12,    13,    14,
947       15,    16,    17,    18,    19,    20,    21,    22,    23,    24,
948       25,    26,    27,    28,    29,    30,    31,    32,    33,    34,
949       35,    36,    37,    38,    39,    40,    41,    42,    43,    44,
950       45,    46,    47,    48,    49,    50,    51,    52,    53,    54,
951       55,    56,    57,    58,    59,    60,    61,    62,    63,    64,
952       65,    66,    67,    68,    69,    70,    71,    72,    73,    74,
953       75,    76,    77,    78,    79,    80,    81,    82,    83,    84,
954       85,    86,    87,    88,    89,    90,    91,    92,    93
956 static const yytype_int8 yyrline[] =
958        0,    11,    11,    12,    13,    13,    14,    14,    14,    14,
959       14,    14,    14,    14,    14,    15,    15,    16,    16,    17,
960       18,    18,    19,    20,    21,    21,    22,    22,    23,    63,
961       63
963 static const char *const yytname[] =
965   "\"end of file\"", "error", "\"invalid token\"", "T00", "T01", "T02",
966   "T03", "T04", "T05", "T06", "T07", "T08", "T09", "T10", "T11", "T12",
967   "T13", "T14", "T15", "T16", "T17", "T18", "T19", "T20", "T21", "T22",
968   "T23", "T24", "T25", "T26", "T27", "T28", "T29", "T30", "T31", "T32",
969   "T33", "T34", "T35", "T36", "T37", "T38", "T39", "T40", "T41", "T42",
970   "T43", "T44", "T45", "T46", "T47", "T48", "T49", "T50", "T51", "T52",
971   "T53", "T54", "T55", "T56", "T57", "T58", "T59", "T60", "T61", "T62",
972   "T63", "T64", "T65", "T66", "T67", "T68", "T69", "T70", "T71", "T72",
973   "T73", "T74", "T75", "T76", "T77", "T78", "T79", "T80", "T81", "T82",
974   "T83", "T84", "T85", "T86", "T87", "T88", "T89", "T90", "$accept", "n00",
975   "n01", "n02", "n03", "n04", "n05", "n06", "n07", "n08", "n09", "n11",
976   "n13", "n10", "n12", YY_NULLPTR
978 #define YYPACT_NINF (-78)
979 #define YYTABLE_NINF (-1)
980 static const yytype_int8 yypact[] =
982       -2,   -77,    11,   -73,   -78,   -78,   -19,   -71,   -69,   -68,
983      -67,   -66,   -65,   -64,   -63,   -62,   -61,   -19,   -78,   -49,
984      -49,   -49,   -49,   -49,   -51,   -49,   -49,   -49,   -78,   -78,
985      -78,   -78,   -60,   -78,   -49,   -59,   -58,   -78,   -57,   -49,
986      -56,   -78,   -52,   -48,   -78,   -50,   -78,   -72,   -47,   -46,
987      -45,   -78,   -78,   -78,   -78,   -78,   -78,   -78,   -49,   -49,
988      -78,   -78,   -78,   -78,   -78,   -44,   -43,   -78,   -78
990 static const yytype_int8 yydefact[] =
992        0,     0,     0,     0,     2,     1,     5,     0,     0,     0,
993        0,     0,     0,     0,     0,     0,     0,     5,    14,    16,
994        0,     0,     0,    30,    25,     0,     0,     0,     3,     4,
995       17,    18,     0,    28,    16,     0,     0,    19,     0,    30,
996        0,    22,     0,     0,    20,     0,    21,    25,     0,     0,
997        0,     6,    15,    23,     8,     7,    29,    13,     0,    30,
998        9,    24,    10,    11,    12,     0,     0,    26,    27
1000 static const yytype_int8 yypgoto[] =
1002      -78,   -78,   -78,     2,   -78,    -4,   -18,   -78,   -78,   -15,
1003      -78,     3,   -78,    30,    13
1005 static const yytype_int8 yydefgoto[] =
1007        0,     2,     4,    16,    17,    32,    33,    36,    45,    40,
1008       18,    46,    47,    34,    41
1010 static const yytype_int8 yytable[] =
1012        7,     1,    35,     3,    38,    39,    44,    48,    49,    50,
1013       30,     5,    30,    31,     8,    31,    42,    43,     6,    29,
1014       19,    39,    20,    21,    22,    23,    24,    25,    26,    27,
1015       52,    28,    51,    53,    54,    55,    57,    42,    43,    58,
1016       65,    39,    60,    59,    66,    62,    63,    64,    67,    68,
1017       61,    37,    56,     0,     0,     0,     0,     0,     0,     0,
1018        0,     0,     9,    10,    11,    12,    13,    14,    15
1020 static const yytype_int8 yycheck[] =
1022       19,     3,    20,    80,    22,    23,    24,    25,    26,    27,
1023       61,     0,    61,    64,    33,    64,    88,    89,    91,    17,
1024       91,    39,    91,    91,    91,    91,    91,    91,    91,    91,
1025       34,    92,    92,    92,    92,    92,    92,    88,    89,    91,
1026       58,    59,    92,    91,    59,    92,    92,    92,    92,    92,
1027       47,    21,    39,    -1,    -1,    -1,    -1,    -1,    -1,    -1,
1028       -1,    -1,    81,    82,    83,    84,    85,    86,    87
1030 static const yytype_int8 yystos[] =
1032        0,     3,    95,    80,    96,     0,    91,    19,    33,    81,
1033       82,    83,    84,    85,    86,    87,    97,    98,   104,    91,
1034       91,    91,    91,    91,    91,    91,    91,    91,    92,    97,
1035       61,    64,    99,   100,   107,   100,   101,   107,   100,   100,
1036      103,   108,    88,    89,   100,   102,   105,   106,   100,   100,
1037      100,    92,    99,    92,    92,    92,   108,    92,    91,    91,
1038       92,   105,    92,    92,    92,   100,   103,    92,    92
1040 static const yytype_int8 yyr1[] =
1042        0,    94,    95,    96,    97,    97,    98,    98,    98,    98,
1043       98,    98,    98,    98,    98,    99,    99,   100,   100,   101,
1044      102,   102,   103,   104,   105,   105,   106,   106,   107,   108,
1045      108
1047 static const yytype_int8 yyr2[] =
1049        0,     2,     2,     4,     2,     0,     4,     4,     4,     4,
1050        4,     4,     4,     4,     1,     2,     0,     1,     1,     1,
1051        1,     1,     1,     4,     2,     0,     4,     4,     1,     2,
1052        0
1056 AT_CLEANUP
1060 ## ------------------------- ##
1061 ## yycheck Bound Violation.  ##
1062 ## ------------------------- ##
1065 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
1066 # --------------------------------
1067 # The following grammar, taken from Andrew Suffield's GPL'd implementation
1068 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
1069 # yycheck's bounds where issuing a verbose error message.  Keep this test
1070 # so that possible bound checking compilers could check all the skeletons.
1071 m4_define([_AT_DATA_DANCER_Y],
1072 [AT_DATA_GRAMMAR([dancer.y],
1073 [[%code provides
1075   ]AT_YYERROR_DECLARE[
1076   ]AT_YYLEX_DECLARE[
1079 %token ARROW INVALID NUMBER STRING DATA
1080 %verbose
1081 %define parse.error verbose
1082 /* Grammar follows */
1084 line: header body
1085    ;
1087 header: '<' from ARROW to '>' type ':'
1088    | '<' ARROW to '>' type ':'
1089    | ARROW to type ':'
1090    | type ':'
1091    | '<' '>'
1092    ;
1094 from: DATA
1095    | STRING
1096    | INVALID
1097    ;
1099 to: DATA
1100    | STRING
1101    | INVALID
1102    ;
1104 type: DATA
1105    | STRING
1106    | INVALID
1107    ;
1109 body: %empty
1110    | body member
1111    ;
1113 member: STRING
1114    | DATA
1115    | '+' NUMBER
1116    | '-' NUMBER
1117    | NUMBER
1118    | INVALID
1119    ;
1121 ]AT_YYERROR_DEFINE[
1122 ]AT_YYLEX_DEFINE([":"])[
1123 ]AT_MAIN_DEFINE[
1125 ])# _AT_DATA_DANCER_Y
1128 # AT_CHECK_DANCER(BISON-OPTIONS)
1129 # ------------------------------
1130 # Generate the grammar, compile it, run it.
1131 m4_define([AT_CHECK_DANCER],
1132 [AT_SETUP([Dancer $1])
1133 AT_BISON_OPTION_PUSHDEFS([$1])
1134 _AT_DATA_DANCER_Y([$1])
1135 AT_FULL_COMPILE([dancer])
1136 AT_PARSER_CHECK([dancer], 1, [],
1137 [syntax error, unexpected ':'
1139 AT_BISON_OPTION_POPDEFS
1140 AT_CLEANUP
1143 AT_CHECK_DANCER()
1144 AT_CHECK_DANCER([%glr-parser])
1145 AT_CHECK_DANCER([%skeleton "lalr1.cc"])
1148 ## ------------------------------------------ ##
1149 ## Diagnostic that expects two alternatives.  ##
1150 ## ------------------------------------------ ##
1153 # _AT_DATA_EXPECT2_Y(BISON-OPTIONS)
1154 # --------------------------------
1155 m4_define([_AT_DATA_EXPECT2_Y],
1156 [AT_DATA_GRAMMAR([expect2.y],
1158 static int yylex (AT_LALR1_CC_IF([int *], [void]));
1159 AT_LALR1_CC_IF([[#include <cstdlib>]],
1161 ]AT_YYERROR_DECLARE])[
1164 %define parse.error verbose
1165 %token A 1000
1166 %token B
1169 program: %empty
1170  | program e ';'
1171  | program error ';';
1173 e: e '+' t | t;
1174 t: A | B;
1177 ]AT_YYERROR_DEFINE[
1178 ]AT_LALR1_CC_IF(
1179 [int
1180 yyparse ()
1182   yy::parser parser;
1183   return parser.parse ();
1187 #include <assert.h>
1188 static int
1189 yylex (]AT_LALR1_CC_IF([int *lval], [void])[)
1191   static int const tokens[] =
1192     {
1193       1000, '+', '+', -1
1194     };
1195   static size_t toknum;
1196   ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC.  */])[
1197   assert (toknum < sizeof tokens / sizeof *tokens);
1198   return tokens[toknum++];
1200 ]AT_MAIN_DEFINE[
1202 ])# _AT_DATA_EXPECT2_Y
1205 # AT_CHECK_EXPECT2(BISON-OPTIONS)
1206 # -------------------------------
1207 # Generate the grammar, compile it, run it.
1208 m4_define([AT_CHECK_EXPECT2],
1209 [AT_SETUP([Expecting two tokens $1])
1210 AT_BISON_OPTION_PUSHDEFS([$1])
1211 _AT_DATA_EXPECT2_Y([$1])
1212 AT_FULL_COMPILE([expect2])
1213 AT_PARSER_CHECK([expect2], 1, [],
1214 [syntax error, unexpected '+', expecting A or B
1216 AT_BISON_OPTION_POPDEFS
1217 AT_CLEANUP
1220 AT_CHECK_EXPECT2()
1221 AT_CHECK_EXPECT2([%glr-parser])
1222 AT_CHECK_EXPECT2([%skeleton "lalr1.cc"])
1226 ## --------------------------------------------- ##
1227 ## Braced code in declaration in rules section.  ##
1228 ## --------------------------------------------- ##
1230 AT_SETUP([Braced code in declaration in rules section])
1232 # Bison once mistook braced code in a declaration in the rules section to be a
1233 # rule action.
1234 AT_BISON_OPTION_PUSHDEFS([%debug])
1235 AT_DATA_GRAMMAR([input.y],
1236 [[%{
1237 ]AT_YYERROR_DECLARE[
1238 ]AT_YYLEX_DECLARE[
1240 %debug
1241 %define parse.error verbose
1244 start:
1245   {
1246     printf ("Bison would once convert this action to a midrule because of the"
1247             " subsequent braced code.\n");
1248   }
1249   ;
1251 %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
1252 %printer { fprintf (yyo, "PRINTER"); } 'a';
1255 ]AT_YYERROR_DEFINE[
1256 ]AT_YYLEX_DEFINE(["a"])[
1257 ]AT_MAIN_DEFINE[
1259 AT_BISON_OPTION_POPDEFS
1261 AT_BISON_CHECK([-o input.c input.y])
1262 AT_COMPILE([input])
1263 AT_PARSER_CHECK([input --debug], 1,
1264 [[Bison would once convert this action to a midrule because of the subsequent braced code.
1266 [[Starting parse
1267 Entering state 0
1268 Stack now 0
1269 Reducing stack by rule 1 (line 20):
1270 -> $$ = nterm start ()
1271 Entering state 1
1272 Stack now 0 1
1273 Reading a token
1274 Next token is token 'a' (PRINTER)
1275 syntax error, unexpected 'a', expecting end of file
1276 Error: popping nterm start ()
1277 Stack now 0
1278 Cleanup: discarding lookahead token 'a' (PRINTER)
1279 DESTRUCTOR
1280 Stack now 0
1283 AT_CLEANUP
1287 ## --------------------------------- ##
1288 ## String alias declared after use.  ##
1289 ## --------------------------------- ##
1291 AT_SETUP([String alias declared after use])
1293 # Bison once incorrectly asserted that the symbol number for either a token or
1294 # its alias was the highest symbol number so far at the point of the alias
1295 # declaration.  That was true unless the declaration appeared after their first
1296 # uses and other tokens appeared in between.
1298 AT_DATA([input.y],
1299 [[%%
1300 start: 'a' "A" 'b';
1301 %token 'a' "A";
1304 AT_BISON_CHECK([-o input.c input.y])
1306 AT_CLEANUP
1310 ## -------------------------------- ##
1311 ## Extra lookahead sets in report.  ##
1312 ## -------------------------------- ##
1314 AT_SETUP([[Extra lookahead sets in report]])
1316 # Bison prints each reduction's lookahead set only next to the associated
1317 # state's one item that (1) is associated with the same rule as the reduction
1318 # and (2) has its dot at the end of its RHS.  Previously, Bison also
1319 # erroneously printed the lookahead set next to all of the state's other items
1320 # associated with the same rule.  This bug affected only the '.output' file and
1321 # not the generated parser source code.
1323 AT_DATA([[input.y]],
1324 [[%%
1325 start: a | 'a' a 'a' ;
1326 a: 'a' ;
1329 AT_BISON_CHECK([[--report=all input.y]])
1330 AT_CHECK([[sed -n '/^State 1$/,/^State 2$/p' input.output]], [[0]],
1331 [[State 1
1333     2 start: 'a' . a 'a'
1334     3 a: . 'a'
1335     3  | 'a' .  [$end]
1337     'a'  shift, and go to state 4
1339     $default  reduce using rule 3 (a)
1341     a  go to state 5
1344 State 2
1347 AT_CLEANUP
1351 ## ---------------------------------------- ##
1352 ## Token number in precedence declaration.  ##
1353 ## ---------------------------------------- ##
1355 AT_SETUP([[Token number in precedence declaration]])
1357 # POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
1358 # we lost this in Bison 1.50.
1359 AT_BISON_OPTION_PUSHDEFS
1360 AT_DATA_GRAMMAR([input.y],
1361 [[%code {
1362   ]AT_YYERROR_DECLARE[
1363   ]AT_YYLEX_DECLARE[
1365 %define parse.error verbose
1366 %token TK_ALIAS 3 "tok alias"
1367 %right END 0
1368 %left TK1 1 TK2 2 "tok alias"
1372 start:
1373     TK1 sr_conflict "tok alias"
1374   | start %prec END
1375   ;
1376 sr_conflict:
1377   TK2
1378   | TK2 "tok alias"
1379   ;
1383 ]AT_YYERROR_DEFINE[
1384 ]AT_YYLEX_DEFINE([{ 1, 2, 3, 0 }])[
1385 ]AT_MAIN_DEFINE[
1388 AT_BISON_CHECK([[-Wall -o input.c input.y]], [[0]],,
1389 [[input.y:24.5-19: warning: rule useless in parser due to conflicts [-Wother]
1390 input.y:28.5-19: warning: rule useless in parser due to conflicts [-Wother]
1391 input.y:18.1-5: warning: useless precedence and associativity for TK1 [-Wprecedence]
1393 AT_COMPILE([[input]])
1394 AT_PARSER_CHECK([[input]])
1395 AT_BISON_OPTION_POPDEFS
1397 AT_CLEANUP
1401 ## --------------------------- ##
1402 ## parse-gram.y: LALR = IELR.  ##
1403 ## --------------------------- ##
1405 # If parse-gram.y's LALR and IELR parser tables ever begin to differ, we
1406 # need to fix parse-gram.y or start using IELR.
1408 AT_SETUP([[parse-gram.y: LALR = IELR]])
1410 # Avoid tests/bison's dark magic by processing a local copy of the
1411 # grammar.  Avoid differences in synclines by telling bison that the
1412 # output files have the same name.
1413 [cp $abs_top_srcdir/src/parse-gram.y input.y]
1414 AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]])
1415 [mv input.c lalr.c]
1416 AT_CAPTURE_FILE([lalr.c])
1417 AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]])
1418 [mv input.c ielr.c]
1419 AT_CAPTURE_FILE([ielr.c])
1420 AT_CHECK([[diff lalr.c ielr.c]], [[0]])
1422 AT_CLEANUP
1426 ## -------------------------------------------- ##
1427 ## parse.error=verbose and YYSTACK_USE_ALLOCA.  ##
1428 ## -------------------------------------------- ##
1430 AT_SETUP([[parse.error=verbose and YYSTACK_USE_ALLOCA]])
1432 AT_BISON_OPTION_PUSHDEFS
1433 AT_DATA_GRAMMAR([input.y],
1434 [[%code {
1435   ]AT_YYERROR_DECLARE[
1436   ]AT_YYLEX_DECLARE[
1437   #define YYSTACK_USE_ALLOCA 1
1440 %define parse.error verbose
1444 start: check syntax_error syntax_error ;
1446 check:
1448   if (128 < sizeof yymsgbuf)
1449     {
1450       fprintf (stderr,
1451                "The initial size of yymsgbuf in yyparse has increased\n"
1452                "since this test group was last updated.  As a result,\n"
1453                "this test group may no longer manage to induce a\n"
1454                "reallocation of the syntax error message buffer.\n"
1455                "This test group must be adjusted to produce a longer\n"
1456                "error message.\n");
1457       YYABORT;
1458     }
1462 // Induce a syntax error message whose total length is more than
1463 // sizeof yymsgbuf in yyparse.  Each token here is 64 bytes.
1464 syntax_error:
1465   "123456789112345678921234567893123456789412345678951234567896123A"
1466 | "123456789112345678921234567893123456789412345678951234567896123B"
1467 | error 'a' 'b' 'c'
1472 ]AT_YYERROR_DEFINE[
1473   /* Induce two syntax error messages (which requires full error
1474      recovery by shifting 3 tokens) in order to detect any loss of the
1475      reallocated buffer.  */
1476 ]AT_YYLEX_DEFINE(["abc"])[
1477 ]AT_MAIN_DEFINE[
1479 AT_BISON_OPTION_POPDEFS
1481 AT_BISON_CHECK([[-o input.c input.y]])
1482 AT_COMPILE([[input]])
1483 AT_PARSER_CHECK([[input]], [[1]], [],
1484 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1485 syntax error, unexpected end of file, expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1488 AT_CLEANUP
1492 ## ------------------------------ ##
1493 ## parse.error=verbose overflow.  ##
1494 ## ------------------------------ ##
1496 # Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an
1497 # invocation of yysyntax_error has caused yymsg_alloc to grow to exactly
1498 # YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had
1499 # to be clipped to YYSTACK_ALLOC_MAXIMUM).  In an old version of yacc.c,
1500 # a subsequent invocation of yysyntax_error that overflows during its
1501 # size calculation would return YYSIZE_MAXIMUM to yyparse.  Then,
1502 # yyparse would invoke yyerror using the old contents of yymsg.
1504 AT_SETUP([[parse.error=verbose overflow]])
1506 AT_BISON_OPTION_PUSHDEFS
1507 AT_DATA_GRAMMAR([input.y],
1508 [[%code {
1509   ]AT_YYERROR_DECLARE[
1510   ]AT_YYLEX_DECLARE[
1512   /* This prevents this test case from having to induce error messages
1513      large enough to overflow size_t.  */
1514   #define YYSIZE_T unsigned char
1516   /* Bring in malloc and set EXIT_SUCCESS so yacc.c doesn't try to
1517      provide a malloc prototype using our YYSIZE_T.  */
1518   #include <stdlib.h>
1519   #ifndef EXIT_SUCCESS
1520   # define EXIT_SUCCESS 0
1521   #endif
1523   /* Max depth is usually much smaller than YYSTACK_ALLOC_MAXIMUM, and
1524      we don't want gcc to warn everywhere this constant would be too big
1525      to make sense for our YYSIZE_T.  */
1526   #define YYMAXDEPTH 100
1529 %define parse.error verbose
1533 start: syntax_error1 check syntax_error2 check syntax_error3;
1535 // Induce a syntax error message whose total length causes yymsg in
1536 // yyparse to be reallocated to size YYSTACK_ALLOC_MAXIMUM, which
1537 // should be 255.  Each token here is 64 bytes.
1538 syntax_error1:
1539   "123456789112345678921234567893123456789412345678951234567896123A"
1540 | "123456789112345678921234567893123456789412345678951234567896123B"
1541 | "123456789112345678921234567893123456789412345678951234567896123C"
1542 | error 'a' 'b' 'c'
1545 check:
1547   if (yymsg_alloc != YYSTACK_ALLOC_MAXIMUM
1548       || YYSTACK_ALLOC_MAXIMUM != YYSIZE_MAXIMUM
1549       || YYSIZE_MAXIMUM != 255)
1550     {
1551       fprintf (stderr,
1552                "The assumptions of this test group are no longer\n"
1553                "valid, so it may no longer catch the error it was\n"
1554                "designed to catch.  Specifically, the following\n"
1555                "values should all be 255:\n\n");
1556       fprintf (stderr, "  yymsg_alloc = %d\n", yymsg_alloc);
1557       fprintf (stderr, "  YYSTACK_ALLOC_MAXIMUM = %d\n",
1558                YYSTACK_ALLOC_MAXIMUM);
1559       fprintf (stderr, "  YYSIZE_MAXIMUM = %d\n", YYSIZE_MAXIMUM);
1560       YYABORT;
1561     }
1565 // We used to overflow memory here because the first four "expected"
1566 // tokens plus rest of the error message is greater that 255 bytes.
1567 // However there are *five* expected tokens here, so anyway we will
1568 // *not* display these tokens.  So the message fits, no overflow.
1569 syntax_error2:
1570   "123456789112345678921234567893123456789412345678951234567896123A"
1571 | "123456789112345678921234567893123456789412345678951234567896123B"
1572 | "123456789112345678921234567893123456789412345678951234567896123C"
1573 | "123456789112345678921234567893123456789412345678951234567896123D"
1574 | "123456789112345678921234567893123456789412345678951234567896123E"
1575 | error 'd' 'e' 'f'
1579 // Now overflow.
1580 syntax_error3:
1581   "123456789112345678921234567893123456789412345678951234567896123A"
1582 | "123456789112345678921234567893123456789412345678951234567896123B"
1583 | "123456789112345678921234567893123456789412345678951234567896123C"
1584 | "123456789112345678921234567893123456789412345678951234567896123D"
1589 ]AT_YYERROR_DEFINE[
1590   /* Induce two syntax error messages (which requires full error
1591      recovery by shifting 3 tokens).  */
1592 ]AT_YYLEX_DEFINE(["abcdef"])[
1594 main (void)
1596   /* Push parsers throw away the message buffer between tokens, so skip
1597      this test under maintainer-push-check.  */
1598   if (YYPUSH)
1599     return 77;
1600   return yyparse ();
1604 AT_BISON_CHECK([[-o input.c input.y]])
1606 # gcc warns about tautologies and fallacies involving comparisons for
1607 # unsigned char.  However, it doesn't produce these same warnings for
1608 # size_t and many other types when the warnings would seem to make just
1609 # as much sense.  We ignore the warnings.
1610 [CFLAGS="$NO_WERROR_CFLAGS"]
1611 AT_COMPILE([[input]])
1613 AT_PARSER_CHECK([[input]], [[2]], [],
1614 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B or 123456789112345678921234567893123456789412345678951234567896123C
1615 syntax error, unexpected 'd'
1616 syntax error
1617 memory exhausted
1619 AT_BISON_OPTION_POPDEFS
1620 AT_CLEANUP
1624 ## ------------------------ ##
1625 ## LAC: Exploratory stack.  ##
1626 ## ------------------------ ##
1628 AT_SETUP([[LAC: Exploratory stack]])
1629 AT_KEYWORDS([lac])
1631 m4_pushdef([AT_LAC_CHECK], [
1633 AT_BISON_OPTION_PUSHDEFS([%debug $1])
1635 AT_DATA_GRAMMAR([input.y],
1636 [AT_LANG_CASE(
1637 [d], [[%define api.symbol.prefix {SYM_}
1639 [java], [[%code imports {
1640   import java.io.IOException;
1643 %code lexer {
1644 ]AT_YYERROR_DEFINE[
1645 ]AT_YYLEX_DEFINE(["bbbbc"])[
1648 [[%code {
1649 #include <stdio.h> /* printf */
1650   ]AT_YYERROR_DECLARE[
1651   ]AT_YYLEX_DECLARE[
1653 ]])[
1654 %debug
1655 ]$1[
1656 %define parse.error verbose
1657 %token 'c'
1658 %expect 21
1661 // default reductions in inconsistent states
1662 // v   v v   v v v v   v v v v v v v
1663 S: A B A A B A A A A B A A A A A A A B C C A A A A A A A A A A A A B ;
1664 //       ^                     ^                               ^
1665 // LAC reallocs
1667 A: 'a' | %empty { ]AT_JAVA_IF([System.out.print], [printf])[ ("inconsistent default reduction\n"); } ;
1668 B: 'b' ;
1669 C: %empty { ]AT_JAVA_IF([System.out.print], [printf])[ ("consistent default reduction\n"); } ;
1672 ]AT_JAVA_IF([], [[
1673   ]AT_YYERROR_DEFINE[
1674   ]AT_YYLEX_DEFINE(["bbbbc"])[
1675 ]])[
1677 ]AT_MAIN_DEFINE[
1680 AT_FULL_COMPILE([[input]], [], [], [],
1681                 [[-Dparse.lac=full]AT_C_IF([ \
1682                  -Dparse.lac.es-capacity-initial=1 \
1683                  -Dparse.lac.memory-trace=full])])
1685 AT_PARSER_CHECK([[input --debug > stdout.txt 2> stderr.txt]], [[1]])
1687 # Make sure syntax error doesn't forget that 'a' is expected.  It would
1688 # be forgotten without lookahead correction.
1689 AT_CHECK([[grep 'syntax error,' stderr.txt]], [[0]],
1690 [[syntax error, unexpected 'c', expecting 'a' or 'b'
1693 # Check number of default reductions in inconsistent states to be sure
1694 # syntax error is detected before unnecessary reductions are performed.
1695 AT_PERL_CHECK([[-0777 -ne 'print s/inconsistent default reduction//g;' stdout.txt]],
1696               [[0]], [[14]])
1698 # Check number of default reductions in consistent states to be sure
1699 # it is performed before the syntax error is detected.
1700 AT_PERL_CHECK([[-0777 -ne 'print s/\bconsistent default reduction//g;' stdout.txt]],
1701               [[0]], [[2]])
1703 ]AT_C_IF([[
1704   # Check number of reallocs to be sure reallocated memory isn't somehow
1705   # lost between LAC invocations.
1706   AT_PERL_CHECK([[-0777 -ne 'print s/\(realloc//g;' < stderr.txt]], [[0]], [[3]])
1707 ]])[
1709 AT_BISON_OPTION_POPDEFS
1712 # C.
1713 AT_LAC_CHECK([[%define api.push-pull pull]])
1714 AT_LAC_CHECK([[%define api.push-pull pull %define api.pure]])
1715 AT_LAC_CHECK([[%define api.push-pull both]])
1716 AT_LAC_CHECK([[%define api.push-pull both %define api.pure]])
1718 # C++.
1719 AT_LAC_CHECK([[%skeleton "lalr1.cc"]])
1721 # D.
1722 # FIXME: does not work.  lalr1.d cannot work with literal chars,
1723 # and AT_YYLEX_DEFINE(d) is incorrect.
1724 # AT_LAC_CHECK([[%skeleton "lalr1.d"]])
1726 # Java.
1727 AT_LAC_CHECK([[%skeleton "lalr1.java"]])
1729 m4_popdef([AT_LAC_CHECK])
1731 AT_CLEANUP
1735 ## ------------------------ ##
1736 ## LAC: Memory exhaustion.  ##
1737 ## ------------------------ ##
1739 AT_SETUP([[LAC: Memory exhaustion]])
1740 AT_KEYWORDS([lac])
1742 m4_pushdef([AT_LAC_CHECK],
1743 [AT_BISON_OPTION_PUSHDEFS([%debug])
1744 AT_DATA_GRAMMAR([input.y],
1745 [[%code {
1746   ]AT_YYERROR_DECLARE[
1747   ]AT_YYLEX_DECLARE[
1748   #define YYMAXDEPTH 8
1750 %debug
1751 %define parse.error verbose
1752 %expect 8
1755 S: A A A A A A A A A ;
1756 A: %empty | 'a' ;
1759 ]AT_YYERROR_DEFINE[
1760 ]AT_YYLEX_DEFINE(["$1"])[
1761 ]AT_MAIN_DEFINE[
1764 AT_FULL_COMPILE([input], [], [], [],
1765                 [[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1]])
1766 AT_COMPILE([[input]])
1767 AT_BISON_OPTION_POPDEFS
1770 # Check for memory exhaustion during parsing.
1771 AT_LAC_CHECK([])
1772 AT_PARSER_CHECK([[input --debug]], [[2]], [],
1773 [[Starting parse
1774 Entering state 0
1775 Stack now 0
1776 Reading a token
1777 Now at end of input.
1778 LAC: initial context established for "end of file"
1779 LAC: checking lookahead "end of file": R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
1780 memory exhausted
1781 Cleanup: discarding lookahead token "end of file" ()
1782 Stack now 0
1785 # Induce an immediate syntax error with an undefined token, and check
1786 # for memory exhaustion while building syntax error message.
1787 AT_LAC_CHECK([z], [[0]])
1788 AT_PARSER_CHECK([[input --debug]], [[2]], [],
1789 [[Starting parse
1790 Entering state 0
1791 Stack now 0
1792 Reading a token
1793 Next token is token "invalid token" ()
1794 LAC: initial context established for "invalid token"
1795 LAC: checking lookahead "invalid token": Always Err
1796 Constructing syntax error message
1797 LAC: checking lookahead "end of file": R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
1798 syntax error
1799 memory exhausted
1800 Cleanup: discarding lookahead token "invalid token" ()
1801 Stack now 0
1804 m4_popdef([AT_LAC_CHECK])
1806 AT_CLEANUP
1809 ## ---------------------- ##
1810 ## Lex and parse params.  ##
1811 ## ---------------------- ##
1813 # AT_TEST(SKELETON)
1814 # -----------------
1815 # Check that the identifier of the params is properly fetched
1816 # even when there are trailing blanks.
1818 m4_pushdef([AT_TEST],
1819 [AT_SETUP([[Lex and parse params: $1]])
1821 ## FIXME: Improve parsing of parse-param.
1822 AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" %parse-param { int x } %parse-param { int y }])
1824 AT_DATA_GRAMMAR([input.y],
1825 [[%header
1826 %locations
1827 %skeleton "$1"
1828 %union { int ival; }
1829 %parse-param { int x }
1830 // Spaces, tabs, and new lines.
1831 %parse-param { @&t@
1832 @tb@ int y@tb@ @&t@
1833          @&t@
1834  @&t@
1838 #include <stdio.h> /* printf. */
1839   ]AT_YYERROR_DECLARE[
1840   ]AT_YYLEX_DECLARE[
1844 exp: 'a' { printf ("x: %d, y: %d\n", x, y); };
1846 ]AT_YYERROR_DEFINE[
1847 ]AT_YYLEX_DEFINE(["a"])[
1849 ]AT_CXX_IF(
1850 [int
1851 yyparse (int x, int y)
1853   yy::parser parser(x, y);
1854   return parser.parse ();
1859 main (void)
1861   return yyparse(1, 2);
1865 AT_FULL_COMPILE([input])
1866 AT_PARSER_CHECK([input], 0, [[x: 1, y: 2
1868 AT_BISON_OPTION_POPDEFS
1870 AT_CLEANUP
1873 ## FIXME: test Java, and iterate over skeletons.
1874 AT_TEST([yacc.c])
1875 AT_TEST([glr.c])
1876 AT_TEST([lalr1.cc])
1877 AT_TEST([glr.cc])
1878 AT_TEST([glr2.cc])
1880 m4_popdef([AT_TEST])
1883 ## ----------------------- ##
1884 ## stdio.h is not needed.  ##
1885 ## ----------------------- ##
1887 # At some point, by accident, yy_location_print_ was using fprintf and
1888 # FILE which are from stdio.h, which we do not require.
1889 AT_SETUP([[stdio.h is not needed]])
1891 AT_BISON_OPTION_PUSHDEFS
1893 AT_DATA_GRAMMAR([input.y],
1894 [[%locations
1895 %code
1897   static int yylex (void) { return 0; }
1898   static void yyerror (const char* msg) { (void) msg; }
1901 exp: {}
1903 ]AT_MAIN_DEFINE[
1906 AT_FULL_COMPILE([input])
1908 AT_BISON_OPTION_POPDEFS
1910 AT_CLEANUP