1 # Checking the Bison reader. -*- Autotest -*-
3 # Copyright (C) 2002-2015, 2018-2020 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([[Input Processing.]])
20 # Mostly test that we are robust to mistakes.
23 ## ----------------------------- ##
24 ## Invalid number of arguments. ##
25 ## ----------------------------- ##
27 AT_SETUP([Invalid number of arguments])
29 AT_BISON_CHECK([], [1], [],
30 [[bison: missing operand
31 Try 'bison --help' for more information.
34 AT_BISON_CHECK([1.y 2.y], [1], [],
35 [[bison: extra operand '2.y'
36 Try 'bison --help' for more information.
39 # For some reason, on some systems we use the system's getopt, not the
40 # one we ship in gnulib. So we can get two different error messages.
41 # See https://lists.gnu.org/archive/html/bison-patches/2018-10/msg00154.html
42 AT_BISON_CHECK([--skeleton], [1], [], [stderr])
44 "s/requires an argument -- skeleton/'--skeleton' requires an argument/" \
46 [[bison: option '--skeleton' requires an argument
47 Try 'bison --help' for more information.
54 ## ----------------- ##
55 ## Invalid options. ##
56 ## ----------------- ##
58 AT_SETUP([Invalid options])
65 # We used to accept these, as -f, --report and others were sharing
67 AT_BISON_CHECK([-ferror=caret input.y], [1], [], [ignore])
68 AT_BISON_CHECK([--report=error=itemsets input.y], [1], [], [ignore])
70 # We used to accept any character after "-Werror", instead of ensuring
72 AT_BISON_CHECK([-Werror?all input.y], [1], [], [ignore])
77 ## ---------------- ##
79 ## ---------------- ##
81 # The truly bad guys no human would write, but easily uncovered by
83 AT_SETUP([Invalid inputs])
96 AT_PERL_REQUIRE([[-pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y]])
98 AT_BISON_CHECK([-fcaret input.y], [1], [], [stderr])
100 # Autotest's diffing, when there are NUL bytes, just reports "binary
101 # files differ". So don't leave NUL bytes.
102 AT_PERL_CHECK([[-p -e 's{([\0\377])}{sprintf "\\x%02x", ord($1)}ge' stderr]], [],
103 [[input.y:1.1-2: error: invalid characters: '\0\001\002\377?'
104 1 | \x00
\x01\x02\xff?
106 input.y:2.2: error: invalid null character
109 input.y:4.1: error: invalid character: '?'
112 input.y:5.14: error: invalid character: '}'
115 input.y:6.1: error: invalid character: '%'
118 input.y:6.2: error: invalid character: '&'
121 input.y:7.1-17: error: invalid directive: '%a-does-not-exist'
122 7 | %a-does-not-exist
124 input.y:8.1: error: invalid character: '%'
127 input.y:8.2: error: invalid character: '-'
130 input.y:9.1-10.0: error: missing '%}' at end of file
138 AT_SETUP([Invalid inputs with {}])
140 # We used to SEGV here. See
141 # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
153 AT_BISON_CHECK([input.y], [1], [],
154 [[input.y:3.1-15: error: expected {...} before %initial-action
160 ## -------------------------- ##
161 ## Yacc warnings on symbols. ##
162 ## -------------------------- ##
164 AT_SETUP([Yacc warnings on symbols])
168 %token NUM 0x40 "number"
173 AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
174 [[input.y:1.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
177 input.y:2.12-15: warning: POSIX Yacc does not support hexadecimal literals [-Wyacc]
178 2 | %token NUM 0x40 "number"
180 input.y:2.17-24: warning: POSIX Yacc does not support string literals [-Wyacc]
181 2 | %token NUM 0x40 "number"
183 input.y:4.6-13: warning: POSIX Yacc does not support string literals [-Wyacc]
191 ## --------------- ##
193 ## --------------- ##
195 AT_SETUP([Yacc warnings])
198 [[%destructor {} <int>
202 exp: a b { $$ = $1 + $2; };
203 a: <int>{ $$ = 42; } { $$ = $1; };
204 b: %empty { $$ = 42; };
207 AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
208 [[input.y:1.1-11: warning: POSIX Yacc does not support %destructor [-Wyacc]
209 1 | %destructor {} <int>
211 input.y:2.1-8: warning: POSIX Yacc does not support %printer [-Wyacc]
212 2 | %printer {} <int>
214 input.y:6.9-20: warning: POSIX Yacc does not support typed midrule actions [-Wyacc]
215 6 | a: <int>{ $$ = 42; } { $$ = $1; };
217 input.y:7.4-9: warning: POSIX Yacc does not support %empty [-Wyacc]
218 7 | b: %empty { $$ = 42; };
229 AT_SETUP([Yacc's %type])
234 %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
238 expr: nterm1 nterm2 nterm3
244 AT_BISON_CHECK([-fcaret -Wyacc input.y], [0], [],
245 [[input.y:2.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
248 input.y:3.14-19: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
249 3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
251 input.y:3.28-35: warning: POSIX Yacc does not support string literals [-Wyacc]
252 3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
254 input.y:3.28-35: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
255 3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
257 input.y:3.58-60: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
258 3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
260 input.y:5.1-6: warning: POSIX Yacc does not support %nterm [-Wyacc]
263 input.y:3.21-26: warning: POSIX yacc reserves %type to nonterminals [-Wyacc]
264 3 | %type <ival> TOKEN1 TOKEN2 "TOKEN3" nterm1 nterm2 nterm3 '+'
266 input.y:10.9-16: warning: POSIX Yacc does not support string literals [-Wyacc]
267 10 | nterm3: "TOKEN3"
274 ## ----------------------------- ##
275 ## Invalid symbol declarations. ##
276 ## ----------------------------- ##
278 AT_SETUP([Invalid symbol declarations])
281 [[%nterm expr "expression";
283 %nterm fact 124 "factor";
290 expr: expr '+' term | term;
291 term: term '*' fact | fact;
295 AT_BISON_CHECK([-fcaret input.y], [1], [],
296 [[input.y:1.13-24: error: nonterminals cannot be given a string alias
297 1 | %nterm expr "expression";
299 input.y:2.13-15: error: nonterminals cannot be given a token code
302 input.y:3.13-15: error: nonterminals cannot be given a token code
303 3 | %nterm fact 124 "factor";
305 input.y:3.17-24: error: nonterminals cannot be given a string alias
306 3 | %nterm fact 124 "factor";
308 input.y:4.8-10: error: character literals cannot be nonterminals
311 input.y:5.8-15: error: expected character literal or identifier or <tag> before string
314 input.y:6.8-13: error: expected character literal or identifier or <tag> before string
317 input.y:7.14: error: unexpected integer literal
320 input.y:8.14: error: unexpected integer literal
328 ## ---------------------------- ##
329 ## Redefining the error token. ##
330 ## ---------------------------- ##
332 AT_SETUP([Redefining the error token])
334 # We used to crash when trying to display the original definition of
335 # "error", which is a builtin without any location.
336 AT_BISON_OPTION_PUSHDEFS
345 AT_BISON_CHECK([-fcaret input.y], [1], [],
346 [[input.y:2.8-12: warning: symbol error redeclared [-Wother]
349 input.y:1.8-12: note: previous declaration
352 input.y:2.14-16: error: redefining code of token error
357 # While at it, make sure we properly used the user's number for
358 # "error". I don't see what it buys us, but...
373 assert (YYerror == 123);
374 assert (YYTRANSLATE (YYEOF) == YYSYMBOL_YYEOF);
375 assert (YYTRANSLATE (YYerror) == YYSYMBOL_YYerror);
376 assert (YYTRANSLATE (YYUNDEF) == YYSYMBOL_YYUNDEF);
381 AT_FULL_COMPILE([input])
382 AT_PARSER_CHECK([input], 0)
384 AT_BISON_OPTION_POPDEFS
388 ## ------------------ ##
389 ## Dangling aliases. ##
390 ## ------------------ ##
392 AT_SETUP([Dangling aliases])
398 expr: "foo" "bar" "baz"
401 AT_BISON_CHECK([-fcaret -Wdangling input.y], [0], [],
402 [[input.y:2.13-17: warning: string literal "bar" not attached to a symbol [-Wdangling-alias]
403 2 | %type <val> "bar"
405 input.y:4.19-23: warning: string literal "baz" not attached to a symbol [-Wdangling-alias]
406 4 | expr: "foo" "bar" "baz"
413 ## --------------------- ##
414 ## Symbol declarations. ##
415 ## --------------------- ##
417 # Check the parsing of %token, %nterm, %type and %left...
418 AT_SETUP([Symbol declarations])
420 AT_DATA([dump-symbols.m4],
421 [[m4@&t@_define([b4_api_PREFIX], [YY])
423 m4@&t@_define([b4_symbol_dump],
425 b4_symbol_if([$1], [is_token], [Token], [Nonterminal]), d@&t@nl
426 b4_symbol([$1], [tag]), d@&t@nl
427 b4_symbol([$1], [id]), d@&t@nl
428 b4_symbol([$1], [code]), d@&t@nl
429 b4_symbol([$1], [type]),
432 b4_output_begin([symbols.csv])
433 number, class, tag, id, code, type,
434 b4_symbol_foreach([b4_symbol_dump])d@&t@nl
439 [[%token 'a' A1 1 "A1" A2 A3 "A3" A4 4
440 <type_b> 'b' B5 5 "B5" B6 B7 "B8" B9 9
441 <type_c> 'c' C10 10 "C10" C11 C12 "C12" C13 13
443 %left 'd' D20 20 "D20" D21 D22 "D22" D23 23
444 <type_e> 'e' E25 25 "E25" E26 E27 "E28" E29 29
445 <type_f> 'f' F30 30 "F30" F31 F32 "F32" F33 33
447 %type 'g' G40 "D40" G21 G22 G23
448 <type_h> 'h' H25 "H25" H26 H27 "H28" H29
449 <type_i> 'i' I30 "I30" I31 I32 "I32" I33
451 %nterm j60 j61 j62 j63
452 <type_k> k75 k76 k77 k79
453 <type_l> l80 l81 l82 l83
458 AT_BISON_CHECK([-Wno-other -S./dump-symbols.m4 input.y])
459 AT_CHECK([cat symbols.csv], [],
460 [[number, class, tag, id, code, type,
461 0, Token, "end of file", YYEOF, 0, ,
462 1, Token, error, YYerror, 256, ,
463 2, Token, "invalid token", YYUNDEF, 257, ,
464 3, Token, 'a', , 97, ,
465 4, Token, "A1", A1, 1, ,
466 5, Token, A2, A2, 258, ,
467 6, Token, "A3", A3, 259, ,
468 7, Token, A4, A4, 4, ,
469 8, Token, 'b', , 98, type_b,
470 9, Token, "B5", B5, 5, type_b,
471 10, Token, B6, B6, 260, type_b,
472 11, Token, "B8", B7, 261, type_b,
473 12, Token, B9, B9, 9, type_b,
474 13, Token, 'c', , 99, type_c,
475 14, Token, "C10", C10, 10, type_c,
476 15, Token, C11, C11, 262, type_c,
477 16, Token, "C12", C12, 263, type_c,
478 17, Token, C13, C13, 13, type_c,
479 18, Token, 'd', , 100, ,
480 19, Token, D20, D20, 20, ,
481 20, Token, "D20", , 264, ,
482 21, Token, D21, D21, 265, ,
483 22, Token, D22, D22, 266, ,
484 23, Token, "D22", , 267, ,
485 24, Token, D23, D23, 23, ,
486 25, Token, 'e', , 101, type_e,
487 26, Token, E25, E25, 25, type_e,
488 27, Token, "E25", , 268, type_e,
489 28, Token, E26, E26, 269, type_e,
490 29, Token, E27, E27, 270, type_e,
491 30, Token, "E28", , 271, type_e,
492 31, Token, E29, E29, 29, type_e,
493 32, Token, 'f', , 102, type_f,
494 33, Token, F30, F30, 30, type_f,
495 34, Token, "F30", , 272, type_f,
496 35, Token, F31, F31, 273, type_f,
497 36, Token, F32, F32, 274, type_f,
498 37, Token, "F32", , 275, type_f,
499 38, Token, F33, F33, 33, type_f,
500 39, Token, 'g', , 103, ,
501 40, Token, "D40", , 276, ,
502 41, Token, 'h', , 104, type_h,
503 42, Token, "H25", , 277, type_h,
504 43, Token, "H28", , 278, type_h,
505 44, Token, 'i', , 105, type_i,
506 45, Token, "I30", , 279, type_i,
507 46, Token, "I32", , 280, type_i,
508 47, Nonterminal, $accept, , -1, ,
509 48, Nonterminal, exp, exp, -1, ,
519 AT_SETUP([Invalid $n and @n])
523 exp: %empty { $$ = $1 ; };
524 exp: %empty { @$ = @1 ; };
527 AT_BISON_CHECK([-fcaret input.y], [1], [],
528 [[input.y:2.20-21: error: integer out of range: '$1'
529 2 | exp: %empty { $$ = $1 ; };
531 input.y:3.20-21: error: integer out of range: '@1'
532 3 | exp: %empty { @$ = @1 ; };
543 AT_SETUP([Type Clashes])
546 [[%union { int bar; }
550 exp: foo { $$; } foo { $2; } foo
556 AT_BISON_CHECK([-fcaret input.y], [1], [],
557 [[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type
558 5 | exp: foo { $$; } foo { $2; } foo
560 input.y:5.24-25: error: $2 of 'exp' has no declared type
561 5 | exp: foo { $$; } foo { $2; } foo
563 input.y:5.6-32: warning: type clash on default action: <bar> != <> [-Wother]
564 5 | exp: foo { $$; } foo { $2; } foo
565 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~
566 input.y:6.6-8: warning: type clash on default action: <bar> != <> [-Wother]
569 input.y:7.6-11: warning: empty rule for typed nonterminal, and no action [-Wother]
577 # _AT_UNUSED_VALUES_DECLARATIONS()
578 # --------------------------------
579 # Generate the token, type, and destructor
580 # declarations for the unused values tests.
581 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
582 [[[%token <integer> INT;
583 %type <integer> a b c d e f g h i j k l m n o;
584 %destructor { destroy ($$); } <integer>;]]])
587 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
588 # ----------------------------------------------------------------
589 # Generate a grammar to test unused values, and compile it. If
590 # DECLARATIONS_AFTER is set, then the token, type, and destructor
591 # declarations are generated after the rules rather than before. If
592 # CHECK_MIDRULE_VALUES is set, then --warnings=midrule-values is set.
593 m4_define([AT_CHECK_UNUSED_VALUES],
598 ], [_AT_UNUSED_VALUES_DECLARATIONS
601 'a' a { $][2; } | 'b' b { $][2; } | 'c' c { $][2; } | 'd' d { $][2; }
602 | 'e' e { $][2; } | 'f' f { $][2; } | 'g' g { $][2; } | 'h' h { $][2; }
603 | 'i' i { $][2; } | 'j' j { $][2; } | 'k' k { $][2; } | 'l' l { $][2; }
604 | 'm' m { $][2; } | 'n' n { $][2; } | 'o' o { $][2; }
607 a: INT | INT { } INT { } INT { };
609 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
610 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
611 e: INT | INT { } INT { } INT { $][1; };
612 f: INT | INT { } INT { } INT { $][$ = $][1 + $][3 + $][5; };
613 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
614 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
615 i: INT | INT INT { } { $][$ = $][1 + $][2; };
616 j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
617 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
618 l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };
619 m: INT | INT <integer>{ $][$ = $][1; } INT <integer>{ $][$ = $][2 + $][3; } INT { $][$ = $][4 + $][5; };
620 n: INT | INT <integer>{ } INT <integer>{ } INT { };
621 o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
623 _AT_UNUSED_VALUES_DECLARATIONS])
626 AT_BISON_CHECK(m4_ifval([$2], [--warnings=midrule-values ])[-fcaret input.y],
628 [[input.y:12.10-32: warning: unset value: $][$ [-Wother]
629 12 | a: INT | INT { } INT { } INT { };
630 | ^~~~~~~~~~~~~~~~~~~~~~~
631 input.y:12.10-12: warning: unused value: $][1 [-Wother]
632 12 | a: INT | INT { } INT { } INT { };
634 input.y:12.18-20: warning: unused value: $][3 [-Wother]
635 12 | a: INT | INT { } INT { } INT { };
637 input.y:12.26-28: warning: unused value: $][5 [-Wother]
638 12 | a: INT | INT { } INT { } INT { };
640 input.y:13.10-15: warning: empty rule for typed nonterminal, and no action [-Wother]
641 13 | b: INT | %empty;
643 ]]m4_ifval([$2], [[[input.y:14.14-20: warning: unset value: $][$ [-Wmidrule-values]
644 14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
646 input.y:14.26-41: warning: unset value: $][$ [-Wmidrule-values]
647 14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
649 ]]])[[input.y:14.10-62: warning: unset value: $][$ [-Wother]
650 14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
651 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
652 input.y:14.22-24: warning: unused value: $][3 [-Wother]
653 14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
655 input.y:14.43-45: warning: unused value: $][5 [-Wother]
656 14 | c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
658 ]]m4_ifval([$2], [[[input.y:15.14-16: warning: unset value: $][$ [-Wmidrule-values]
659 15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
661 ]]])[[input.y:15.10-49: warning: unset value: $][$ [-Wother]
662 15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
663 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
664 input.y:15.18-20: warning: unused value: $][3 [-Wother]
665 15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
667 input.y:15.30-32: warning: unused value: $][5 [-Wother]
668 15 | d: INT | INT { } INT { $][1; } INT { $<integer>2; };
670 input.y:16.10-37: warning: unset value: $][$ [-Wother]
671 16 | e: INT | INT { } INT { } INT { $][1; };
672 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
673 input.y:16.18-20: warning: unused value: $][3 [-Wother]
674 16 | e: INT | INT { } INT { } INT { $][1; };
676 input.y:16.27-29: warning: unused value: $][5 [-Wother]
677 16 | e: INT | INT { } INT { } INT { $][1; };
679 input.y:18.10-58: warning: unset value: $][$ [-Wother]
680 18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
681 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
682 input.y:18.10-12: warning: unused value: $][1 [-Wother]
683 18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
685 ]]m4_ifval([$2], [[[input.y:18.14-29: warning: unused value: $][2 [-Wmidrule-values]
686 18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
688 ]]])[[input.y:18.31-33: warning: unused value: $][3 [-Wother]
689 18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
691 ]]m4_ifval([$2], [[[input.y:18.35-50: warning: unused value: $][4 [-Wmidrule-values]
692 18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
694 ]]])[[input.y:18.52-54: warning: unused value: $][5 [-Wother]
695 18 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
697 input.y:19.10-72: warning: unset value: $][$ [-Wother]
698 19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
699 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
700 input.y:19.10-12: warning: unused value: $][1 [-Wother]
701 19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
703 input.y:19.31-33: warning: unused value: $][3 [-Wother]
704 19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
706 ]]m4_ifval([$2], [[[input.y:19.35-64: warning: unused value: $][4 [-Wmidrule-values]
707 19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
708 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
709 ]]])[[input.y:19.66-68: warning: unused value: $][5 [-Wother]
710 19 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
712 ]]m4_ifval([$2], [[[input.y:21.18-37: warning: unused value: $][3 [-Wmidrule-values]
713 21 | j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
714 | ^~~~~~~~~~~~~~~~~~~~
715 ]]])[[input.y:22.10-68: warning: unset value: $][$ [-Wother]
716 22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
717 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
718 input.y:22.10-12: warning: unused value: $][1 [-Wother]
719 22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
721 input.y:22.14-16: warning: unused value: $][2 [-Wother]
722 22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
724 ]]m4_ifval([$2], [[[input.y:22.35-64: warning: unused value: $][4 [-Wmidrule-values]
725 22 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
726 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
727 ]]])[[input.y:25.23-25: warning: unset value: $][$ [-Wother]
728 25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
730 input.y:25.40-42: warning: unset value: $][$ [-Wother]
731 25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
733 input.y:25.10-50: warning: unset value: $][$ [-Wother]
734 25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
735 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
736 input.y:25.10-12: warning: unused value: $][1 [-Wother]
737 25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
739 input.y:25.23-25: warning: unused value: $][2 [-Wother]
740 25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
742 input.y:25.27-29: warning: unused value: $][3 [-Wother]
743 25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
745 input.y:25.40-42: warning: unused value: $][4 [-Wother]
746 25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
748 input.y:25.44-46: warning: unused value: $][5 [-Wother]
749 25 | n: INT | INT <integer>{ } INT <integer>{ } INT { };
751 input.y:26.23-25: warning: unset value: $][$ [-Wother]
752 26 | o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
754 input.y:26.40-42: warning: unset value: $][$ [-Wother]
755 26 | o: INT | INT <integer>{ } INT <integer>{ } INT { $][$ = $][1 + $][2 + $][3 + $][4 + $][5; };
761 ## --------------- ##
763 ## --------------- ##
765 AT_SETUP([Unused values])
766 AT_CHECK_UNUSED_VALUES
767 AT_CHECK_UNUSED_VALUES(, [1])
771 ## ------------------------------------------ ##
772 ## Unused values before symbol declarations. ##
773 ## ------------------------------------------ ##
775 AT_SETUP([Unused values before symbol declarations])
776 AT_CHECK_UNUSED_VALUES([1])
777 AT_CHECK_UNUSED_VALUES([1], [1])
781 ## ------------------- ##
782 ## Symbol redeclared. ##
783 ## ------------------- ##
785 AT_SETUP([Symbol redeclared])
795 AT_BISON_CHECK([-fcaret input.y], [0], [],
796 [[input.y:1.12-14: warning: symbol FOO redeclared [-Wother]
799 input.y:1.8-10: note: previous declaration
802 input.y:2.15-17: warning: symbol BAR redeclared [-Wother]
803 2 | %token BAR 12 BAR 12
805 input.y:2.8-10: note: previous declaration
806 2 | %token BAR 12 BAR 12
808 input.y:3.14-16: warning: symbol EOF redeclared [-Wother]
809 3 | %token EOF 0 EOF 0
811 input.y:3.8-10: note: previous declaration
812 3 | %token EOF 0 EOF 0
819 ## --------------------------- ##
820 ## Symbol class redefinition. ##
821 ## --------------------------- ##
823 AT_SETUP([Symbol class redefinition])
829 %nterm error // The token error cannot be redefined as an nterm.
835 AT_BISON_CHECK([-fcaret input.y], [1], [],
836 [[input.y:2.8-10: error: symbol FOO redeclared as a nonterminal
839 input.y:1.8-10: note: previous definition
842 input.y:3.8-10: error: symbol BAR redeclared as a token
845 input.y:2.12-14: note: previous definition
848 input.y:4.8-12: error: symbol error redeclared as a nonterminal
849 4 | %nterm error // The token error cannot be redefined as an nterm.
851 input.y:6.1-3: error: rule given for FOO, which is a token
859 ## --------------------------------------------- ##
860 ## Default %printer and %destructor redeclared. ##
861 ## --------------------------------------------- ##
863 AT_SETUP([Default %printer and %destructor redeclared])
867 m4_pushdef([AT_TEST],
868 [AT_DATA([[input.y]],
869 [[%destructor { destroy ($$); } <$1> <$1>
870 %printer { print ($$); } <$1> <$1>
872 %destructor { destroy ($$); } <$1>
873 %printer { print ($$); } <$1>
879 %destructor { destroy ($$); } <$1>;
880 %printer { print ($$); } <$1>;
883 AT_BISON_CHECK([-fcaret input.y], [1], [],
884 [[input.y:1.13-29: error: %destructor redeclaration for <>
885 1 | %destructor { destroy ($$); } <> <>
887 input.y:1.13-29: note: previous declaration
888 1 | %destructor { destroy ($$); } <> <>
890 input.y:2.10-24: error: %printer redeclaration for <>
891 2 | %printer { print ($$); } <> <>
893 input.y:2.10-24: note: previous declaration
894 2 | %printer { print ($$); } <> <>
896 input.y:4.13-29: error: %destructor redeclaration for <>
897 4 | %destructor { destroy ($$); } <>
899 input.y:1.13-29: note: previous declaration
900 1 | %destructor { destroy ($$); } <> <>
902 input.y:5.10-24: error: %printer redeclaration for <>
903 5 | %printer { print ($$); } <>
905 input.y:2.10-24: note: previous declaration
906 2 | %printer { print ($$); } <> <>
908 input.y:11.13-29: error: %destructor redeclaration for <>
909 11 | %destructor { destroy ($$); } <>;
911 input.y:1.13-29: note: previous declaration
912 1 | %destructor { destroy ($$); } <> <>
914 input.y:12.10-24: error: %printer redeclaration for <>
915 12 | %printer { print ($$); } <>;
917 input.y:2.10-24: note: previous declaration
918 2 | %printer { print ($$); } <> <>
924 AT_TEST([], [*], [*])
930 ## ---------------------------------------------- ##
931 ## Per-type %printer and %destructor redeclared. ##
932 ## ---------------------------------------------- ##
934 AT_SETUP([Per-type %printer and %destructor redeclared])
937 [[%destructor { destroy ($$); } <field1> <field2>
938 %printer { print ($$); } <field1> <field2>
940 %destructor { destroy ($$); } <field1> <field1>
941 %printer { print ($$); } <field2> <field2>
947 %destructor { destroy ($$); } <field2> <field1>;
948 %printer { print ($$); } <field2> <field1>;
951 AT_BISON_CHECK([input.y], [1], [],
952 [[input.y:4.13-29: error: %destructor redeclaration for <field1>
953 input.y:1.13-29: note: previous declaration
954 input.y:4.13-29: error: %destructor redeclaration for <field1>
955 input.y:1.13-29: note: previous declaration
956 input.y:5.10-24: error: %printer redeclaration for <field2>
957 input.y:2.10-24: note: previous declaration
958 input.y:5.10-24: error: %printer redeclaration for <field2>
959 input.y:2.10-24: note: previous declaration
960 input.y:11.13-29: error: %destructor redeclaration for <field2>
961 input.y:1.13-29: note: previous declaration
962 input.y:11.13-29: error: %destructor redeclaration for <field1>
963 input.y:1.13-29: note: previous declaration
964 input.y:12.10-24: error: %printer redeclaration for <field2>
965 input.y:2.10-24: note: previous declaration
966 input.y:12.10-24: error: %printer redeclaration for <field1>
967 input.y:2.10-24: note: previous declaration
973 ## ------------------- ##
974 ## Undefined symbols. ##
975 ## ------------------- ##
977 AT_SETUP([Undefined symbols])
980 [[%printer {} foo baz
987 AT_BISON_CHECK([-fcaret input.y], [1], [],
988 [[input.y:1.13-15: warning: symbol 'foo' is used, but is not defined as a token and has no rules [-Wother]
989 1 | %printer {} foo baz
991 input.y:1.17-19: warning: symbol 'baz' is used, but is not defined as a token and has no rules [-Wother]
992 1 | %printer {} foo baz
994 input.y:2.16-18: error: symbol 'bar' is used, but is not defined as a token and has no rules
995 2 | %destructor {} bar
997 input.y:3.13-15: warning: symbol 'qux' is used, but is not defined as a token and has no rules [-Wother]
1005 ## ----------------------------------------------------- ##
1006 ## Unassociated types used for a printer or destructor. ##
1007 ## ----------------------------------------------------- ##
1009 AT_SETUP([Unassociated types used for a printer or destructor])
1011 AT_DATA([[input.y]],
1012 [[%token <type1> tag1
1015 %printer { } <type1> <type3>
1016 %destructor { } <type2> <type4>
1026 AT_BISON_CHECK([input.y], [0], [],
1027 [[input.y:4.22-28: warning: type <type3> is used, but is not associated to any symbol [-Wother]
1028 input.y:5.25-31: warning: type <type4> is used, but is not associated to any symbol [-Wother]
1034 ## --------------------------------- ##
1035 ## Useless printers or destructors. ##
1036 ## --------------------------------- ##
1038 AT_SETUP([Useless printers or destructors])
1040 # AT_TEST([INPUT], [STDERR])
1041 # --------------------------
1042 m4_pushdef([AT_TEST],
1043 [AT_DATA([[input.y]],
1046 AT_BISON_CHECK([input.y], [0], [], [$2
1049 AT_TEST([[%token <type1> token1
1050 %token <type2> token2
1051 %token <type3> token3
1052 %token <type4> token4
1053 %token <type5> token51 token52
1054 %token <type6> token61 token62
1055 %token <type7> token7
1058 %destructor {} token2
1060 %destructor {} token61
1065 %destructor {} <type2>
1067 %destructor {} <type4>
1070 %destructor {} <type6>
1072 %destructor {} <type7>
1076 [[input.y:16.13-19: warning: useless %printer for type <type1> [-Wother]
1077 input.y:17.16-22: warning: useless %destructor for type <type2> [-Wother]]])
1079 # If everybody is typed, <> is useless.
1080 AT_TEST([[%type <type> exp
1085 [[input.y:3.13-14: warning: useless %printer for type <> [-Wother]]])
1087 # If nobody is typed, <*> is useless.
1092 [[input.y:2.16-18: warning: useless %printer for type <*> [-Wother]]])
1094 m4_popdef([AT_TEST])
1099 ## ---------------------------------------- ##
1100 ## Unused values with default %destructor. ##
1101 ## ---------------------------------------- ##
1103 AT_SETUP([Unused values with default %destructor])
1105 AT_DATA([[input.y]],
1106 [[%destructor { destroy ($$); } <>
1111 start: end end tagged tagged { $<tag>1; $3; } ;
1116 AT_BISON_CHECK([-fcaret input.y], [0], [],
1117 [[input.y:6.8-45: warning: unset value: $$ [-Wother]
1118 6 | start: end end tagged tagged { $<tag>1; $3; } ;
1119 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
1120 input.y:6.12-14: warning: unused value: $2 [-Wother]
1121 6 | start: end end tagged tagged { $<tag>1; $3; } ;
1123 input.y:7.6-8: warning: unset value: $$ [-Wother]
1128 AT_DATA([[input.y]],
1129 [[%destructor { destroy ($$); } <*>
1134 start: end end tagged tagged { $<tag>1; $3; } ;
1139 AT_BISON_CHECK([input.y], [0], [],
1140 [[input.y:6.23-28: warning: unused value: $4 [-Wother]
1141 input.y:8.9-11: warning: unset value: $$ [-Wother]
1147 ## ----------------------------------------- ##
1148 ## Unused values with per-type %destructor. ##
1149 ## ----------------------------------------- ##
1151 AT_SETUP([Unused values with per-type %destructor])
1153 AT_DATA([[input.y]],
1154 [[%destructor { destroy ($$); } <field1>
1155 %type <field1> start end
1159 start: end end { $1; } ;
1163 AT_BISON_CHECK([-fcaret input.y], [0], [],
1164 [[input.y:6.8-22: warning: unset value: $$ [-Wother]
1165 6 | start: end end { $1; } ;
1167 input.y:6.12-14: warning: unused value: $2 [-Wother]
1168 6 | start: end end { $1; } ;
1170 input.y:7.6-8: warning: unset value: $$ [-Wother]
1178 ## ------------------ ##
1179 ## Duplicate string. ##
1180 ## ------------------ ##
1183 AT_SETUP([Duplicate string])
1185 AT_BISON_OPTION_PUSHDEFS
1187 [[/* 'Bison -v' used to dump core when two tokens are defined with the same
1188 string, as LE and GE below. */
1195 exp: '(' exp ')' | NUM ;
1198 AT_BISON_OPTION_POPDEFS
1200 AT_BISON_CHECK([-v -o input.c input.y], 0, [],
1201 [[input.y:6.11-14: warning: symbol "<=" used more than once as a literal string [-Wother]
1207 ## ------------------ ##
1208 ## Token collisions. ##
1209 ## ------------------ ##
1211 AT_SETUP([Token collisions])
1213 AT_DATA([[input.y]],
1214 [[%token FOO 42 "foo"
1220 AT_BISON_CHECK([-fcaret input.y], [1], [],
1221 [[input.y:2.17-21: warning: symbol "foo" used more than once as a literal string [-Wother]
1224 input.y:2.10-12: error: code 42 reassigned to token BAR
1227 input.y:1.15-19: note: previous declaration for "foo"
1228 1 | %token FOO 42 "foo"
1235 ## ---------------------- ##
1236 ## Incompatible Aliases. ##
1237 ## ---------------------- ##
1239 AT_SETUP([Incompatible Aliases])
1241 m4_pushdef([AT_TEST],
1242 [AT_DATA([input.y], [$1])
1243 AT_BISON_CHECK([-fcaret input.y], [1], [], [$2])
1246 # Use the string-alias first to check the order between "first
1247 # declaration" and second.
1249 AT_TEST([[%token foo "foo"
1255 [[input.y:3.13-15: error: %type redeclaration for foo
1258 input.y:2.13-17: note: previous declaration
1259 2 | %type <bar> "foo"
1263 AT_TEST([[%token foo "foo"
1264 %printer {bar} "foo"
1269 [[input.y:3.10-14: error: %printer redeclaration for foo
1270 3 | %printer {baz} foo
1272 input.y:2.10-14: note: previous declaration
1273 2 | %printer {bar} "foo"
1277 AT_TEST([[%token foo "foo"
1278 %destructor {bar} "foo"
1279 %destructor {baz} foo
1283 [[input.y:3.13-17: error: %destructor redeclaration for foo
1284 3 | %destructor {baz} foo
1286 input.y:2.13-17: note: previous declaration
1287 2 | %destructor {bar} "foo"
1291 AT_TEST([[%token foo "foo"
1297 [[input.y:3.1-5: error: %left redeclaration for foo
1300 input.y:2.1-5: note: previous declaration
1305 # This time, declare the alias after its use.
1307 # Precedence/associativity.
1308 AT_TEST([[%left "foo"
1314 [[input.y:2.1-5: error: %left redeclaration for foo
1317 input.y:1.1-5: note: previous declaration
1323 AT_TEST([[%printer {} "foo"
1329 [[input.y:2.10-11: error: %printer redeclaration for foo
1332 input.y:1.10-11: note: previous declaration
1333 1 | %printer {} "foo"
1338 AT_TEST([[%destructor {} "foo"
1344 [[input.y:2.13-14: error: %destructor redeclaration for foo
1345 2 | %destructor {} foo
1347 input.y:1.13-14: note: previous declaration
1348 1 | %destructor {} "foo"
1352 m4_popdef([AT_TEST])
1357 ## ----------------------- ##
1358 ## Torturing the Scanner. ##
1359 ## ----------------------- ##
1361 # Be sure to compile and run, so that the C compiler checks what
1364 AT_SETUP([Torturing the Scanner])
1366 AT_BISON_OPTION_PUSHDEFS
1367 AT_DATA([input.y], [])
1368 AT_BISON_CHECK([input.y], [1], [],
1369 [[input.y:1.1: error: unexpected end of file
1376 AT_BISON_CHECK([-fcaret input.y], [1], [],
1377 [[input.y:1.1-2: error: unexpected {...}
1383 # Clang chokes on some of our comments, because it tries to "parse"
1384 # some documentation directives in the comments:
1386 # input.c:166:50: error: '\a' command does not have a valid word argument [-Werror,-Wdocumentation]
1387 # FAKE = 258 /* "fake [] \a\b\f\n\r\t\v\"'?\\[\\ ??!??'??(??)??-??/??<??=??> \001\001" */
1389 AT_DATA_GRAMMAR([input.y],
1391 #if defined __clang__ && 10 <= __clang_major__
1392 # pragma clang diagnostic ignored "-Wdocumentation"
1397 /* This is seen in GCC: a %{ and %} in middle of a comment. */
1398 const char *foo = "So %{ and %} can be here too.";
1401 /* These examples test Bison while not stressing C compilers too much.
1402 Many C compilers mishandle backslash-newlines, so this part of the
1403 test is inside "#if 0". The comment and string are written so that
1404 the "#endif" will be seen regardless of the C compiler bugs that we
1407 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
1410 The Apple Darwin compiler (as of late 2002) mishandles
1411 \\[newline]' within a character constant.
1416 * A comment with backslash-newlines in it. %} *\
1419 /* { Close the above comment, if the C compiler mishandled it. */
1422 " A string with backslash-newlines in it %{ %} \\
1426 char apostrophe = '\'';
1433 /* %{ and %} can be here too. */
1436 /* Exercise pre-prologue dependency to %union. */
1440 /* Exercise M4 quoting: '@:>@@:>@', 0. */
1442 /* Also exercise %union. */
1445 value ival; /* A comment to exercise an old bug. */
1449 /* Exercise post-prologue dependency to %union. */
1451 static YYSTYPE value_as_yystype (value val);
1453 /* Exercise quotes in declarations. */
1454 char quote[] = "@:>@@:>@,";
1458 ]AT_YYERROR_DECLARE[
1464 /* Exercise quotes in strings. */
1465 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
1467 /* Beware of the generated comments that embed string aliases that
1468 might close the comment. */
1469 %token COMMENT_CLOSE "*/"
1470 %token COMMENT "/* comment */"
1473 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
1474 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
1476 /* Exercise quotes in braces. */
1477 char tmp[] = "@<:@%c@:>@,\n";
1482 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
1483 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
1484 output.or.oline.opt: %empty;|oline;;|output;;;
1485 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
1487 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
1490 value_as_yystype (value val)
1500 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
1503 enum { input_elts = sizeof input };
1506 assert (0 <= toknum && toknum < input_elts);
1507 yylval = value_as_yystype (input[toknum]);
1508 return input[toknum++];
1512 # Pacify Emacs'font-lock-mode: "
1515 [[typedef int value;
1521 AT_BISON_OPTION_POPDEFS
1523 AT_BISON_CHECK([-d -v -o input.c input.y])
1524 AT_COMPILE([input.o])
1525 AT_COMPILE([main.o])
1526 AT_COMPILE([input], [input.o main.o])
1527 AT_PARSER_CHECK([input], 0,
1534 ## ---------------------- ##
1535 ## Typed symbol aliases. ##
1536 ## ---------------------- ##
1538 AT_SETUP([Typed symbol aliases])
1540 # Bison 2.0 broke typed symbol aliases - ensure they work.
1541 AT_BISON_OPTION_PUSHDEFS
1543 AT_DATA_GRAMMAR([input.y],
1548 %token <val> MY_TOKEN "MY TOKEN"
1555 AT_BISON_CHECK([-o input.c input.y])
1557 AT_BISON_OPTION_POPDEFS
1565 m4_define([AT_CHECK_REQUIRE],
1566 [AT_SETUP([Require $1])
1567 AT_BISON_OPTION_PUSHDEFS
1568 AT_DATA_GRAMMAR([input.y],
1573 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
1574 AT_BISON_OPTION_POPDEFS
1578 AT_CHECK_REQUIRE(1.0, 0)
1579 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
1580 ## FIXME: Some day augment this version number.
1581 AT_CHECK_REQUIRE(100.0, 63)
1584 ## ------------------------------------- ##
1585 ## String aliases for character tokens. ##
1586 ## ------------------------------------- ##
1588 AT_SETUP([String aliases for character tokens])
1590 # Bison once thought a character token and its alias were different
1591 # symbols with the same code.
1593 AT_BISON_OPTION_PUSHDEFS
1594 AT_DATA_GRAMMAR([input.y],
1601 AT_BISON_CHECK([-o input.c input.y])
1603 AT_BISON_OPTION_POPDEFS
1607 ## -------------- ##
1609 ## -------------- ##
1613 AT_BISON_OPTION_PUSHDEFS
1614 AT_DATA_GRAMMAR([input.y],
1616 %token WITHOUT_DASH "WITHOUT-DASH"
1618 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
1620 ]AT_YYERROR_DECLARE[
1624 start: with-dash without_dash with.period without_period;
1625 with-dash: WITH-DASH;
1626 without_dash: "WITHOUT-DASH";
1627 with.period: WITH.PERIOD;
1628 without_period: "WITHOUT.PERIOD";
1634 # POSIX Yacc accept periods, but not dashes.
1635 AT_BISON_CHECK([--yacc input.y], [], [],
1636 [[input.y:1.1-5: warning: POSIX Yacc does not support %code [-Wyacc]
1637 input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc]
1638 input.y:10.21-34: warning: POSIX Yacc does not support string literals [-Wyacc]
1639 input.y:12.23-38: warning: POSIX Yacc does not support string literals [-Wyacc]
1640 input.y:13.1-5: warning: POSIX Yacc does not support %code [-Wyacc]
1641 input.y:20.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc]
1642 input.y:22.15-28: warning: POSIX Yacc does not support string literals [-Wyacc]
1643 input.y:24.17-32: warning: POSIX Yacc does not support string literals [-Wyacc]
1646 # Dashes are fine for GNU Bison.
1647 AT_BISON_CHECK([-o input.c input.y])
1649 # Make sure we don't export silly token identifiers with periods or dashes.
1650 AT_COMPILE([input.o])
1653 # Periods are genuine letters, they can start identifiers.
1654 # Digits and dashes cannot.
1655 AT_DATA_GRAMMAR([input.y],
1663 AT_BISON_CHECK([-o input.c input.y], [1], [],
1664 [[input.y:10.10: error: invalid character: '-'
1665 input.y:11.10-16: error: invalid identifier: '1NV4L1D'
1666 input.y:12.10: error: invalid character: '-'
1669 AT_BISON_OPTION_POPDEFS
1673 ## ----------------- ##
1674 ## Numbered tokens. ##
1675 ## ----------------- ##
1677 AT_SETUP([Numbered tokens])
1679 AT_BISON_OPTION_PUSHDEFS
1680 AT_DATA_GRAMMAR([redecl.y],
1681 [[%token DECIMAL_1 11259375
1682 HEXADECIMAL_1 0xabcdef
1683 HEXADECIMAL_2 0xFEDCBA
1686 start: DECIMAL_1 HEXADECIMAL_2;
1689 AT_BISON_CHECK([redecl.y], [1], [],
1690 [[redecl.y:10.10-22: error: code 11259375 reassigned to token HEXADECIMAL_1
1691 redecl.y:9.8-16: note: previous declaration for DECIMAL_1
1692 redecl.y:12.10-18: error: code 16702650 reassigned to token DECIMAL_2
1693 redecl.y:11.10-22: note: previous declaration for HEXADECIMAL_2
1696 AT_DATA_GRAMMAR([too-large.y],
1697 [[%token TOO_LARGE_DEC 999999999999999999999
1698 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
1700 start: TOO_LARGE_DEC TOO_LARGE_HEX
1704 AT_BISON_CHECK([too-large.y], [1], [],
1705 [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
1706 too-large.y:9.22-42: error: code of token TOO_LARGE_DEC too large
1707 too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
1708 too-large.y:10.24-44: error: code of token TOO_LARGE_HEX too large
1711 AT_BISON_OPTION_POPDEFS
1715 ## --------------------- ##
1716 ## Unclosed constructs. ##
1717 ## --------------------- ##
1719 AT_SETUP([Unclosed constructs])
1721 # Bison's scan-gram.l once forgot to STRING_FINISH () some unclosed
1722 # constructs, so they were prepended to whatever it STRING_GROW ()'ed
1723 # next. It also threw them away rather than returning them to the
1724 # parser. The effect was confusing subsequent error messages.
1729 %token AB "ab" // Used to complain that "ab" was already used.
1732 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
1738 // Used to report a syntax error because it didn't see any kind of symbol
1744 // Used to report a syntax error because it didn't see braced code.
1745 %destructor { free ($$)
1748 AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [],
1749 [[input.y:1.10-2.0: error: missing '"' at end of line
1752 input.y:4.10-5.0: error: missing "'" at end of line
1755 input.y:14.11-15.0: error: missing "'" at end of line
1758 input.y:16.11-17.0: error: missing '"' at end of line
1761 input.y:19.13-20.0: error: missing '}' at end of file
1762 19 | %destructor { free ($$)
1764 input.y:20.1: error: unexpected end of file
1770 ## ------------------------- ##
1771 ## %start after first rule. ##
1772 ## ------------------------- ##
1774 AT_SETUP([%start after first rule])
1776 # Bison once complained that a %start after the first rule was a
1777 # redeclaration of the start symbol.
1781 false_start: %empty;
1782 start: false_start ;
1786 AT_BISON_CHECK([-o input.c input.y])
1791 ## --------------------- ##
1792 ## %prec takes a token. ##
1793 ## --------------------- ##
1795 AT_SETUP([%prec takes a token])
1797 # Bison once allowed %prec sym where sym was a nonterminal.
1801 start: PREC %prec PREC ;
1805 AT_BISON_CHECK([input.y], [1], [],
1806 [[input.y:3.1-4: error: rule given for PREC, which is a token
1812 ## ------------------------------- ##
1813 ## %prec's token must be defined. ##
1814 ## ------------------------------- ##
1816 AT_SETUP([[%prec's token must be defined]])
1818 # According to POSIX, a %prec token must be defined separately.
1820 AT_DATA([[input.y]],
1825 AT_BISON_CHECK([[input.y]], [[0]], [],
1826 [[input.y:2.8-17: warning: token for %prec is not defined: PREC [-Wother]
1832 ## -------------------------------- ##
1833 ## Reject unused %code qualifiers. ##
1834 ## -------------------------------- ##
1836 AT_SETUP([Reject unused %code qualifiers])
1838 AT_DATA([input-c.y],
1846 AT_BISON_CHECK([[input-c.y]], [[1]], [],
1847 [[input-c.y:1.7: error: %code qualifier 'q' is not used
1848 input-c.y:2.7-9: error: %code qualifier 'bad' is not used
1849 input-c.y:3.7-9: error: %code qualifier 'bad' is not used
1850 input-c.y:4.7-12: error: %code qualifier 'format' is not used
1853 AT_DATA([input-c-glr.y],
1860 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
1861 [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used
1862 input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used
1863 input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used
1866 AT_DATA([input-c++.y],
1873 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
1874 [[input-c++.y:1.7: error: %code qualifier 'q' is not used
1875 input-c++.y:2.7-9: error: %code qualifier 'bad' is not used
1876 input-c++.y:3.8: error: %code qualifier 'q' is not used
1879 AT_DATA([input-c++-glr.y],
1886 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
1887 [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used
1888 input-c++-glr.y:2.7: error: %code qualifier 'q' is not used
1889 input-c++-glr.y:3.7: error: %code qualifier 'q' is not used
1892 AT_DATA([special-char-@@.y],
1899 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
1900 [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used
1901 special-char-@@.y:2.7: error: %code qualifier 'q' is not used
1902 special-char-@@.y:3.7: error: %code qualifier 'q' is not used
1905 AT_DATA([special-char-@:>@.y],
1912 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
1913 [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used
1914 special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used
1915 special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used
1921 ## ---------------- ##
1922 ## Multiple %code. ##
1923 ## ---------------- ##
1925 AT_SETUP([Multiple %code])
1927 # Make sure that repeated arguments to %code are separated by
1928 # end-of-lines. At some point, a missing eol would leave synclines
1929 # appended to the previous value. Here, we use CPP directive to
1930 # introduce dependency on the absence/presence of the eol.
1931 AT_BISON_OPTION_PUSHDEFS
1934 [[%code {#include <assert.h>}
1938 %code {#define D 42}
1940 ]AT_YYERROR_DECLARE[
1954 AT_FULL_COMPILE([input])
1955 AT_PARSER_CHECK([input])
1957 AT_BISON_OPTION_POPDEFS
1961 ## ---------------- ##
1962 ## %define errors. ##
1963 ## ---------------- ##
1965 AT_SETUP([%define errors])
1967 AT_DATA([input-redefined.y],
1968 [[%define var "value1"
1969 %define var "value1"
1970 %define var "value2"
1971 %define special1 "@:>@"
1972 %define special2 "@<:@"
1977 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
1978 [[input-redefined.y:2.1-20: warning: %define variable 'var' redefined [-Wother]
1979 input-redefined.y:1.1-20: note: previous definition
1980 input-redefined.y:3.2-21: error: %define variable 'var' redefined
1981 input-redefined.y:2.1-20: note: previous definition
1982 input-redefined.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
1985 AT_DATA([input-unused.y],
1986 [[%define var "value"
1991 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
1992 [[input-unused.y:1.1-19: error: %define variable 'var' is not used
1998 ## ----------------------------------- ##
1999 ## %define, --define, --force-define. ##
2000 ## ----------------------------------- ##
2002 AT_SETUP([[%define, --define, --force-define]])
2005 [[m4@&t@_divert_push(0)@
2006 @output(b4_parser_file_name@)@
2007 [var-dd: ]b4_percent_define_get([[var-dd]])[
2008 var-ff: ]b4_percent_define_get([[var-ff]])[
2009 var-dfg: ]b4_percent_define_get([[var-dfg]])[
2010 var-fd: ]b4_percent_define_get([[var-fd]])
2011 m4@&t@_divert_pop(0)
2013 AT_DATA([[input.y]],
2014 [[%define var-dfg "gram"
2018 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
2019 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
2020 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
2021 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
2022 --skeleton ./skel.c input.y]])
2023 AT_CHECK([[cat input.tab.c]], [[0]],
2030 AT_DATA([[input-dg.y]],
2031 [[%define var "gram"
2035 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
2036 [[input-dg.y:1.1-18: error: %define variable 'var' redefined
2037 <command line>:3: note: previous definition
2038 input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
2041 AT_DATA([[input-dg.y]],
2042 [[%define var "gram"
2046 AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
2047 [[input-dg.y:1.1-18: error: %define variable 'var' redefined
2048 1 | %define var "gram"
2049 | ^~~~~~~~~~~~~~~~~~
2050 <command line>:4: note: previous definition
2051 input-dg.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
2054 AT_DATA([[input-unused.y]],
2058 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
2059 [[<command line>:3: error: %define variable 'unused-d' is not used
2060 <command line>:4: error: %define variable 'unused-f' is not used
2066 ## --------------------------- ##
2067 ## %define Boolean variables. ##
2068 ## --------------------------- ##
2070 AT_SETUP([["%define" Boolean variables]])
2074 %define api.parser.class {Input}
2075 %define api.parser.public {maybe}
2080 AT_BISON_CHECK([[Input.y]], [1], [],
2081 [[Input.y:3.1-33: error: invalid value for %define Boolean variable 'api.parser.public'
2087 ## ------------------------ ##
2088 ## %define code variables. ##
2089 ## ------------------------ ##
2091 AT_SETUP([["%define" code variables]])
2093 m4_pushdef([AT_TEST],
2094 [AT_DATA([input.yy],
2095 [[%skeleton "lalr1.cc" %locations
2096 %define api.location.type ]$1[quux]$2[
2097 %define api.namespace ]$1[quux]$2[
2098 %define api.prefix ]$1[quux]$2[
2099 %define api.token.prefix ]$1[quux]$2[
2100 %token TOK // Otherwise api.token.prefix is unused.
2105 AT_BISON_CHECK([[input.yy]], [0], [],
2106 [[input.yy:2.$3: warning: %define variable 'api.location.type' requires '{...}' values [-Wdeprecated]
2107 input.yy:4.$3: warning: %define variable 'api.prefix' requires '{...}' values [-Wdeprecated]
2108 input.yy:5.$3: warning: %define variable 'api.token.prefix' requires '{...}' values [-Wdeprecated]
2109 input.yy:3.$3: warning: %define variable 'api.namespace' requires '{...}' values [-Wdeprecated]
2113 AT_TEST([], [], [1-30])
2114 AT_TEST(["], ["], [1-32])
2115 m4_popdef([AT_TEST])
2120 ## --------------------------- ##
2121 ## %define keyword variables. ##
2122 ## --------------------------- ##
2124 AT_SETUP([["%define" keyword variables]])
2126 m4_pushdef([AT_TEST],
2128 [[%define api.pure ]$1[true]$2[
2129 %define api.push-pull ]$1[both]$2[
2130 %define lr.default-reduction ]$1[most]$2[
2131 %define lr.keep-unreachable-state ]$1[true]$2[
2132 %define lr.type ]$1[lalr]$2[
2137 AT_BISON_CHECK([[input.y]], [0], [],
2138 [[input.y:5.1-40: warning: %define variable 'lr.type' requires keyword values [-Wdeprecated]
2139 input.y:3.1-40: warning: %define variable 'lr.default-reduction' requires keyword values [-Wdeprecated]
2140 input.y:4.1-40: warning: %define variable 'lr.keep-unreachable-state' requires keyword values [-Wdeprecated]
2141 input.y:1.1-38: warning: %define variable 'api.pure' requires keyword values [-Wdeprecated]
2142 input.y:2.1-40: warning: %define variable 'api.push-pull' requires keyword values [-Wdeprecated]
2148 m4_popdef([AT_TEST])
2153 ## ------------------------ ##
2154 ## %define enum variables. ##
2155 ## ------------------------ ##
2157 AT_SETUP([["%define" enum variables]])
2159 # Check errors from the front-end, and the back-end. Since the
2160 # front-end quits before calling the back-end, these tests cannot be
2164 AT_DATA([[input.y]],
2165 [[%define lr.default-reduction bogus
2169 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2170 [[input.y:1.1-34: error: invalid value for %define variable 'lr.default-reduction': 'bogus'
2171 1 | %define lr.default-reduction bogus
2172 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2173 input.y:1.1-34: note: accepted value: 'most'
2174 input.y:1.1-34: note: accepted value: 'consistent'
2175 input.y:1.1-34: note: accepted value: 'accepting'
2179 AT_DATA([[input.y]],
2180 [[%define lr.default-reduction {[$@]}
2184 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2185 [[input.y:1.1-35: warning: %define variable 'lr.default-reduction' requires keyword values [-Wdeprecated]
2186 1 | %define lr.default-reduction {[$@]}
2187 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2188 input.y:1.1-35: error: invalid value for %define variable 'lr.default-reduction': '[$@]'
2189 1 | %define lr.default-reduction {[$@]}
2190 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2191 input.y:1.1-35: note: accepted value: 'most'
2192 input.y:1.1-35: note: accepted value: 'consistent'
2193 input.y:1.1-35: note: accepted value: 'accepting'
2198 AT_DATA([[input.y]],
2199 [[%define api.push-pull neither
2203 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2204 [[input.y:1.1-29: error: invalid value for %define variable 'api.push-pull': 'neither'
2205 1 | %define api.push-pull neither
2206 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2207 input.y:1.1-29: note: accepted value: 'pull'
2208 input.y:1.1-29: note: accepted value: 'push'
2209 input.y:1.1-29: note: accepted value: 'both'
2216 ## ------------------------ ##
2217 ## %define file variables. ##
2218 ## ------------------------ ##
2220 AT_SETUP([["%define" file variables]])
2222 AT_DATA([[input.y]],
2223 [[%skeleton "lalr1.cc"
2225 %define api.location.file {bogus}
2229 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2230 [[input.y:3.1-33: error: %define variable 'api.location.file' requires 'none' or '"..."' values
2231 3 | %define api.location.file {bogus}
2232 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2238 ## -------------------------------- ##
2239 ## %define backward compatibility. ##
2240 ## -------------------------------- ##
2242 AT_SETUP([["%define" backward compatibility]])
2244 # The error messages tell us whether the variables are properly updated.
2245 AT_DATA([[input.y]],
2246 [[%define api.push_pull both
2247 %define lr.keep_unreachable_states maybe
2248 %define namespace "foo"
2250 %define parser_class_name {parser}
2251 %define filename_type {filename}
2255 AT_BISON_CHECK([[-fcaret input.y]], [1], [],
2256 [[input.y:1.1-26: warning: deprecated directive: '%define api.push_pull both', use '%define api.push-pull both' [-Wdeprecated]
2257 1 | %define api.push_pull both
2258 | ^~~~~~~~~~~~~~~~~~~~~~~~~~
2259 | %define api.push-pull both
2260 input.y:2.1-40: warning: deprecated directive: '%define lr.keep_unreachable_states maybe', use '%define lr.keep-unreachable-state maybe' [-Wdeprecated]
2261 2 | %define lr.keep_unreachable_states maybe
2262 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2263 | %define lr.keep-unreachable-state maybe
2264 input.y:3.1-23: warning: deprecated directive: '%define namespace "foo"', use '%define api.namespace {foo}' [-Wdeprecated]
2265 3 | %define namespace "foo"
2266 | ^~~~~~~~~~~~~~~~~~~~~~~
2267 | %define api.namespace {foo}
2268 input.y:4.1-15: warning: deprecated directive: '%define variant', use '%define api.value.type variant' [-Wdeprecated]
2271 | %define api.value.type variant
2272 input.y:5.1-34: warning: deprecated directive: '%define parser_class_name {parser}', use '%define api.parser.class {parser}' [-Wdeprecated]
2273 5 | %define parser_class_name {parser}
2274 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2275 | %define api.parser.class {parser}
2276 input.y:6.1-32: warning: deprecated directive: '%define filename_type {filename}', use '%define api.filename.type {filename}' [-Wdeprecated]
2277 6 | %define filename_type {filename}
2278 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2279 | %define api.filename.type {filename}
2280 input.y:2.1-40: error: invalid value for %define Boolean variable 'lr.keep-unreachable-state'
2281 2 | %define lr.keep_unreachable_states maybe
2282 | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2283 input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
2289 ## ------------------------- ##
2290 ## Unused %define api.pure. ##
2291 ## ------------------------- ##
2293 AT_SETUP([[Unused %define api.pure]])
2295 # AT_TEST(DECLS, VALUE, LOCATION)
2296 # -------------------------------
2297 # Make sure Bison reports that '%define api.pure VALUE' is unused when DECLS
2299 m4_pushdef([AT_TEST],
2301 AT_DATA([[input.y]],
2302 [[%define api.pure ]$2[
2308 AT_BISON_CHECK([[input.y]], [[1]], [],
2309 [[input.y:]$3[: error: %define variable 'api.pure' is not used
2313 AT_TEST([[%language "c++"]], [[]], [[1.1-16]])
2314 AT_TEST([[%language "c++"]], [[false]], [[1.1-22]])
2315 AT_TEST([[%language "c++" %glr-parser]], [[""]], [[1.1-19]])
2316 AT_TEST([[%language "c++" %glr-parser]], [[false]], [[1.1-22]])
2317 AT_TEST([[%language "java"]], [[true]], [[1.1-21]])
2318 AT_TEST([[%language "java"]], [[false]], [[1.1-22]])
2320 m4_popdef([AT_TEST])
2325 ## -------------------------------- ##
2326 ## C++ namespace reference errors. ##
2327 ## -------------------------------- ##
2329 AT_SETUP([[C++ namespace reference errors]])
2331 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
2332 # -------------------------------------------------------------
2333 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
2334 m4_define([AT_CHECK_NAMESPACE_ERROR],
2336 AT_DATA([[input.y]],
2339 %define api.namespace {]$1[}
2344 AT_BISON_CHECK([[input.y]], [1], [],
2345 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
2350 AT_CHECK_NAMESPACE_ERROR([[]],
2351 [[input.y:3.1-24: error: namespace reference is empty]])
2352 AT_CHECK_NAMESPACE_ERROR([[ @tb@@tb@ @tb@ @tb@]],
2353 [[input.y:3.1-57: error: namespace reference is empty]])
2354 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
2355 [[input.y:3.1-34: error: namespace reference has consecutive "::"]])
2356 AT_CHECK_NAMESPACE_ERROR([[foo:: @tb@::bar]],
2357 [[input.y:3.1-38: error: namespace reference has consecutive "::"]])
2358 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
2359 [[input.y:3.1-31: error: namespace reference has consecutive "::"]])
2360 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
2361 [[input.y:3.1-32: error: namespace reference has consecutive "::"]])
2362 AT_CHECK_NAMESPACE_ERROR([[foo::bar::@tb@::]],
2363 [[input.y:3.1-43: error: namespace reference has consecutive "::"]],
2364 [[input.y:3.1-43: error: namespace reference has a trailing "::"]])
2365 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
2366 [[input.y:3.1-34: error: namespace reference has a trailing "::"]])
2367 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: @tb@]],
2368 [[input.y:3.1-41: error: namespace reference has a trailing "::"]])
2369 AT_CHECK_NAMESPACE_ERROR([[::]],
2370 [[input.y:3.1-26: error: namespace reference has a trailing "::"]])
2375 ## ------------------------ ##
2376 ## Bad character literals. ##
2377 ## ------------------------ ##
2379 # Bison used to accept character literals that were empty or contained
2380 # too many characters.
2382 AT_SETUP([[Bad character literals]])
2384 AT_DATA_NO_FINAL_EOL([empty.y],
2390 AT_BISON_CHECK([-fcaret empty.y], [1], [],
2391 [[empty.y:2.8-9: error: empty character literal
2394 empty.y:3.8-4.0: error: missing "'" at end of line
2397 empty.y:3.8-4.0: error: empty character literal
2400 empty.y:4.8: error: missing "'" at end of file
2403 empty.y:4.8: error: empty character literal
2408 AT_DATA_NO_FINAL_EOL([two.y],
2414 AT_BISON_CHECK([two.y], [1], [],
2415 [[two.y:2.8-11: error: extra characters in character literal
2416 two.y:3.8-4.0: error: missing "'" at end of line
2417 two.y:3.8-4.0: error: extra characters in character literal
2418 two.y:4.8-10: error: missing "'" at end of file
2419 two.y:4.8-10: error: extra characters in character literal
2422 AT_DATA_NO_FINAL_EOL([three.y],
2428 AT_BISON_CHECK([three.y], [1], [],
2429 [[three.y:2.8-12: error: extra characters in character literal
2430 three.y:3.8-4.0: error: missing "'" at end of line
2431 three.y:3.8-4.0: error: extra characters in character literal
2432 three.y:4.8-11: error: missing "'" at end of file
2433 three.y:4.8-11: error: extra characters in character literal
2439 ## ------------------------- ##
2440 ## Bad escapes in literals. ##
2441 ## ------------------------- ##
2443 AT_SETUP([[Bad escapes in literals]])
2447 start: '\777' '\0' '\xfff' '\x0'
2448 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
2452 # It is not easy to create special characters, we cannot even trust tr.
2453 # Beside we cannot even expect "echo '\0'" to output two characters
2454 # (well three with \n): at least Bash 3.2 converts the two-character
2455 # sequence "\0" into a single NUL character.
2456 AT_PERL_REQUIRE([[-e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y]])
2458 AT_BISON_CHECK([input.y], [1], [],
2459 [[input.y:2.9-12: error: invalid number after \-escape: 777
2460 input.y:2.16-17: error: invalid number after \-escape: 0
2461 input.y:2.21-25: error: invalid number after \-escape: xfff
2462 input.y:2.29-31: error: invalid number after \-escape: x0
2463 input.y:3.9-14: error: invalid number after \-escape: uffff
2464 input.y:3.18-23: error: invalid number after \-escape: u0000
2465 input.y:3.27-36: error: invalid number after \-escape: Uffffffff
2466 input.y:3.40-49: error: invalid number after \-escape: U00000000
2467 input.y:4.9-10: error: invalid character after \-escape: ' '
2468 input.y:4.14-15: error: invalid character after \-escape: A
2469 input.y:5.9-16: error: invalid character after \-escape: \t
2470 input.y:5.17: error: invalid character after \-escape: \f
2471 input.y:5.18: error: invalid character after \-escape: \0
2472 input.y:5.19: error: invalid character after \-escape: \001
2478 ## ------------------------- ##
2479 ## LAC: Errors for %define. ##
2480 ## ------------------------- ##
2482 AT_SETUP([[LAC: Errors for %define]])
2485 AT_DATA([[input.y]],
2490 # Only "full" and "none" are accepted for parse.lac
2491 # Unknown values (such as "unsupported") are rejected
2492 AT_BISON_CHECK([[-Dparse.lac=none input.y]])
2493 AT_BISON_CHECK([[-Dparse.lac=none -L c++ input.y]])
2494 AT_BISON_CHECK([[-Dparse.lac=full input.y]])
2495 AT_BISON_CHECK([[-Dparse.lac=full -L c++ input.y]])
2496 AT_BISON_CHECK([[-Dparse.lac=unsupported input.y]],
2498 [[<command line>:3: error: invalid value for %define variable 'parse.lac': 'unsupported'
2499 <command line>:3: note: accepted value: 'full'
2500 <command line>:3: note: accepted value: 'none'
2502 AT_BISON_CHECK([[-Dparse.lac=unsupported -L c++ input.y]],
2504 [[<command line>:3: error: invalid value for %define variable 'parse.lac': 'unsupported'
2505 <command line>:3: note: accepted value: 'full'
2506 <command line>:3: note: accepted value: 'none'
2509 # parse.lac.* options are useless if LAC isn't actually activated.
2510 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
2512 [[<command line>:3: error: %define variable 'parse.lac.es-capacity-initial' is not used
2514 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
2516 [[<command line>:3: error: %define variable 'parse.lac.memory-trace' is not used
2519 # parse.lac.* options are useless in C++ even if LAC isn't actually activated.
2520 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 -L C++ -Dparse.lac=full input.y]],
2522 [[<command line>:3: error: %define variable 'parse.lac.es-capacity-initial' is not used
2524 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full -L C++ -Dparse.lac=full input.y]],
2526 [[<command line>:3: error: %define variable 'parse.lac.memory-trace' is not used
2532 ## ---------------------- ##
2533 ## -Werror combinations. ##
2534 ## ---------------------- ##
2536 AT_SETUP([[-Werror combinations]])
2538 AT_DATA([[input.y]],
2543 # -Werror is not enabled by -Wall or equivalent.
2544 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
2545 [[input.y:2.15: warning: stray '$' [-Wother]
2547 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
2548 [[input.y:2.15: warning: stray '$' [-Wother]
2550 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
2551 [[input.y:2.15: warning: stray '$' [-Wother]
2554 # -Werror is not disabled by -Wnone or equivalent.
2555 AT_BISON_CHECK([[-Werror,none,other input.y]], [[1]], [[]],
2556 [[input.y:2.15: error: stray '$' [-Werror=other]
2558 AT_BISON_CHECK([[-Werror,no-all,other input.y]], [[1]], [[]],
2559 [[input.y:2.15: error: stray '$' [-Werror=other]
2562 # Check that -Wno-error keeps warnings enabled, but non fatal.
2563 AT_BISON_CHECK([[-Werror -Wno-error=other input.y]], [[0]], [[]],
2564 [[input.y:2.15: warning: stray '$' [-Wother]
2567 AT_BISON_CHECK([[-Wno-error=other -Werror input.y]], [[0]], [[]],
2568 [[input.y:2.15: warning: stray '$' [-Wother]
2571 AT_BISON_CHECK([[-Werror=other -Wno-other input.y]], [[0]], [[]],
2577 ## ------------------------------------------------------ ##
2578 ## %name-prefix and %define api.prefix are incompatible. ##
2579 ## ------------------------------------------------------ ##
2581 AT_SETUP([[%name-prefix and api.prefix are incompatible]])
2583 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
2584 # --------------------------------------------
2585 m4_pushdef([AT_TEST],
2586 [AT_DATA([[input.y]],
2591 AT_BISON_CHECK([[$2 -Wno-deprecated input.y]], [[1]], [[]],
2592 [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
2596 AT_TEST([%define api.prefix {foo} %name-prefix "bar"], [], [input.y:1.1-24])
2597 AT_TEST([], [-Dapi.prefix={foo} -p bar], [<command line>:3])
2598 AT_TEST([%name-prefix "bar"], [-Dapi.prefix={foo}], [<command line>:3])
2599 AT_TEST([%define api.prefix {foo}], [-p bar], [input.y:1.1-24])
2601 m4_popdef([AT_TEST])
2606 ## ----------------------- ##
2607 ## Redefined %union name. ##
2608 ## ----------------------- ##
2610 AT_SETUP([[Redefined %union name]])
2612 # AT_TEST(DIRECTIVES, EXIT-STATUS, ERROR)
2613 # ---------------------------------------
2614 m4_pushdef([AT_TEST],
2615 [AT_DATA([[input.y]],
2621 AT_BISON_CHECK([[input.y]], [$2], [[]],
2625 AT_TEST([[%union foo {};
2628 %define api.value.union.name foo]],
2630 [[input.y:3.8-10: warning: %define variable 'api.value.union.name' redefined [-Wother]
2631 input.y:1.8-10: note: previous definition
2632 input.y:4.1-32: warning: %define variable 'api.value.union.name' redefined [-Wother]
2633 input.y:3.8-10: note: previous definition
2634 input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
2637 AT_TEST([[%define api.value.union.name {foo}]], [1],
2638 [[input.y:1.1-34: error: %define variable 'api.value.union.name' requires keyword values
2639 input.y:1.1-34: error: %define variable 'api.value.union.name' is not used
2642 AT_TEST([[%define api.value.union.name "foo"]], [1],
2643 [[input.y:1.1-34: error: %define variable 'api.value.union.name' requires keyword values
2644 input.y:1.1-34: error: %define variable 'api.value.union.name' is not used
2647 m4_popdef([AT_TEST])
2653 ## -------------- ##
2655 ## -------------- ##
2657 AT_SETUP([[Stray $ or @]])
2658 AT_BISON_OPTION_PUSHDEFS
2660 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
2661 # check that the warnings are reported once, not three times.
2663 AT_DATA_GRAMMAR([[input.y]],
2665 %token <TYPE> TOK TOK2
2666 %destructor { $%; @%; } <*> exp TOK;
2667 %initial-action { $%; @%; };
2668 %printer { $%; @%; } <*> exp TOK;
2669 %{ $ @ %} // Should not warn.
2671 exp: TOK { $%; @%; $$ = $1; }
2672 | 'a' { $<->1; $$ = 1; }
2673 | 'b' { $<foo->bar>$; }
2675 $ @ // Should not warn.
2678 AT_BISON_CHECK([[-Wall input.y]], 0, [],
2679 [[input.y:11.19: warning: stray '$' [-Wother]
2680 input.y:11.23: warning: stray '@' [-Wother]
2681 input.y:12.19: warning: stray '$' [-Wother]
2682 input.y:12.23: warning: stray '@' [-Wother]
2683 input.y:13.19: warning: stray '$' [-Wother]
2684 input.y:13.23: warning: stray '@' [-Wother]
2685 input.y:16.19: warning: stray '$' [-Wother]
2686 input.y:16.23: warning: stray '@' [-Wother]
2687 input.y:17.19: warning: stray '$' [-Wother]
2690 AT_BISON_OPTION_POPDEFS
2695 ## ---------------- ##
2696 ## Code injection. ##
2697 ## ---------------- ##
2700 AT_SETUP([[Code injection]])
2702 m4_pattern_allow([^m4_errprintn$])
2706 # Try to have MACRO be run by bison.
2707 m4_pushdef([AT_TEST],
2708 [AT_DATA([[input.y]],
2709 [[%type <$1(DEAD %type)> exp
2710 %token <$1(DEAD %token)> a
2715 $<$1(DEAD %initial-action)>$
2720 $<$1(DEAD %printer)>$
2728 $1(DEAD %parse-param)
2736 $<$1(DEAD action 1)>$
2737 $<$1(DEAD action 2)>1
2738 $<$1(DEAD action 3)>name
2739 $<$1(DEAD action 4)>0
2744 # FIXME: Provide a means to iterate over all the skeletons.
2745 AT_BISON_CHECK([[-d input.y]])
2746 AT_BISON_CHECK([[-d -S glr.c input.y]])
2747 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
2748 AT_BISON_CHECK([[-d -S glr.cc input.y]])
2749 AT_BISON_CHECK([[ -S lalr1.java input.y]])
2752 AT_TEST([m4_errprintn])
2753 AT_TEST([@:>@m4_errprintn])
2755 m4_popdef([AT_TEST])
2760 ##----------------------- ##
2761 ## Deprecated directives. ##
2762 ## ---------------------- ##
2764 AT_SETUP([[Deprecated directives]])
2766 AT_KEYWORDS([[deprec]])
2768 AT_BISON_OPTION_PUSHDEFS
2769 AT_DATA_GRAMMAR([[input.y]],
2774 %file-prefix = "foo"
2785 %output = "output.c"
2795 AT_DATA([errors-all],
2796 [[input.y:10.1-13: warning: deprecated directive: '%default_prec', use '%default-prec' [-Wdeprecated]
2797 fix-it:"input.y":{10:1-10:14}:"%default-prec"
2798 input.y:11.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
2799 fix-it:"input.y":{11:1-11:15}:"%define parse.error verbose"
2800 input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
2801 fix-it:"input.y":{12:1-12:11}:"%expect-rr"
2802 input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
2803 fix-it:"input.y":{13:1-13:15}:"%file-prefix"
2804 input.y:14.1-16.5: warning: duplicate directive: '%file-prefix\n =' [-Wother]
2805 input.y:13.1-20: note: previous declaration
2806 fix-it:"input.y":{14:1-16:6}:""
2807 input.y:17.9-27: warning: deprecated directive: '%fixed-output_files', use '%output "y.tab.c"' [-Wdeprecated]
2808 fix-it:"input.y":{17:2-17:21}:"%output \"y.tab.c\""
2809 input.y:18.9-27: warning: deprecated directive: '%fixed_output-files', use '%output "y.tab.c"' [-Wdeprecated]
2810 fix-it:"input.y":{18:9-18:28}:"%output \"y.tab.c\""
2811 input.y:19.1-19: warning: deprecated directive: '%fixed-output-files', use '%output "y.tab.c"' [-Wdeprecated]
2812 fix-it:"input.y":{19:1-19:20}:"%output \"y.tab.c\""
2813 input.y:20.1-19: warning: deprecated directive: '%name-prefix= "foo"', use '%define api.prefix {foo}' [-Wdeprecated]
2814 fix-it:"input.y":{20:1-20:20}:"%define api.prefix {foo}"
2815 input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated]
2816 fix-it:"input.y":{21:1-21:17}:"%no-default-prec"
2817 input.y:22.1-16: warning: deprecated directive: '%no_default-prec', use '%no-default-prec' [-Wdeprecated]
2818 fix-it:"input.y":{22:1-22:17}:"%no-default-prec"
2819 input.y:23.1-9: warning: deprecated directive: '%no_lines', use '%no-lines' [-Wdeprecated]
2820 fix-it:"input.y":{23:1-23:10}:"%no-lines"
2821 input.y:24.1-9: warning: deprecated directive: '%output =', use '%output' [-Wdeprecated]
2822 fix-it:"input.y":{24:1-24:10}:"%output"
2823 input.y:25.1-12: warning: deprecated directive: '%pure_parser', use '%define api.pure' [-Wdeprecated]
2824 fix-it:"input.y":{25:1-25:13}:"%define api.pure"
2825 input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated]
2826 fix-it:"input.y":{26:1-26:13}:"%token-table"
2827 input.y:27.1-14: warning: %define variable 'parse.error' redefined [-Wother]
2828 input.y:11.1-14: note: previous definition
2829 fix-it:"input.y":{27:1-27:15}:""
2830 input.y:29.1-18: warning: duplicate directive: '%name-prefix "bar"' [-Wother]
2831 input.y:13.1-20: note: previous declaration
2832 fix-it:"input.y":{29:1-29:19}:""
2833 input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
2836 AT_CHECK([cp errors-all experr])
2837 AT_BISON_CHECK([[-ffixit input.y]], [], [], [experr])
2839 AT_CHECK([[sed -e '/^fix-it:/d' errors-all >experr]])
2840 AT_BISON_CHECK([[input.y]], [], [], [experr])
2843 # Update the input file. Make sure we generated nothing.
2844 AT_CHECK([rm -f output.c])
2845 AT_CHECK([cp input.y input.y.orig])
2846 AT_CHECK([sed -e '/fix-it/d' <errors-all >experr])
2847 AT_CHECK([echo "bison: file 'input.y' was updated (backup: 'input.y~')" >>experr])
2848 AT_BISON_CHECK([[--update input.y]], [], [[]], [experr])
2851 AT_CHECK([diff input.y.orig input.y~])
2853 # Check we did not generate any file.
2854 AT_CHECK([test ! -f output.c])
2857 AT_CHECK([sed -e '1,8d' input.y], [],
2860 %define parse.error verbose
2866 %define api.prefix {foo}
2878 AT_BISON_CHECK([[input.y]])
2880 AT_BISON_OPTION_POPDEFS
2884 ## ---------------------------- ##
2885 ## Unput's effect on locations. ##
2886 ## ---------------------------- ##
2888 # When the scanner detects a deprecated construct, it unputs the
2889 # correct version, but it should *not* have any impact on the scanner
2890 # cursor. If it does, the locations of directives on the same line
2893 AT_SETUP([[Unput's effect on locations]])
2895 AT_KEYWORDS([[deprec]])
2897 AT_BISON_OPTION_PUSHDEFS
2898 AT_DATA_GRAMMAR([[input.y]],
2901 %expect_rr 42 %expect_rr 42
2903 %error_verbose %error_verbose
2908 AT_BISON_CHECK([[input.y]], [[1]], [[]],
2909 [[input.y:11.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
2910 input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
2911 input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
2912 input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
2913 input.y:13.16-29: warning: %define variable 'parse.error' redefined [-Wother]
2914 input.y:13.1-14: note: previous definition
2915 input.y:14.16-29: warning: %define variable 'parse.error' redefined [-Wother]
2916 input.y:13.16-29: note: previous definition
2917 input.y: error: reduce/reduce conflicts: 0 found, 42 expected
2918 input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
2921 AT_BISON_OPTION_POPDEFS
2925 ## -------------------------- ##
2926 ## Non-deprecated directives. ##
2927 ## -------------------------- ##
2929 AT_SETUP([[Non-deprecated directives]])
2931 AT_KEYWORDS([[deprec]])
2933 AT_BISON_OPTION_PUSHDEFS
2934 AT_DATA_GRAMMAR([[input.y]],
2937 %define parse.error verbose
2949 AT_BISON_CHECK([[input.y]], [[0]], [[]],
2950 [[input.y:14.1-15.5: warning: duplicate directive: '%file-prefix' [-Wother]
2951 input.y:13.1-18: note: previous declaration
2952 input.y: warning: %expect-rr applies only to GLR parsers [-Wother]
2953 input.y: warning: fix-its can be applied. Rerun with option '--update'. [-Wother]
2956 AT_BISON_OPTION_POPDEFS
2960 ## -------------------- ##
2961 ## Cannot type action. ##
2962 ## -------------------- ##
2964 AT_SETUP([[Cannot type action]])
2966 AT_BISON_OPTION_PUSHDEFS
2967 AT_DATA_GRAMMAR([[input.y]],
2972 AT_BISON_CHECK([[-fcaret input.y]], [[0]], [[]],
2973 [[input.y:10.6-13: warning: only midrule actions can be typed: int [-Wother]
2978 AT_BISON_OPTION_POPDEFS
2983 ## -------------------------------------- ##
2984 ## Character literals and api.token.raw. ##
2985 ## -------------------------------------- ##
2987 AT_SETUP([[Character literals and api.token.raw]])
2989 AT_BISON_OPTION_PUSHDEFS
2990 AT_DATA_GRAMMAR([[input.y]],
2991 [[%define api.token.raw
2997 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
2998 [[input.y:10.8-10: error: character literals cannot be used together with api.token.raw
3001 input.y:9.1-21: note: definition of api.token.raw
3002 9 | %define api.token.raw
3003 | ^~~~~~~~~~~~~~~~~~~~~
3004 input.y:12.6-8: error: character literals cannot be used together with api.token.raw
3005 12 | exp: 'b' "c" {}
3007 input.y:9.1-21: note: definition of api.token.raw
3008 9 | %define api.token.raw
3009 | ^~~~~~~~~~~~~~~~~~~~~
3012 AT_BISON_OPTION_POPDEFS
3017 ## ------------------------------ ##
3018 ## %token-table and parse.error. ##
3019 ## ------------------------------ ##
3021 AT_SETUP([[%token-table and parse.error]])
3023 # AT_TEST(DIRECTIVES, ERROR-LOCATION)
3024 # -----------------------------------
3025 m4_pushdef([AT_TEST],
3026 [AT_DATA([[input.y]],
3031 AT_BISON_CHECK([[input.y]], [[1]], [[]],
3032 [$2: error: '%token-table' and '%define parse.error (custom|detailed)' cannot be used together
3036 AT_TEST([%define parse.error custom %token-table], [[input.y:1.1-26]])
3037 AT_TEST([%define parse.error detailed %token-table],[[input.y:1.1-28]])
3039 m4_popdef([AT_TEST])
3043 ## --------------------------------------- ##
3044 ## Invalid file prefix mapping arguments. ##
3045 ## --------------------------------------- ##
3047 AT_SETUP([[Invalid file prefix mapping arguments]])
3049 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
3050 # --------------------------------------------
3051 m4_pushdef([AT_TEST],
3052 [AT_DATA([[input.y]],
3057 AT_BISON_CHECK([[$1 input.y]], [[1]], [[]],
3058 [[$3: error: invalid argument for '--file-prefix-map': $2
3062 AT_TEST([-M foo], [foo], [<command line>:4])
3063 AT_TEST([--file-prefix-map foo], [foo], [<command line>:4])
3064 AT_TEST([-M foo=bar -M baz], [baz], [<command line>:6])
3065 AT_TEST([-M foo= -M baz], [baz], [<command line>:6])
3067 m4_popdef([AT_TEST])