1 # Checking the Bison scanner. -*- Autotest -*-
3 # Copyright (C) 2002-2013 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 ## ---------------- ##
25 ## ---------------- ##
27 AT_SETUP([Invalid inputs])
39 AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]])
41 AT_BISON_CHECK([input.y], [1], [],
42 [[input.y:1.1-2: error: invalid characters: '\0\001\002\377?'
43 input.y:3.1: error: invalid character: '?'
44 input.y:4.14: error: invalid character: '}'
45 input.y:5.1: error: invalid character: '%'
46 input.y:5.2: error: invalid character: '&'
47 input.y:6.1-17: error: invalid directive: '%a-does-not-exist'
48 input.y:7.1: error: invalid character: '%'
49 input.y:7.2: error: invalid character: '-'
50 input.y:8.1-9.0: error: missing '%}' at end of file
51 input.y:8.1-9.0: error: syntax error, unexpected %{...%}
57 AT_SETUP([Invalid inputs with {}])
59 # We used to SEGV here. See
60 # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
72 AT_BISON_CHECK([input.y], [1], [],
73 [[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...}
84 AT_SETUP([Invalid $n and @n])
92 AT_BISON_CHECK([input.y], [1], [],
93 [[input.y:2.13-14: error: integer out of range: '$1'
94 input.y:3.13-14: error: integer out of range: '@1'
104 AT_SETUP([Type Clashes])
107 [[%union { int bar; }
111 exp: foo { $$; } foo { $2; } foo
117 AT_BISON_CHECK([input.y], [1], [],
118 [[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type
119 input.y:5.24-25: error: $2 of 'exp' has no declared type
120 input.y:5.6-32: warning: type clash on default action: <bar> != <>
121 input.y:6.6-8: warning: type clash on default action: <bar> != <>
122 input.y:7.5: warning: empty rule for typed nonterminal, and no action
128 # _AT_UNUSED_VALUES_DECLARATIONS()
129 # --------------------------------
130 # Generate the token, type, and destructor
131 # declarations for the unused values tests.
133 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
134 [[[%token <integer> INT;
135 %type <integer> a b c d e f g h i j k l;
136 %destructor { destroy ($$); } INT a b c d e f g h i j k l;]]])
139 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
140 # ------------------------------------------------------------------
141 # Generate a grammar to test unused values,
142 # compile it, run it. If DECLARATIONS_AFTER
143 # is set, then the token, type, and destructor
144 # declarations are generated after the rules
145 # rather than before. If CHECK_MIDRULE_VALUES
146 # is set, then --warnings=midrule-values is
149 m4_define([AT_CHECK_UNUSED_VALUES],
154 ], [_AT_UNUSED_VALUES_DECLARATIONS
157 'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; }
158 | 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; }
159 | 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; }
162 a: INT | INT { } INT { } INT { };
163 b: INT | /* empty */;
164 c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; };
165 d: INT | INT { } INT { $]1[; } INT { $<integer>2; };
166 e: INT | INT { } INT { } INT { $]1[; };
167 f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; };
168 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
169 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
170 i: INT | INT INT { } { $]$[ = $]1[ + $]2[; };
171 j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; };
172 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
173 l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [
174 _AT_UNUSED_VALUES_DECLARATIONS])
177 AT_BISON_CHECK(m4_ifval($2, [--warnings=midrule-values ])[-fcaret input.y],
179 [[input.y:11.10-32: warning: unset value: $][$
180 a: INT | INT { } INT { } INT { };
181 ^^^^^^^^^^^^^^^^^^^^^^^
182 input.y:11.10-12: warning: unused value: $][1
183 a: INT | INT { } INT { } INT { };
185 input.y:11.18-20: warning: unused value: $][3
186 a: INT | INT { } INT { } INT { };
188 input.y:11.26-28: warning: unused value: $][5
189 a: INT | INT { } INT { } INT { };
191 input.y:12.9: warning: empty rule for typed nonterminal, and no action
192 b: INT | /* empty */;
194 ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $][$
195 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
197 input.y:13.26-41: warning: unset value: $][$
198 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
200 ]]])[[input.y:13.10-62: warning: unset value: $][$
201 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
202 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
203 input.y:13.22-24: warning: unused value: $][3
204 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
206 input.y:13.43-45: warning: unused value: $][5
207 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
209 ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $][$
210 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
212 ]]])[[input.y:14.10-49: warning: unset value: $][$
213 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
214 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
215 input.y:14.18-20: warning: unused value: $][3
216 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
218 input.y:14.30-32: warning: unused value: $][5
219 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
221 input.y:15.10-37: warning: unset value: $][$
222 e: INT | INT { } INT { } INT { $][1; };
223 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
224 input.y:15.18-20: warning: unused value: $][3
225 e: INT | INT { } INT { } INT { $][1; };
227 input.y:15.27-29: warning: unused value: $][5
228 e: INT | INT { } INT { } INT { $][1; };
230 input.y:17.10-58: warning: unset value: $][$
231 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
232 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
233 input.y:17.10-12: warning: unused value: $][1
234 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
236 ]]m4_ifval($2, [[[input.y:17.14-29: warning: unused value: $][2
237 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
239 ]]])[[input.y:17.31-33: warning: unused value: $][3
240 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
242 ]]m4_ifval($2, [[[input.y:17.35-50: warning: unused value: $][4
243 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
245 ]]])[[input.y:17.52-54: warning: unused value: $][5
246 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
248 input.y:18.10-72: warning: unset value: $][$
249 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
250 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
251 input.y:18.10-12: warning: unused value: $][1
252 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
254 input.y:18.31-33: warning: unused value: $][3
255 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
257 ]]m4_ifval($2, [[[input.y:18.35-64: warning: unused value: $][4
258 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
259 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
260 ]]])[[input.y:18.66-68: warning: unused value: $][5
261 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
263 ]]m4_ifval($2, [[[input.y:20.18-37: warning: unused value: $][3
264 j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
266 ]]])[[input.y:21.10-68: warning: unset value: $][$
267 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
268 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
269 input.y:21.10-12: warning: unused value: $][1
270 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
272 input.y:21.14-16: warning: unused value: $][2
273 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
275 ]]m4_ifval($2, [[[input.y:21.35-64: warning: unused value: $][4
276 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
277 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
281 ## --------------- ##
283 ## --------------- ##
285 AT_SETUP([Unused values])
286 AT_CHECK_UNUSED_VALUES
287 AT_CHECK_UNUSED_VALUES(, [1])
291 ## ------------------------------------------ ##
292 ## Unused values before symbol declarations. ##
293 ## ------------------------------------------ ##
295 AT_SETUP([Unused values before symbol declarations])
296 AT_CHECK_UNUSED_VALUES([1])
297 AT_CHECK_UNUSED_VALUES([1], [1])
301 ## --------------------------------------------- ##
302 ## Default %printer and %destructor redeclared. ##
303 ## --------------------------------------------- ##
305 AT_SETUP([Default %printer and %destructor redeclared])
308 [[%destructor { destroy ($$); } <*> <*>
309 %printer { print ($$); } <*> <*>
311 %destructor { destroy ($$); } <*>
312 %printer { print ($$); } <*>
314 %destructor { destroy ($$); } <> <>
315 %printer { print ($$); } <> <>
317 %destructor { destroy ($$); } <>
318 %printer { print ($$); } <>
324 %destructor { destroy ($$); } <*>;
325 %printer { print ($$); } <*>;
327 %destructor { destroy ($$); } <>;
328 %printer { print ($$); } <>;
331 AT_BISON_CHECK([input.y], [1], [],
332 [[input.y:1.13-29: error: redeclaration for default tagged %destructor
333 input.y:1.13-29: previous declaration
334 input.y:2.10-24: error: redeclaration for default tagged %printer
335 input.y:2.10-24: previous declaration
336 input.y:4.13-29: error: redeclaration for default tagged %destructor
337 input.y:1.13-29: previous declaration
338 input.y:5.10-24: error: redeclaration for default tagged %printer
339 input.y:2.10-24: previous declaration
340 input.y:7.13-29: error: redeclaration for default tagless %destructor
341 input.y:7.13-29: previous declaration
342 input.y:8.10-24: error: redeclaration for default tagless %printer
343 input.y:8.10-24: previous declaration
344 input.y:10.13-29: error: redeclaration for default tagless %destructor
345 input.y:7.13-29: previous declaration
346 input.y:11.10-24: error: redeclaration for default tagless %printer
347 input.y:8.10-24: previous declaration
348 input.y:17.13-29: error: redeclaration for default tagged %destructor
349 input.y:4.13-29: previous declaration
350 input.y:18.10-24: error: redeclaration for default tagged %printer
351 input.y:5.10-24: previous declaration
352 input.y:20.13-29: error: redeclaration for default tagless %destructor
353 input.y:10.13-29: previous declaration
354 input.y:21.10-24: error: redeclaration for default tagless %printer
355 input.y:11.10-24: previous declaration
361 ## ---------------------------------------------- ##
362 ## Per-type %printer and %destructor redeclared. ##
363 ## ---------------------------------------------- ##
365 AT_SETUP([Per-type %printer and %destructor redeclared])
368 [[%destructor { destroy ($$); } <field1> <field2>
369 %printer { print ($$); } <field1> <field2>
371 %destructor { destroy ($$); } <field1> <field1>
372 %printer { print ($$); } <field2> <field2>
378 %destructor { destroy ($$); } <field2> <field1>;
379 %printer { print ($$); } <field2> <field1>;
382 AT_BISON_CHECK([input.y], [1], [],
383 [[input.y:4.13-29: error: %destructor redeclaration for <field1>
384 input.y:1.13-29: previous declaration
385 input.y:4.13-29: error: %destructor redeclaration for <field1>
386 input.y:4.13-29: previous declaration
387 input.y:5.10-24: error: %printer redeclaration for <field2>
388 input.y:2.10-24: previous declaration
389 input.y:5.10-24: error: %printer redeclaration for <field2>
390 input.y:5.10-24: previous declaration
391 input.y:11.13-29: error: %destructor redeclaration for <field1>
392 input.y:4.13-29: previous declaration
393 input.y:11.13-29: error: %destructor redeclaration for <field2>
394 input.y:1.13-29: previous declaration
395 input.y:12.10-24: error: %printer redeclaration for <field1>
396 input.y:2.10-24: previous declaration
397 input.y:12.10-24: error: %printer redeclaration for <field2>
398 input.y:5.10-24: previous declaration
404 ## ---------------------------------------- ##
405 ## Unused values with default %destructor. ##
406 ## ---------------------------------------- ##
408 AT_SETUP([Unused values with default %destructor])
411 [[%destructor { destroy ($$); } <>
416 start: end end tagged tagged { $<tag>1; $3; } ;
421 AT_BISON_CHECK([input.y], [0], [],
422 [[input.y:6.8-45: warning: unset value: $$
423 input.y:6.12-14: warning: unused value: $2
424 input.y:7.6-8: warning: unset value: $$
428 [[%destructor { destroy ($$); } <*>
433 start: end end tagged tagged { $<tag>1; $3; } ;
438 AT_BISON_CHECK([input.y], [0], [],
439 [[input.y:6.23-28: warning: unused value: $4
440 input.y:8.9-11: warning: unset value: $$
446 ## ----------------------------------------- ##
447 ## Unused values with per-type %destructor. ##
448 ## ----------------------------------------- ##
450 AT_SETUP([Unused values with per-type %destructor])
453 [[%destructor { destroy ($$); } <field1>
454 %type <field1> start end
458 start: end end { $1; } ;
462 AT_BISON_CHECK([input.y], [0], [],
463 [[input.y:6.8-22: warning: unset value: $$
464 input.y:6.12-14: warning: unused value: $2
465 input.y:7.6-8: warning: unset value: $$
471 ## ---------------------- ##
472 ## Incompatible Aliases. ##
473 ## ---------------------- ##
475 AT_SETUP([Incompatible Aliases])
482 %destructor {bar} foo
487 %destructor {baz} "foo"
494 AT_BISON_CHECK([input.y], [1], [],
495 [[input.y:8.7-11: error: %type redeclaration for foo
496 input.y:3.7-11: previous declaration
497 input.y:10.13-17: error: %destructor redeclaration for foo
498 input.y:5.13-17: previous declaration
499 input.y:9.10-14: error: %printer redeclaration for foo
500 input.y:4.10-14: previous declaration
501 input.y:11.1-5: error: %left redeclaration for foo
502 input.y:6.1-5: previous declaration
509 ## ----------------------- ##
510 ## Torturing the Scanner. ##
511 ## ----------------------- ##
513 # Be sure to compile and run, so that the C compiler checks what
516 AT_SETUP([Torturing the Scanner])
518 AT_BISON_OPTION_PUSHDEFS
519 AT_DATA([input.y], [])
520 AT_BISON_CHECK([input.y], [1], [],
521 [[input.y:1.1: error: syntax error, unexpected end of file
528 AT_BISON_CHECK([input.y], [1], [],
529 [[input.y:1.1-2: error: syntax error, unexpected {...}
533 AT_DATA_GRAMMAR([input.y],
535 /* This is seen in GCC: a %{ and %} in middle of a comment. */
536 const char *foo = "So %{ and %} can be here too.";
539 /* These examples test Bison while not stressing C compilers too much.
540 Many C compilers mishandle backslash-newlines, so this part of the
541 test is inside "#if 0". The comment and string are written so that
542 the "#endif" will be seen regardless of the C compiler bugs that we
545 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
548 The Apple Darwin compiler (as of late 2002) mishandles
549 \\[newline]' within a character constant.
554 * A comment with backslash-newlines in it. %} *\
557 /* { Close the above comment, if the C compiler mishandled it. */
560 " A string with backslash-newlines in it %{ %} \\
564 char apostrophe = '\'';
571 /* %{ and %} can be here too. */
574 /* Exercise pre-prologue dependency to %union. */
578 /* Exercise M4 quoting: '@:>@@:>@', 0. */
580 /* Also exercise %union. */
583 value ival; /* A comment to exercise an old bug. */
587 /* Exercise post-prologue dependency to %union. */
589 static YYSTYPE value_as_yystype (value val);
591 /* Exercise quotes in declarations. */
592 char quote[] = "@:>@@:>@,";
602 /* Exercise quotes in strings. */
603 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
606 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
607 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
609 /* Exercise quotes in braces. */
610 char tmp[] = "@<:@%c@:>@,\n";
615 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
616 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
617 output.or.oline.opt: ;|oline;;|output;;;
618 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
620 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
623 value_as_yystype (value val)
633 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
636 static size_t toknum;
637 assert (toknum < sizeof input);
638 yylval = value_as_yystype (input[toknum]);
639 return input[toknum++];
643 # Pacify Emacs' font-lock-mode: "
657 AT_BISON_OPTION_POPDEFS
659 AT_BISON_CHECK([-d -v -o input.c input.y])
660 AT_COMPILE([input.o])
662 AT_COMPILE([input], [input.o main.o])
663 AT_PARSER_CHECK([./input], 0,
670 ## ---------------------- ##
671 ## Typed symbol aliases. ##
672 ## ---------------------- ##
674 AT_SETUP([Typed symbol aliases])
676 # Bison 2.0 broke typed symbol aliases - ensure they work.
678 AT_DATA_GRAMMAR([input.y],
683 %token <val> MY_TOKEN "MY TOKEN"
690 AT_BISON_CHECK([-o input.c input.y])
699 m4_define([AT_CHECK_REQUIRE],
700 [AT_SETUP([Require $1])
701 AT_DATA_GRAMMAR([input.y],
706 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
710 AT_CHECK_REQUIRE(1.0, 0)
711 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
712 ## FIXME: Some day augment this version number.
713 AT_CHECK_REQUIRE(100.0, 63)
716 ## ------------------------------------- ##
717 ## String aliases for character tokens. ##
718 ## ------------------------------------- ##
720 AT_SETUP([String aliases for character tokens])
722 # Bison once thought a character token and its alias were different symbols
723 # with the same user token number.
725 AT_DATA_GRAMMAR([input.y],
732 AT_BISON_CHECK([-o input.c input.y])
743 AT_BISON_OPTION_PUSHDEFS
744 AT_DATA_GRAMMAR([input.y],
746 %token WITHOUT_DASH "WITHOUT-DASH"
748 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
754 start: with-dash without_dash with.period without_period;
755 with-dash: WITH-DASH;
756 without_dash: "WITHOUT-DASH";
757 with.period: WITH.PERIOD;
758 without_period: "WITHOUT.PERIOD";
763 AT_BISON_OPTION_POPDEFS
765 # POSIX Yacc accept periods, but not dashes.
766 AT_BISON_CHECK([--yacc input.y], [1], [],
767 [[input.y:9.8-16: POSIX Yacc forbids dashes in symbol names: WITH-DASH
768 input.y:18.8-16: POSIX Yacc forbids dashes in symbol names: with-dash
771 # So warn about them.
772 AT_BISON_CHECK([-Wyacc input.y], [], [],
773 [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH
774 input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
777 # Dashes are fine for GNU Bison.
778 AT_BISON_CHECK([-o input.c input.y])
780 # Make sure we don't export silly token identifiers with periods or dashes.
781 AT_COMPILE([input.o])
784 # Periods are genuine letters, they can start identifiers.
785 # Digits and dashes cannot.
786 AT_DATA_GRAMMAR([input.y],
794 AT_BISON_CHECK([-o input.c input.y], [1], [],
795 [[input.y:10.10: error: invalid character: '-'
796 input.y:11.10-16: error: invalid identifier: '1NV4L1D'
797 input.y:12.10: error: invalid character: '-'
803 ## ----------------- ##
804 ## Numbered tokens. ##
805 ## ----------------- ##
807 AT_SETUP([Numbered tokens])
809 AT_DATA_GRAMMAR([redecl.y],
810 [[%token DECIMAL_1 11259375
811 HEXADECIMAL_1 0xabcdef
812 HEXADECIMAL_2 0xFEDCBA
815 start: DECIMAL_1 HEXADECIMAL_2;
818 AT_BISON_CHECK([redecl.y], [1], [],
819 [[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1
820 redecl.y:9.8-16: previous declaration for DECIMAL_1
821 redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2
822 redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
825 AT_DATA_GRAMMAR([too-large.y],
826 [[%token TOO_LARGE_DEC 999999999999999999999
827 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
829 start: TOO_LARGE_DEC TOO_LARGE_HEX
833 AT_BISON_CHECK([too-large.y], [1], [],
834 [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
835 too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
841 ## --------------------- ##
842 ## Unclosed constructs. ##
843 ## --------------------- ##
845 AT_SETUP([Unclosed constructs])
847 # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
848 # they were prepended to whatever it STRING_GROW'ed next. It also threw them
849 # away rather than returning them to the parser. The effect was confusing
850 # subsequent error messages.
855 %token AB "ab" // Used to complain that "ab" was already used.
858 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
864 // Used to report a syntax error because it didn't see any kind of symbol
870 // Used to report a syntax error because it didn't see braced code.
871 %destructor { free ($$)
874 AT_BISON_CHECK([-o input.c input.y], 1, [],
875 [[input.y:1.10-2.0: error: missing '"' at end of line
876 input.y:4.10-5.0: error: missing "'" at end of line
877 input.y:14.11-15.0: error: missing "'" at end of line
878 input.y:16.11-17.0: error: missing '"' at end of line
879 input.y:19.13-20.0: error: missing '}' at end of file
880 input.y:20.1: error: syntax error, unexpected end of file
883 AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [],
884 [[input.y:1.10-2.0: error: missing '"' at end of line
887 input.y:4.10-5.0: error: missing "'" at end of line
890 input.y:14.11-15.0: error: missing "'" at end of line
893 input.y:16.11-17.0: error: missing '"' at end of line
896 input.y:19.13-20.0: error: missing '}' at end of file
897 %destructor { free ($$)
899 input.y:20.1: error: syntax error, unexpected end of file
905 ## ------------------------- ##
906 ## %start after first rule. ##
907 ## ------------------------- ##
909 AT_SETUP([%start after first rule])
911 # Bison once complained that a %start after the first rule was a redeclaration
912 # of the start symbol.
921 AT_BISON_CHECK([-o input.c input.y])
926 ## --------------------- ##
927 ## %prec takes a token. ##
928 ## --------------------- ##
930 AT_SETUP([%prec takes a token])
932 # Bison once allowed %prec sym where sym was a nonterminal.
936 start: PREC %prec PREC ;
940 AT_BISON_CHECK([input.y], [1], [],
941 [[input.y:3.1-4: error: rule given for PREC, which is a token
947 ## ------------------------------- ##
948 ## %prec's token must be defined. ##
949 ## ------------------------------- ##
951 AT_SETUP([[%prec's token must be defined]])
953 # According to POSIX, a %prec token must be defined separately.
960 AT_BISON_CHECK([[input.y]], [[0]], [],
961 [[input.y:2.8-17: warning: token for %prec is not defined: PREC
967 ## -------------------------------- ##
968 ## Reject unused %code qualifiers. ##
969 ## -------------------------------- ##
971 AT_SETUP([Reject unused %code qualifiers])
981 AT_BISON_CHECK([[input-c.y]], [[1]], [],
982 [[input-c.y:1.7: error: %code qualifier 'q' is not used
983 input-c.y:2.7-9: error: %code qualifier 'bad' is not used
984 input-c.y:3.7-9: error: %code qualifier 'bad' is not used
985 input-c.y:4.7-12: error: %code qualifier 'format' is not used
988 AT_DATA([input-c-glr.y],
995 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
996 [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used
997 input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used
998 input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used
1001 AT_DATA([input-c++.y],
1008 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
1009 [[input-c++.y:1.7: error: %code qualifier 'q' is not used
1010 input-c++.y:2.7-9: error: %code qualifier 'bad' is not used
1011 input-c++.y:3.8: error: %code qualifier 'q' is not used
1014 AT_DATA([input-c++-glr.y],
1021 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
1022 [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used
1023 input-c++-glr.y:2.7: error: %code qualifier 'q' is not used
1024 input-c++-glr.y:3.7: error: %code qualifier 'q' is not used
1027 AT_DATA([special-char-@@.y],
1034 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
1035 [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used
1036 special-char-@@.y:2.7: error: %code qualifier 'q' is not used
1037 special-char-@@.y:3.7: error: %code qualifier 'q' is not used
1040 AT_DATA([special-char-@:>@.y],
1047 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
1048 [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used
1049 special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used
1050 special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used
1056 ## ---------------- ##
1057 ## %define errors. ##
1058 ## ---------------- ##
1060 AT_SETUP([%define errors])
1062 AT_DATA([input-redefined.y],
1063 [[%define var "value1"
1064 %define var "value1"
1065 %define var "value2"
1066 %define special1 "@:>@"
1067 %define special2 "@<:@"
1072 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
1073 [[input-redefined.y:2.9-11: error: %define variable 'var' redefined
1074 input-redefined.y:1.9-11: previous definition
1075 input-redefined.y:3.10-12: error: %define variable 'var' redefined
1076 input-redefined.y:2.9-11: previous definition
1079 AT_DATA([input-unused.y],
1080 [[%define var "value"
1085 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
1086 [[input-unused.y:1.9-11: error: %define variable 'var' is not used
1092 ## ----------------------------------- ##
1093 ## %define, --define, --force-define. ##
1094 ## ----------------------------------- ##
1096 AT_SETUP([[%define, --define, --force-define]])
1099 [[m4@&t@_divert_push(0)@
1100 @output(b4_parser_file_name@)@
1101 [var-dd: ]b4_percent_define_get([[var-dd]])[
1102 var-ff: ]b4_percent_define_get([[var-ff]])[
1103 var-dfg: ]b4_percent_define_get([[var-dfg]])[
1104 var-fd: ]b4_percent_define_get([[var-fd]])
1105 m4@&t@_divert_pop(0)
1107 AT_DATA([[input.y]],
1108 [[%define var-dfg "gram"
1112 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
1113 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
1114 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
1115 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
1116 --skeleton ./skel.c input.y]])
1117 AT_CHECK([[cat input.tab.c]], [[0]],
1124 AT_DATA([[input-dg.y]],
1125 [[%define var "gram"
1129 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
1130 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1131 <command line>:1: previous definition
1134 AT_DATA([[input-dg.y]],
1135 [[%define var "gram"
1139 AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
1140 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1143 <command line>:2: previous definition
1146 AT_DATA([[input-unused.y]],
1150 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
1151 [[<command line>:1: error: %define variable 'unused-d' is not used
1152 <command line>:2: error: %define variable 'unused-f' is not used
1157 ## --------------------------- ##
1158 ## %define Boolean variables. ##
1159 ## --------------------------- ##
1161 AT_SETUP([[%define Boolean variables]])
1165 %define public "maybe"
1166 %define parser_class_name "Input"
1171 AT_BISON_CHECK([[Input.y]], [1], [],
1172 [[Input.y:2.9-14: error: invalid value for %define Boolean variable 'public'
1177 ## ------------------------ ##
1178 ## %define enum variables. ##
1179 ## ------------------------ ##
1181 AT_SETUP([[%define enum variables]])
1184 AT_DATA([[input.y]],
1185 [[%define lr.default-reductions bogus
1189 AT_BISON_CHECK([[input.y]], [[1]], [[]],
1190 [[input.y:1.9-29: error: invalid value for %define variable 'lr.default-reductions': 'bogus'
1191 input.y:1.9-29: accepted value: 'most'
1192 input.y:1.9-29: accepted value: 'consistent'
1193 input.y:1.9-29: accepted value: 'accepting'
1197 # FIXME: these should be indented, but we shouldn't mess with the m4 yet
1198 AT_DATA([[input.y]],
1199 [[%define api.push-pull neither
1203 AT_BISON_CHECK([[input.y]], [1], [],
1204 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1205 input.y:1.9-21: error: accepted value: 'pull'
1206 input.y:1.9-21: error: accepted value: 'push'
1207 input.y:1.9-21: error: accepted value: 'both'
1212 ## -------------------------------- ##
1213 ## %define backward compatibility. ##
1214 ## -------------------------------- ##
1216 AT_SETUP([[%define backward compatibility]])
1218 # The error messages tell us whether underscores in these variables are
1219 # being converted to dashes.
1221 AT_DATA([[input.y]],
1222 [[%define api.push_pull "neither"
1226 AT_BISON_CHECK([[input.y]], [1], [],
1227 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1228 input.y:1.9-21: error: accepted value: 'pull'
1229 input.y:1.9-21: error: accepted value: 'push'
1230 input.y:1.9-21: error: accepted value: 'both'
1233 AT_DATA([[input.y]],
1234 [[%define lr.keep_unreachable_states maybe
1238 AT_BISON_CHECK([[input.y]], [1], [],
1239 [[input.y:1.9-34: error: invalid value for %define Boolean variable 'lr.keep-unreachable-states'
1242 AT_DATA([[input.y]],
1243 [[%define foo_bar "baz"
1247 AT_BISON_CHECK([[input.y]], [[1]], [],
1248 [[input.y:1.9-15: error: %define variable 'foo_bar' is not used
1253 ## ------------------------- ##
1254 ## Unused %define api.pure. ##
1255 ## ------------------------- ##
1257 AT_SETUP([[Unused %define api.pure]])
1259 # AT_CHECK_API_PURE(DECLS, VALUE)
1260 # -------------------------------
1261 # Make sure Bison reports that `%define api.pure VALUE' is unused when DECLS
1263 m4_define([AT_CHECK_API_PURE],
1265 AT_DATA([[input.y]],
1266 [[%define api.pure ]$2[
1272 AT_BISON_CHECK([[input.y]], [[1]], [],
1273 [[input.y:1.9-16: error: %define variable 'api.pure' is not used
1277 AT_CHECK_API_PURE([[%language "c++" %defines]], [[]])
1278 AT_CHECK_API_PURE([[%language "c++" %defines]], [[false]])
1279 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[""]])
1280 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[false]])
1281 AT_CHECK_API_PURE([[%language "java"]], [[true]])
1282 AT_CHECK_API_PURE([[%language "java"]], [[false]])
1286 ## -------------------------------- ##
1287 ## C++ namespace reference errors. ##
1288 ## -------------------------------- ##
1290 AT_SETUP([[C++ namespace reference errors]])
1292 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
1293 # -------------------------------------------------------------
1294 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
1295 m4_define([AT_CHECK_NAMESPACE_ERROR],
1297 AT_DATA([[input.y]],
1300 %define namespace "]$1["
1305 AT_BISON_CHECK([[input.y]], [1], [],
1306 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
1307 [[input.y:3.9-17: error: ]b4_arg[
1311 AT_CHECK_NAMESPACE_ERROR([[]],
1312 [[namespace reference is empty]])
1313 AT_CHECK_NAMESPACE_ERROR([[ ]],
1314 [[namespace reference is empty]])
1315 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
1316 [[namespace reference has consecutive "::"]])
1317 AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]],
1318 [[namespace reference has consecutive "::"]])
1319 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
1320 [[namespace reference has consecutive "::"]])
1321 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
1322 [[namespace reference has consecutive "::"]])
1323 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]],
1324 [[namespace reference has consecutive "::"]],
1325 [[namespace reference has a trailing "::"]])
1326 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
1327 [[namespace reference has a trailing "::"]])
1328 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]],
1329 [[namespace reference has a trailing "::"]])
1330 AT_CHECK_NAMESPACE_ERROR([[::]],
1331 [[namespace reference has a trailing "::"]])
1335 ## ------------------------ ##
1336 ## Bad character literals. ##
1337 ## ------------------------ ##
1339 # Bison used to accept character literals that were empty or contained
1340 # too many characters.
1342 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
1343 # the final newline to be omitted. See the threads starting at
1344 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
1346 AT_SETUP([[Bad character literals]])
1353 AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
1355 AT_BISON_CHECK([empty.y], [1], [],
1356 [[empty.y:2.8-9: warning: empty character literal
1357 empty.y:3.8-4.0: warning: empty character literal
1358 empty.y:3.8-4.0: error: missing "'" at end of line
1359 empty.y:4.8: warning: empty character literal
1360 empty.y:4.8: error: missing "'" at end of file
1368 AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
1370 AT_BISON_CHECK([two.y], [1], [],
1371 [[two.y:2.8-11: warning: extra characters in character literal
1372 two.y:3.8-4.0: warning: extra characters in character literal
1373 two.y:3.8-4.0: error: missing "'" at end of line
1374 two.y:4.8-10: warning: extra characters in character literal
1375 two.y:4.8-10: error: missing "'" at end of file
1383 AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
1385 AT_BISON_CHECK([three.y], [1], [],
1386 [[three.y:2.8-12: warning: extra characters in character literal
1387 three.y:3.8-4.0: warning: extra characters in character literal
1388 three.y:3.8-4.0: error: missing "'" at end of line
1389 three.y:4.8-11: warning: extra characters in character literal
1390 three.y:4.8-11: error: missing "'" at end of file
1395 ## ------------------------- ##
1396 ## Bad escapes in literals. ##
1397 ## ------------------------- ##
1399 AT_SETUP([[Bad escapes in literals]])
1403 start: '\777' '\0' '\xfff' '\x0'
1404 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
1408 # It is not easy to create special characters, we cannot even trust tr.
1409 # Beside we cannot even expect "echo '\0'" to output two characters
1410 # (well three with \n): at least Bash 3.2 converts the two-character
1411 # sequence "\0" into a single NUL character.
1412 AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
1415 AT_BISON_CHECK([input.y], [1], [],
1416 [[input.y:2.9-12: error: invalid number after \-escape: 777
1417 input.y:2.8-13: warning: empty character literal
1418 input.y:2.16-17: error: invalid number after \-escape: 0
1419 input.y:2.15-18: warning: empty character literal
1420 input.y:2.21-25: error: invalid number after \-escape: xfff
1421 input.y:2.20-26: warning: empty character literal
1422 input.y:2.29-31: error: invalid number after \-escape: x0
1423 input.y:2.28-32: warning: empty character literal
1424 input.y:3.9-14: error: invalid number after \-escape: uffff
1425 input.y:3.8-15: warning: empty character literal
1426 input.y:3.18-23: error: invalid number after \-escape: u0000
1427 input.y:3.17-24: warning: empty character literal
1428 input.y:3.27-36: error: invalid number after \-escape: Uffffffff
1429 input.y:3.26-37: warning: empty character literal
1430 input.y:3.40-49: error: invalid number after \-escape: U00000000
1431 input.y:3.39-50: warning: empty character literal
1432 input.y:4.9-10: error: invalid character after \-escape: ' '
1433 input.y:4.8-11: warning: empty character literal
1434 input.y:4.14-15: error: invalid character after \-escape: A
1435 input.y:4.13-16: warning: empty character literal
1436 input.y:5.9-16: error: invalid character after \-escape: \t
1437 input.y:5.17: error: invalid character after \-escape: \f
1438 input.y:5.18: error: invalid character after \-escape: \0
1439 input.y:5.19: error: invalid character after \-escape: \001
1444 ## ------------------------- ##
1445 ## LAC: Errors for %define. ##
1446 ## ------------------------- ##
1448 AT_SETUP([[LAC: Errors for %define]])
1450 AT_DATA([[input.y]],
1455 # parse.lac.* options are useless if LAC isn't actually activated.
1456 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
1458 [[<command line>:1: error: %define variable 'parse.lac.es-capacity-initial' is not used
1460 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
1462 [[<command line>:1: error: %define variable 'parse.lac.memory-trace' is not used
1467 ## --------------------------------------------- ##
1468 ## -Werror is not affected by -Wnone and -Wall. ##
1469 ## --------------------------------------------- ##
1471 AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
1473 AT_DATA([[input.y]],
1478 # -Werror is not enabled by -Wall or equivalent.
1479 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
1480 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1482 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
1483 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1485 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
1486 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1489 # -Werror is not disabled by -Wnone or equivalent.
1490 AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]])
1491 AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]],
1492 [[bison: warnings being treated as errors
1493 input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1496 AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])
1501 ## ------------------------------------------------------ ##
1502 ## %name-prefix and %define api.prefix are incompatible. ##
1503 ## ------------------------------------------------------ ##
1505 AT_SETUP([[%name-prefix and %define api.prefix are incompatible]])
1507 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
1508 # --------------------------------------------
1509 m4_pushdef([AT_TEST],
1510 [AT_DATA([[input.y]],
1515 AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
1516 [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
1520 AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
1521 AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:1])
1522 AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:1])
1523 AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
1525 m4_popdef([AT_TEST])
1530 ## -------------- ##
1532 ## -------------- ##
1534 AT_SETUP([[Stray $ or @]])
1536 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
1537 # check that the warnings are reported once, not three times.
1539 AT_DATA_GRAMMAR([[input.y]],
1541 %destructor { $%; @%; } <*> exp TOK;
1542 %initial-action { $%; @%; };
1543 %printer { $%; @%; } <*> exp TOK;
1545 exp: TOK { $%; @%; $$ = $1; };
1548 AT_BISON_CHECK([[input.y]], 0, [],
1549 [[input.y:10.19: warning: stray '$'
1550 input.y:10.23: warning: stray '@'
1551 input.y:11.19: warning: stray '$'
1552 input.y:11.23: warning: stray '@'
1553 input.y:12.19: warning: stray '$'
1554 input.y:12.23: warning: stray '@'
1555 input.y:14.19: warning: stray '$'
1556 input.y:14.23: warning: stray '@'
1563 ## ---------------- ##
1564 ## Code injection. ##
1565 ## ---------------- ##
1568 AT_SETUP([[Code injection]])
1570 m4_pattern_allow([^m4_errprintn$])
1574 # Try to have MACRO be run by bison.
1575 m4_pushdef([AT_TEST],
1576 [AT_DATA([[input.y]],
1577 [[%type <$1(DEAD %type)> exp
1578 %token <$1(DEAD %token)> a
1582 $<$1(DEAD %initial-action)>$
1587 $<$1(DEAD %printer)>$
1595 $1(DEAD %parse-param)
1603 $<$1(DEAD action 1)>$
1604 $<$1(DEAD action 2)>1
1605 $<$1(DEAD action 3)>last
1606 $<$1(DEAD action 4)>0
1611 # FIXME: Provide a means to iterate over all the skeletons.
1612 AT_BISON_CHECK([[-d input.y]])
1613 AT_BISON_CHECK([[-d -S glr.c input.y]])
1614 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
1615 AT_BISON_CHECK([[-d -S glr.cc input.y]])
1616 AT_BISON_CHECK([[ -S lalr1.java input.y]])
1619 AT_TEST([m4_errprintn])
1620 AT_TEST([@:>@m4_errprintn])
1622 m4_popdef([AT_TEST])