1 # Bison Regressions. -*- Autotest -*-
3 # Copyright (C) 2001-2012 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 <http://www.gnu.org/licenses/>.
18 AT_BANNER([[Regression tests.]])
21 ## ------------------ ##
22 ## Trivial grammars. ##
23 ## ------------------ ##
25 AT_SETUP([Trivial grammars])
27 AT_DATA_GRAMMAR([input.y],
29 void yyerror (char const *);
41 AT_BISON_CHECK([-o input.c input.y])
42 AT_COMPILE([input.o], [-c input.c])
43 AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
49 ## ----------------- ##
50 ## YYSTYPE typedef. ##
51 ## ----------------- ##
53 AT_SETUP([YYSTYPE typedef])
55 AT_DATA_GRAMMAR([input.y],
57 void yyerror (char const *);
59 typedef union { char const *val; } YYSTYPE;
66 program: { $$ = ""; };
69 AT_BISON_CHECK([-o input.c input.y])
70 AT_COMPILE([input.o], [-c input.c])
76 ## ------------------------------------- ##
77 ## Early token definitions with --yacc. ##
78 ## ------------------------------------- ##
81 AT_SETUP([Early token definitions with --yacc])
83 # Found in GCJ: they expect the tokens to be defined before the user
84 # prologue, so that they can use the token definitions in it.
86 AT_DATA_GRAMMAR([input.y],
88 void yyerror (const char *s);
98 # error "MY_TOKEN not defined."
107 AT_BISON_CHECK([-y -o input.c input.y])
108 AT_COMPILE([input.o], [-c input.c])
114 ## ---------------------------------------- ##
115 ## Early token definitions without --yacc. ##
116 ## ---------------------------------------- ##
119 AT_SETUP([Early token definitions without --yacc])
121 # Found in GCJ: they expect the tokens to be defined before the user
122 # prologue, so that they can use the token definitions in it.
124 AT_DATA_GRAMMAR([input.y],
127 void yyerror (const char *s);
129 void print_my_token (void);
138 print_my_token (void)
140 enum yytokentype my_token = MY_TOKEN;
141 printf ("%d\n", my_token);
150 AT_BISON_CHECK([-o input.c input.y])
151 AT_COMPILE([input.o], [-c input.c])
157 ## ---------------- ##
158 ## Braces parsing. ##
159 ## ---------------- ##
162 AT_SETUP([Braces parsing])
165 [[/* Bison used to swallow the character after '}'. */
168 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
172 AT_BISON_CHECK([-v -o input.c input.y])
174 AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
179 ## ------------------ ##
180 ## Duplicate string. ##
181 ## ------------------ ##
184 AT_SETUP([Duplicate string])
187 [[/* 'Bison -v' used to dump core when two tokens are defined with the same
188 string, as LE and GE below. */
195 exp: '(' exp ')' | NUM ;
199 AT_BISON_CHECK([-v -o input.c input.y], 0, [],
200 [[input.y:6.8-14: warning: symbol '"<="' used more than once as a literal string
206 ## ------------------- ##
207 ## Rule Line Numbers. ##
208 ## ------------------- ##
210 AT_SETUP([Rule Line Numbers])
212 AT_KEYWORDS([report])
244 AT_BISON_CHECK([-o input.c -v input.y])
246 # Check the contents of the report.
247 AT_CHECK([cat input.output], [],
261 Terminals, with rules where they appear
270 Nonterminals, with rules where they appear
275 on left: 2 4, on right: 0
277 on left: 1, on right: 2
279 on left: 3, on right: 4
284 0 $accept: . expr $end
286 'a' shift, and go to state 1
288 $default reduce using rule 3 ($@2)
296 2 expr: 'a' . $@1 'b'
298 $default reduce using rule 1 ($@1)
305 0 $accept: expr . $end
307 $end shift, and go to state 5
314 'c' shift, and go to state 6
319 2 expr: 'a' $@1 . 'b'
321 'b' shift, and go to state 7
326 0 $accept: expr $end .
335 $default reduce using rule 4 (expr)
340 2 expr: 'a' $@1 'b' .
342 $default reduce using rule 2 (expr)
349 ## ---------------------- ##
350 ## Mixing %token styles. ##
351 ## ---------------------- ##
354 AT_SETUP([Mixing %token styles])
356 # Taken from the documentation.
358 [[%token <operator> OR "||"
359 %token <operator> LE 134 "<="
366 AT_BISON_CHECK([-v -o input.c input.y])
372 ## ---------------- ##
373 ## Invalid inputs. ##
374 ## ---------------- ##
377 AT_SETUP([Invalid inputs])
389 AT_BISON_CHECK([input.y], [1], [],
390 [[input.y:2.1: invalid character: '?'
391 input.y:3.14: invalid character: '}'
392 input.y:4.1: invalid character: '%'
393 input.y:4.2: invalid character: '&'
394 input.y:5.1-17: invalid directive: '%a-does-not-exist'
395 input.y:6.1: invalid character: '%'
396 input.y:6.2: invalid character: '-'
397 input.y:7.1-8.0: missing '%}' at end of file
398 input.y:7.1-8.0: syntax error, unexpected %{...%}
404 AT_SETUP([Invalid inputs with {}])
416 AT_BISON_CHECK([input.y], [1], [],
417 [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
424 ## ------------------- ##
425 ## Token definitions. ##
426 ## ------------------- ##
429 AT_SETUP([Token definitions])
431 # Bison managed, when fed with '%token 'f' "f"' to #define 'f'!
432 AT_DATA_GRAMMAR([input.y],
436 void yyerror (const char *s);
440 %token MYEOF 0 "end of file"
445 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
446 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
448 exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
451 yyerror (char const *s)
453 fprintf (stderr, "%s\n", s);
472 # Checking the warning message guarantees that the trigraph "??!" isn't
473 # unnecessarily escaped here even though it would need to be if encoded in a
474 # C-string literal. Also notice that unnecessary escaping, such as "\?", from
475 # the user specification is eliminated.
476 AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
477 [[input.y:22.8-14: warning: symbol SPECIAL redeclared
478 input.y:22.8-63: warning: symbol '"\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!"' used more than once as a literal string
482 # Checking the error message here guarantees that yytname, which does contain
483 # C-string literals, does have the trigraph escaped correctly. Thus, the
484 # symbol name reported by the parser is exactly the same as that reported by
487 [[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a
489 AT_PARSER_CHECK([./input], 1, [], [experr])
494 ## -------------------- ##
495 ## Characters Escapes. ##
496 ## -------------------- ##
499 AT_SETUP([Characters Escapes])
501 AT_DATA_GRAMMAR([input.y],
503 void yyerror (const char *s);
513 # Pacify font-lock-mode: "
515 AT_BISON_CHECK([-o input.c input.y])
516 AT_COMPILE([input.o], [-c input.c])
525 # The generation of the reduction was once wrong in Bison, and made it
526 # miss some reductions. In the following test case, the reduction on
527 # 'undef_id_tok' in state 1 was missing. This is stripped down from
528 # the actual web2c.y.
530 AT_SETUP([Web2c Report])
532 AT_KEYWORDS([report])
535 [[%token undef_id_tok const_id_tok
537 %start CONST_DEC_PART
546 | CONST_DEC_LIST CONST_DEC
550 { } undef_id_tok '=' const_id_tok ';'
555 AT_BISON_CHECK([-v input.y])
556 AT_CHECK([cat input.output], 0,
559 0 $accept: CONST_DEC_PART $end
561 1 CONST_DEC_PART: CONST_DEC_LIST
563 2 CONST_DEC_LIST: CONST_DEC
564 3 | CONST_DEC_LIST CONST_DEC
568 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';'
571 Terminals, with rules where they appear
581 Nonterminals, with rules where they appear
586 on left: 1, on right: 0
588 on left: 2 3, on right: 1 3
590 on left: 5, on right: 2 3
592 on left: 4, on right: 5
597 0 $accept: . CONST_DEC_PART $end
599 $default reduce using rule 4 ($@1)
601 CONST_DEC_PART go to state 1
602 CONST_DEC_LIST go to state 2
603 CONST_DEC go to state 3
609 0 $accept: CONST_DEC_PART . $end
611 $end shift, and go to state 5
616 1 CONST_DEC_PART: CONST_DEC_LIST .
617 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
619 undef_id_tok reduce using rule 4 ($@1)
620 $default reduce using rule 1 (CONST_DEC_PART)
622 CONST_DEC go to state 6
628 2 CONST_DEC_LIST: CONST_DEC .
630 $default reduce using rule 2 (CONST_DEC_LIST)
635 5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';'
637 undef_id_tok shift, and go to state 7
642 0 $accept: CONST_DEC_PART $end .
649 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
651 $default reduce using rule 3 (CONST_DEC_LIST)
656 5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';'
658 '=' shift, and go to state 8
663 5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';'
665 const_id_tok shift, and go to state 9
670 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';'
672 ';' shift, and go to state 10
677 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' .
679 $default reduce using rule 5 (CONST_DEC)
685 ## --------------- ##
687 ## --------------- ##
689 # The generation of the mapping 'state -> action' was once wrong in
690 # extremely specific situations. web2c.y exhibits this situation.
691 # Below is a stripped version of the grammar. It looks like one can
692 # simplify it further, but just don't: it is tuned to exhibit a bug,
693 # which disapears when applying sane grammar transformations.
695 # It used to be wrong on yydefact only:
697 # static const yytype_uint8 yydefact[] =
699 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
700 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
704 # but let's check all the tables.
707 AT_SETUP([Web2c Actions])
709 AT_KEYWORDS([report])
713 statement: struct_stat;
714 struct_stat: /* empty. */ | if else;
715 if: "if" "const" "then" statement;
716 else: "else" statement;
720 AT_BISON_CHECK([-v -o input.c input.y])
722 # Check only the tables.
723 [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
725 AT_CHECK([[cat tables.c]], 0,
726 [[static const yytype_uint8 yytranslate[] =
728 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
729 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
730 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
731 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
732 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
733 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
734 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
735 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
736 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
737 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
738 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
739 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
740 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
741 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
742 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
743 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
744 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
745 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
746 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
747 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
748 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
749 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
750 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
751 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
752 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
753 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
756 static const yytype_uint8 yyrline[] =
760 static const char *const yytname[] =
762 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
763 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
765 static const yytype_uint16 yytoknum[] =
767 0, 256, 257, 258, 259, 260, 261
769 static const yytype_int8 yypact[] =
771 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
774 static const yytype_uint8 yydefact[] =
776 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
779 static const yytype_int8 yypgoto[] =
783 static const yytype_int8 yydefgoto[] =
787 static const yytype_uint8 yytable[] =
789 10, 1, 11, 5, 6, 0, 7, 9
791 static const yytype_int8 yycheck[] =
793 7, 3, 9, 4, 0, -1, 6, 5
795 static const yytype_uint8 yystos[] =
797 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
800 static const yytype_uint8 yyr1[] =
802 0, 7, 8, 9, 9, 10, 11
804 static const yytype_uint8 yyr2[] =
813 ## ------------------------- ##
814 ## yycheck Bound Violation. ##
815 ## ------------------------- ##
818 # _AT_DATA_DANCER_Y(BISON-OPTIONS)
819 # --------------------------------
820 # The following grammar, taken from Andrew Suffield's GPL'd implementation
821 # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
822 # yycheck's bounds where issuing a verbose error message. Keep this test
823 # so that possible bound checking compilers could check all the skeletons.
824 m4_define([_AT_DATA_DANCER_Y],
825 [AT_DATA_GRAMMAR([dancer.y],
827 static int yylex (AT_LALR1_CC_IF([int *], [void]));
828 AT_LALR1_CC_IF([#include <cstdlib>],
831 static void yyerror (const char *);])
834 %token ARROW INVALID NUMBER STRING DATA
838 /* Grammar follows */
843 header: '<' from ARROW to '>' type ':'
844 | '<' ARROW to '>' type ':'
878 [/* A C++ error reporting function. */
880 yy::parser::error (const std::string& m)
882 std::cerr << m << std::endl;
890 parser.set_debug_level (YYDEBUG);
892 return parser.parse ();
896 yyerror (const char *s)
898 fprintf (stderr, "%s\n", s);
902 yylex (AT_LALR1_CC_IF([int *lval], [void]))
904 static int const tokens[] =
908 static size_t toknum;
909 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
910 if (! (toknum < sizeof tokens / sizeof *tokens))
912 return tokens[toknum++];
921 ])# _AT_DATA_DANCER_Y
924 # AT_CHECK_DANCER(BISON-OPTIONS)
925 # ------------------------------
926 # Generate the grammar, compile it, run it.
927 m4_define([AT_CHECK_DANCER],
928 [AT_SETUP([Dancer $1])
929 AT_BISON_OPTION_PUSHDEFS([$1])
930 _AT_DATA_DANCER_Y([$1])
931 AT_BISON_CHECK([-o dancer.c dancer.y])
932 AT_FULL_COMPILE([dancer])
933 AT_PARSER_CHECK([./dancer], 1, [],
934 [syntax error, unexpected ':'
936 AT_BISON_OPTION_POPDEFS
941 AT_CHECK_DANCER([%glr-parser])
942 AT_CHECK_DANCER([%skeleton "lalr1.cc"])
945 ## ------------------------------------------ ##
946 ## Diagnostic that expects two alternatives. ##
947 ## ------------------------------------------ ##
950 # _AT_DATA_EXPECT2_Y(BISON-OPTIONS)
951 # --------------------------------
952 m4_define([_AT_DATA_EXPECT2_Y],
953 [AT_DATA_GRAMMAR([expect2.y],
955 static int yylex (AT_LALR1_CC_IF([int *], [void]));
956 AT_LALR1_CC_IF([#include <cstdlib>],
959 static void yyerror (const char *);])
977 [/* A C++ error reporting function. */
979 yy::parser::error (const std::string& m)
981 std::cerr << m << std::endl;
988 return parser.parse ();
992 yyerror (const char *s)
994 fprintf (stderr, "%s\n", s);
998 yylex (AT_LALR1_CC_IF([int *lval], [void]))
1000 static int const tokens[] =
1004 static size_t toknum;
1005 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
1006 if (! (toknum < sizeof tokens / sizeof *tokens))
1008 return tokens[toknum++];
1017 ])# _AT_DATA_EXPECT2_Y
1020 # AT_CHECK_EXPECT2(BISON-OPTIONS)
1021 # ------------------------------
1022 # Generate the grammar, compile it, run it.
1023 m4_define([AT_CHECK_EXPECT2],
1024 [AT_SETUP([Expecting two tokens $1])
1025 AT_BISON_OPTION_PUSHDEFS([$1])
1026 _AT_DATA_EXPECT2_Y([$1])
1027 AT_BISON_CHECK([-o expect2.c expect2.y])
1028 AT_FULL_COMPILE([expect2])
1029 AT_PARSER_CHECK([./expect2], 1, [],
1030 [syntax error, unexpected '+', expecting A or B
1032 AT_BISON_OPTION_POPDEFS
1037 AT_CHECK_EXPECT2([%glr-parser])
1038 AT_CHECK_EXPECT2([%skeleton "lalr1.cc"])
1042 ## --------------------------------------------- ##
1043 ## Braced code in declaration in rules section. ##
1044 ## --------------------------------------------- ##
1046 AT_SETUP([Braced code in declaration in rules section])
1048 # Bison once mistook braced code in a declaration in the rules section to be a
1051 AT_DATA_GRAMMAR([input.y],
1054 static void yyerror (char const *msg);
1055 static int yylex (void);
1064 printf ("Bison would once convert this action to a midrule because of the"
1065 " subsequent braced code.\n");
1069 %destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
1070 %printer { fprintf (yyoutput, "PRINTER"); } 'a';
1075 yyerror (char const *msg)
1077 fprintf (stderr, "%s\n", msg);
1094 AT_BISON_CHECK([-t -o input.c input.y])
1096 AT_PARSER_CHECK([./input], 0,
1097 [[Bison would once convert this action to a midrule because of the subsequent braced code.
1101 Reducing stack by rule 1 (line 20):
1102 -> $$ = nterm start ()
1105 Reading a token: Next token is token 'a' (PRINTER)
1106 syntax error, unexpected 'a', expecting $end
1107 Error: popping nterm start ()
1109 Cleanup: discarding lookahead token 'a' (PRINTER)
1118 ## --------------------------------- ##
1119 ## String alias declared after use. ##
1120 ## --------------------------------- ##
1122 AT_SETUP([String alias declared after use])
1124 # Bison once incorrectly asserted that the symbol number for either a token or
1125 # its alias was the highest symbol number so far at the point of the alias
1126 # declaration. That was true unless the declaration appeared after their first
1127 # uses and other tokens appeared in between.
1135 AT_BISON_CHECK([-t -o input.c input.y])
1141 ## -------------------------------- ##
1142 ## Extra lookahead sets in report. ##
1143 ## -------------------------------- ##
1145 AT_SETUP([[Extra lookahead sets in report]])
1147 # Bison prints each reduction's lookahead set only next to the associated
1148 # state's one item that (1) is associated with the same rule as the reduction
1149 # and (2) has its dot at the end of its RHS. Previously, Bison also
1150 # erroneously printed the lookahead set next to all of the state's other items
1151 # associated with the same rule. This bug affected only the '.output' file and
1152 # not the generated parser source code.
1154 AT_DATA([[input.y]],
1156 start: a | 'a' a 'a' ;
1160 AT_BISON_CHECK([[--report=all input.y]])
1161 AT_CHECK([[sed -n '/^state 1$/,/^state 2$/p' input.output]], [[0]],
1164 2 start: 'a' . a 'a'
1168 'a' shift, and go to state 4
1170 $default reduce using rule 3 (a)
1182 ## ---------------------------------------- ##
1183 ## Token number in precedence declaration. ##
1184 ## ---------------------------------------- ##
1186 AT_SETUP([[Token number in precedence declaration]])
1188 # POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
1189 # we lost this in Bison 1.50.
1191 AT_DATA_GRAMMAR([input.y],
1194 void yyerror (char const *);
1200 %left TK1 1 TK2 2 "tok alias" 3
1205 TK1 sr_conflict "tok alias"
1216 yyerror (char const *msg)
1218 fprintf (stderr, "%s\n", msg);
1224 static int const input[] = { 1, 2, 3, 0 };
1225 static int const *inputp = input;
1236 AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
1237 [[input.y:23.5-19: warning: rule useless in parser due to conflicts: start: start
1238 input.y:27.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias"
1240 AT_COMPILE([[input]])
1241 AT_PARSER_CHECK([[./input]])
1247 ## --------------------------- ##
1248 ## parse-gram.y: LALR = IELR. ##
1249 ## --------------------------- ##
1251 # If parse-gram.y's LALR and IELR parser tables ever begin to differ, we
1252 # need to fix parse-gram.y or start using IELR.
1254 AT_SETUP([[parse-gram.y: LALR = IELR]])
1256 # Avoid tests/bison's dark magic by processing a local copy of the
1257 # grammar. Avoid differences in synclines by telling bison that the
1258 # output files have the same name.
1259 [cp $abs_top_srcdir/src/parse-gram.y input.y]
1260 AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]])
1262 AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]])
1264 AT_CHECK([[cat ielr.c]], [[0]], [[expout]])
1270 ## -------------------------------------------- ##
1271 ## parse.error=verbose and YYSTACK_USE_ALLOCA. ##
1272 ## -------------------------------------------- ##
1274 AT_SETUP([[parse.error=verbose and YYSTACK_USE_ALLOCA]])
1276 AT_DATA_GRAMMAR([input.y],
1279 void yyerror (char const *);
1281 #define YYSTACK_USE_ALLOCA 1
1284 %define parse.error verbose
1288 start: check syntax_error syntax_error ;
1292 if (128 < sizeof yymsgbuf)
1295 "The initial size of yymsgbuf in yyparse has increased\n"
1296 "since this test group was last updated. As a result,\n"
1297 "this test group may no longer manage to induce a\n"
1298 "reallocation of the syntax error message buffer.\n"
1299 "This test group must be adjusted to produce a longer\n"
1300 "error message.\n");
1306 // Induce a syntax error message whose total length is more than
1307 // sizeof yymsgbuf in yyparse. Each token here is 64 bytes.
1309 "123456789112345678921234567893123456789412345678951234567896123A"
1310 | "123456789112345678921234567893123456789412345678951234567896123B"
1317 yyerror (char const *msg)
1319 fprintf (stderr, "%s\n", msg);
1325 /* Induce two syntax error messages (which requires full error
1326 recovery by shifting 3 tokens) in order to detect any loss of the
1327 reallocated buffer. */
1328 static char const *input = "abc";
1339 AT_BISON_CHECK([[-o input.c input.y]])
1340 AT_COMPILE([[input]])
1341 AT_PARSER_CHECK([[./input]], [[1]], [],
1342 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1343 syntax error, unexpected $end, expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1350 ## ------------------------------ ##
1351 ## parse.error=verbose overflow. ##
1352 ## ------------------------------ ##
1354 # Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an
1355 # invocation of yysyntax_error has caused yymsg_alloc to grow to exactly
1356 # YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had
1357 # to be clipped to YYSTACK_ALLOC_MAXIMUM). In an old version of yacc.c,
1358 # a subsequent invocation of yysyntax_error that overflows during its
1359 # size calculation would return YYSIZE_MAXIMUM to yyparse. Then,
1360 # yyparse would invoke yyerror using the old contents of yymsg.
1362 AT_SETUP([[parse.error=verbose overflow]])
1364 AT_DATA_GRAMMAR([input.y],
1367 void yyerror (char const *);
1370 /* This prevents this test case from having to induce error messages
1371 large enough to overflow size_t. */
1372 #define YYSIZE_T unsigned char
1374 /* Bring in malloc and set EXIT_SUCCESS so yacc.c doesn't try to
1375 provide a malloc prototype using our YYSIZE_T. */
1377 #ifndef EXIT_SUCCESS
1378 # define EXIT_SUCCESS 0
1381 /* Max depth is usually much smaller than YYSTACK_ALLOC_MAXIMUM, and
1382 we don't want gcc to warn everywhere this constant would be too big
1383 to make sense for our YYSIZE_T. */
1384 #define YYMAXDEPTH 100
1387 %define parse.error verbose
1391 start: syntax_error1 check syntax_error2 ;
1393 // Induce a syntax error message whose total length causes yymsg in
1394 // yyparse to be reallocated to size YYSTACK_ALLOC_MAXIMUM, which
1395 // should be 255. Each token here is 64 bytes.
1397 "123456789112345678921234567893123456789412345678951234567896123A"
1398 | "123456789112345678921234567893123456789412345678951234567896123B"
1399 | "123456789112345678921234567893123456789412345678951234567896123C"
1405 if (yymsg_alloc != YYSTACK_ALLOC_MAXIMUM
1406 || YYSTACK_ALLOC_MAXIMUM != YYSIZE_MAXIMUM
1407 || YYSIZE_MAXIMUM != 255)
1410 "The assumptions of this test group are no longer\n"
1411 "valid, so it may no longer catch the error it was\n"
1412 "designed to catch. Specifically, the following\n"
1413 "values should all be 255:\n\n");
1414 fprintf (stderr, " yymsg_alloc = %d\n", yymsg_alloc);
1415 fprintf (stderr, " YYSTACK_ALLOC_MAXIMUM = %d\n",
1416 YYSTACK_ALLOC_MAXIMUM);
1417 fprintf (stderr, " YYSIZE_MAXIMUM = %d\n", YYSIZE_MAXIMUM);
1425 "123456789112345678921234567893123456789412345678951234567896123A"
1426 | "123456789112345678921234567893123456789412345678951234567896123B"
1427 | "123456789112345678921234567893123456789412345678951234567896123C"
1428 | "123456789112345678921234567893123456789412345678951234567896123D"
1429 | "123456789112345678921234567893123456789412345678951234567896123E"
1435 yyerror (char const *msg)
1437 fprintf (stderr, "%s\n", msg);
1443 /* Induce two syntax error messages (which requires full error
1444 recovery by shifting 3 tokens). */
1445 static char const *input = "abc";
1452 /* Push parsers throw away the message buffer between tokens, so skip
1453 this test under maintainer-push-check. */
1460 AT_BISON_CHECK([[-o input.c input.y]])
1462 # gcc warns about tautologies and fallacies involving comparisons for
1463 # unsigned char. However, it doesn't produce these same warnings for
1464 # size_t and many other types when the warnings would seem to make just
1465 # as much sense. We ignore the warnings.
1466 [CFLAGS="$NO_WERROR_CFLAGS"]
1467 AT_COMPILE([[input]])
1469 AT_PARSER_CHECK([[./input]], [[2]], [],
1470 [[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B or 123456789112345678921234567893123456789412345678951234567896123C
1479 ## ------------------------ ##
1480 ## LAC: Exploratory stack. ##
1481 ## ------------------------ ##
1483 AT_SETUP([[LAC: Exploratory stack]])
1485 m4_pushdef([AT_LAC_CHECK], [
1487 AT_BISON_OPTION_PUSHDEFS([$1])
1489 AT_DATA_GRAMMAR([input.y],
1492 void yyerror (char const *);
1493 int yylex (]AT_PURE_IF([[YYSTYPE *]], [[void]])[);
1497 %define parse.error verbose
1502 // default reductions in inconsistent states
1503 // v v v v v v v v v v v v v v
1504 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 ;
1508 A: 'a' | /*empty*/ { printf ("inconsistent default reduction\n"); } ;
1510 C: /*empty*/ { printf ("consistent default reduction\n"); } ;
1515 yyerror (char const *msg)
1517 fprintf (stderr, "%s\n", msg);
1521 yylex (]AT_PURE_IF([[YYSTYPE *v]], [[void]])[)
1523 static char const *input = "bbbbc";]AT_PURE_IF([[
1536 AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
1537 -Dparse.lac.memory-trace=full \
1538 -t -o input.c input.y]], [[0]], [],
1539 [[input.y: conflicts: 21 shift/reduce
1541 AT_COMPILE([[input]])
1542 AT_PARSER_CHECK([[./input > stdout.txt 2> stderr.txt]], [[1]])
1544 # Make sure syntax error doesn't forget that 'a' is expected. It would
1545 # be forgotten without lookahead correction.
1546 AT_CHECK([[grep 'syntax error,' stderr.txt]], [[0]],
1547 [[syntax error, unexpected 'c', expecting 'a' or 'b'
1550 # Check number of default reductions in inconsistent states to be sure
1551 # syntax error is detected before unnecessary reductions are performed.
1552 AT_CHECK([[perl -0777 -ne 'print s/inconsistent default reduction//g;' \
1553 < stdout.txt || exit 77]], [[0]], [[14]])
1555 # Check number of default reductions in consistent states to be sure
1556 # it is performed before the syntax error is detected.
1557 AT_CHECK([[perl -0777 -ne 'print s/\bconsistent default reduction//g;' \
1558 < stdout.txt || exit 77]], [[0]], [[2]])
1560 # Check number of reallocs to be sure reallocated memory isn't somehow
1561 # lost between LAC invocations.
1562 AT_CHECK([[perl -0777 -ne 'print s/\(realloc//g;' < stderr.txt \
1563 || exit 77]], [[0]], [[3]])
1565 AT_BISON_OPTION_POPDEFS
1568 AT_LAC_CHECK([[%define api.push-pull pull]])
1569 AT_LAC_CHECK([[%define api.push-pull pull %define api.pure]])
1570 AT_LAC_CHECK([[%define api.push-pull both]])
1571 AT_LAC_CHECK([[%define api.push-pull both %define api.pure]])
1573 m4_popdef([AT_LAC_CHECK])
1579 ## ------------------------ ##
1580 ## LAC: Memory exhaustion. ##
1581 ## ------------------------ ##
1583 AT_SETUP([[LAC: Memory exhaustion]])
1585 m4_pushdef([AT_LAC_CHECK], [
1587 AT_DATA_GRAMMAR([input.y],
1590 void yyerror (char const *);
1592 #define YYMAXDEPTH 8
1599 S: A A A A A A A A A ;
1600 A: /*empty*/ | 'a' ;
1605 yyerror (char const *msg)
1607 fprintf (stderr, "%s\n", msg);
1613 static char const *input = "]$1[";
1625 AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
1626 -t -o input.c input.y]], [[0]], [],
1627 [[input.y: conflicts: 8 shift/reduce
1629 AT_COMPILE([[input]])
1633 # Check for memory exhaustion during parsing.
1635 AT_PARSER_CHECK([[./input]], [[2]], [[]],
1638 Reading a token: Now at end of input.
1639 LAC: initial context established for $end
1640 LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
1642 Cleanup: discarding lookahead token $end ()
1646 # Induce an immediate syntax error with an undefined token, and check
1647 # for memory exhaustion while building syntax error message.
1648 AT_LAC_CHECK([[z]], [[0]])
1649 AT_PARSER_CHECK([[./input]], [[2]], [[]],
1652 Reading a token: Next token is token $undefined ()
1653 LAC: initial context established for $undefined
1654 LAC: checking lookahead $undefined: Always Err
1655 Constructing syntax error message
1656 LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
1659 Cleanup: discarding lookahead token $undefined ()
1663 m4_popdef([AT_LAC_CHECK])