1 # Checking the Bison scanner. -*- Autotest -*-
3 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 AT_BANNER([[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 ])[ input.y], [0], [],
178 [[input.y:11.10-32: warning: unset value: $]$[
179 input.y:11.10-32: warning: unused value: $]1[
180 input.y:11.10-32: warning: unused value: $]3[
181 input.y:11.10-32: warning: unused value: $]5[
182 input.y:12.9: warning: empty rule for typed nonterminal, and no action
183 ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $$
184 input.y:13.26-41: warning: unset value: $$
185 ]]])[[input.y:13.10-62: warning: unset value: $]$[
186 input.y:13.10-62: warning: unused value: $]3[
187 input.y:13.10-62: warning: unused value: $]5[
188 ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $$
189 ]]])[[input.y:14.10-49: warning: unset value: $]$[
190 input.y:14.10-49: warning: unused value: $]3[
191 input.y:14.10-49: warning: unused value: $]5[
192 input.y:15.10-37: warning: unset value: $]$[
193 input.y:15.10-37: warning: unused value: $]3[
194 input.y:15.10-37: warning: unused value: $]5[
195 input.y:17.10-58: warning: unset value: $]$[
196 input.y:17.10-58: warning: unused value: $]1[
197 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]2[
198 ]]])[[input.y:17.10-58: warning: unused value: $]3[
199 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]4[
200 ]]])[[input.y:17.10-58: warning: unused value: $]5[
201 input.y:18.10-72: warning: unset value: $]$[
202 input.y:18.10-72: warning: unused value: $]1[
203 input.y:18.10-72: warning: unused value: $]3[
204 ]]m4_ifval($2, [[[input.y:18.10-72: warning: unused value: $]4[
205 ]]])[[input.y:18.10-72: warning: unused value: $]5[
206 ]]m4_ifval($2, [[[input.y:20.10-55: warning: unused value: $]3[
207 ]]])[[input.y:21.10-68: warning: unset value: $]$[
208 input.y:21.10-68: warning: unused value: $]1[
209 input.y:21.10-68: warning: unused value: $]2[
210 ]]m4_ifval($2, [[[input.y:21.10-68: warning: unused value: $]4[
214 ## --------------- ##
216 ## --------------- ##
218 AT_SETUP([Unused values])
219 AT_CHECK_UNUSED_VALUES
220 AT_CHECK_UNUSED_VALUES(, [1])
224 ## ------------------------------------------ ##
225 ## Unused values before symbol declarations. ##
226 ## ------------------------------------------ ##
228 AT_SETUP([Unused values before symbol declarations])
229 AT_CHECK_UNUSED_VALUES([1])
230 AT_CHECK_UNUSED_VALUES([1], [1])
234 ## --------------------------------------------- ##
235 ## Default %printer and %destructor redeclared. ##
236 ## --------------------------------------------- ##
238 AT_SETUP([Default %printer and %destructor redeclared])
241 [[%destructor { destroy ($$); } <*> <*>
242 %printer { print ($$); } <*> <*>
244 %destructor { destroy ($$); } <*>
245 %printer { print ($$); } <*>
247 %destructor { destroy ($$); } <> <>
248 %printer { print ($$); } <> <>
250 %destructor { destroy ($$); } <>
251 %printer { print ($$); } <>
257 %destructor { destroy ($$); } <*>;
258 %printer { print ($$); } <*>;
260 %destructor { destroy ($$); } <>;
261 %printer { print ($$); } <>;
264 AT_BISON_CHECK([input.y], [1], [],
265 [[input.y:1.13-29: error: redeclaration for default tagged %destructor
266 input.y:1.13-29: previous declaration
267 input.y:2.10-24: error: redeclaration for default tagged %printer
268 input.y:2.10-24: previous declaration
269 input.y:4.13-29: error: redeclaration for default tagged %destructor
270 input.y:1.13-29: previous declaration
271 input.y:5.10-24: error: redeclaration for default tagged %printer
272 input.y:2.10-24: previous declaration
273 input.y:7.13-29: error: redeclaration for default tagless %destructor
274 input.y:7.13-29: previous declaration
275 input.y:8.10-24: error: redeclaration for default tagless %printer
276 input.y:8.10-24: previous declaration
277 input.y:10.13-29: error: redeclaration for default tagless %destructor
278 input.y:7.13-29: previous declaration
279 input.y:11.10-24: error: redeclaration for default tagless %printer
280 input.y:8.10-24: previous declaration
281 input.y:17.13-29: error: redeclaration for default tagged %destructor
282 input.y:4.13-29: previous declaration
283 input.y:18.10-24: error: redeclaration for default tagged %printer
284 input.y:5.10-24: previous declaration
285 input.y:20.13-29: error: redeclaration for default tagless %destructor
286 input.y:10.13-29: previous declaration
287 input.y:21.10-24: error: redeclaration for default tagless %printer
288 input.y:11.10-24: previous declaration
294 ## ---------------------------------------------- ##
295 ## Per-type %printer and %destructor redeclared. ##
296 ## ---------------------------------------------- ##
298 AT_SETUP([Per-type %printer and %destructor redeclared])
301 [[%destructor { destroy ($$); } <field1> <field2>
302 %printer { print ($$); } <field1> <field2>
304 %destructor { destroy ($$); } <field1> <field1>
305 %printer { print ($$); } <field2> <field2>
311 %destructor { destroy ($$); } <field2> <field1>;
312 %printer { print ($$); } <field2> <field1>;
315 AT_BISON_CHECK([input.y], [1], [],
316 [[input.y:4.13-29: error: %destructor redeclaration for <field1>
317 input.y:1.13-29: previous declaration
318 input.y:4.13-29: error: %destructor redeclaration for <field1>
319 input.y:4.13-29: previous declaration
320 input.y:5.10-24: error: %printer redeclaration for <field2>
321 input.y:2.10-24: previous declaration
322 input.y:5.10-24: error: %printer redeclaration for <field2>
323 input.y:5.10-24: previous declaration
324 input.y:11.13-29: error: %destructor redeclaration for <field1>
325 input.y:4.13-29: previous declaration
326 input.y:11.13-29: error: %destructor redeclaration for <field2>
327 input.y:1.13-29: previous declaration
328 input.y:12.10-24: error: %printer redeclaration for <field1>
329 input.y:2.10-24: previous declaration
330 input.y:12.10-24: error: %printer redeclaration for <field2>
331 input.y:5.10-24: previous declaration
337 ## ---------------------------------------- ##
338 ## Unused values with default %destructor. ##
339 ## ---------------------------------------- ##
341 AT_SETUP([Unused values with default %destructor])
344 [[%destructor { destroy ($$); } <>
349 start: end end tagged tagged { $<tag>1; $3; } ;
354 AT_BISON_CHECK([input.y], [0], [],
355 [[input.y:6.8-45: warning: unset value: $$
356 input.y:6.8-45: warning: unused value: $2
357 input.y:7.6-8: warning: unset value: $$
361 [[%destructor { destroy ($$); } <*>
366 start: end end tagged tagged { $<tag>1; $3; } ;
371 AT_BISON_CHECK([input.y], [0], [],
372 [[input.y:6.8-45: warning: unused value: $4
373 input.y:8.9-11: warning: unset value: $$
379 ## ----------------------------------------- ##
380 ## Unused values with per-type %destructor. ##
381 ## ----------------------------------------- ##
383 AT_SETUP([Unused values with per-type %destructor])
386 [[%destructor { destroy ($$); } <field1>
387 %type <field1> start end
391 start: end end { $1; } ;
395 AT_BISON_CHECK([input.y], [0], [],
396 [[input.y:6.8-22: warning: unset value: $$
397 input.y:6.8-22: warning: unused value: $2
398 input.y:7.6-8: warning: unset value: $$
404 ## ---------------------- ##
405 ## Incompatible Aliases. ##
406 ## ---------------------- ##
408 AT_SETUP([Incompatible Aliases])
415 %destructor {bar} foo
420 %destructor {baz} "foo"
427 AT_BISON_CHECK([input.y], [1], [],
428 [[input.y:8.7-11: error: %type redeclaration for foo
429 input.y:3.7-11: previous declaration
430 input.y:10.13-17: error: %destructor redeclaration for foo
431 input.y:5.13-17: previous declaration
432 input.y:9.10-14: error: %printer redeclaration for foo
433 input.y:4.10-14: previous declaration
434 input.y:11.1-5: error: %left redeclaration for foo
435 input.y:6.1-5: previous declaration
442 ## ----------------------- ##
443 ## Torturing the Scanner. ##
444 ## ----------------------- ##
446 # Be sure to compile and run, so that the C compiler checks what
449 AT_SETUP([Torturing the Scanner])
451 AT_BISON_OPTION_PUSHDEFS
452 AT_DATA([input.y], [])
453 AT_BISON_CHECK([input.y], [1], [],
454 [[input.y:1.1: error: syntax error, unexpected end of file
461 AT_BISON_CHECK([input.y], [1], [],
462 [[input.y:1.1-2: error: syntax error, unexpected {...}
466 AT_DATA_GRAMMAR([input.y],
468 /* This is seen in GCC: a %{ and %} in middle of a comment. */
469 const char *foo = "So %{ and %} can be here too.";
472 /* These examples test Bison while not stressing C compilers too much.
473 Many C compilers mishandle backslash-newlines, so this part of the
474 test is inside "#if 0". The comment and string are written so that
475 the "#endif" will be seen regardless of the C compiler bugs that we
478 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
481 The Apple Darwin compiler (as of late 2002) mishandles
482 \\[newline]' within a character constant.
487 * A comment with backslash-newlines in it. %} *\
490 /* { Close the above comment, if the C compiler mishandled it. */
493 " A string with backslash-newlines in it %{ %} \\
497 char apostrophe = '\'';
504 /* %{ and %} can be here too. */
507 /* Exercise pre-prologue dependency to %union. */
511 /* Exercise M4 quoting: '@:>@@:>@', 0. */
513 /* Also exercise %union. */
516 value ival; /* A comment to exercise an old bug. */
520 /* Exercise post-prologue dependency to %union. */
522 static YYSTYPE value_as_yystype (value val);
524 /* Exercise quotes in declarations. */
525 char quote[] = "@:>@@:>@,";
535 /* Exercise quotes in strings. */
536 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
539 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
540 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
542 /* Exercise quotes in braces. */
543 char tmp[] = "@<:@%c@:>@,\n";
548 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
549 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
550 output.or.oline.opt: ;|oline;;|output;;;
551 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
553 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
556 value_as_yystype (value val)
566 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
569 static size_t toknum;
570 assert (toknum < sizeof input);
571 yylval = value_as_yystype (input[toknum]);
572 return input[toknum++];
576 # Pacify Emacs' font-lock-mode: "
590 AT_BISON_OPTION_POPDEFS
592 AT_BISON_CHECK([-d -v -o input.c input.y])
593 AT_COMPILE([input.o])
595 AT_COMPILE([input], [input.o main.o])
596 AT_PARSER_CHECK([./input], 0,
603 ## ---------------------- ##
604 ## Typed symbol aliases. ##
605 ## ---------------------- ##
607 AT_SETUP([Typed symbol aliases])
609 # Bison 2.0 broke typed symbol aliases - ensure they work.
611 AT_DATA_GRAMMAR([input.y],
616 %token <val> MY_TOKEN "MY TOKEN"
623 AT_BISON_CHECK([-o input.c input.y])
632 m4_define([AT_CHECK_REQUIRE],
633 [AT_SETUP([Require $1])
634 AT_DATA_GRAMMAR([input.y],
639 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
643 AT_CHECK_REQUIRE(1.0, 0)
644 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
645 ## FIXME: Some day augment this version number.
646 AT_CHECK_REQUIRE(100.0, 63)
649 ## ------------------------------------- ##
650 ## String aliases for character tokens. ##
651 ## ------------------------------------- ##
653 AT_SETUP([String aliases for character tokens])
655 # Bison once thought a character token and its alias were different symbols
656 # with the same user token number.
658 AT_DATA_GRAMMAR([input.y],
665 AT_BISON_CHECK([-o input.c input.y])
676 AT_BISON_OPTION_PUSHDEFS
677 AT_DATA_GRAMMAR([input.y],
679 %token WITHOUT_DASH "WITHOUT-DASH"
681 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
687 start: with-dash without_dash with.period without_period;
688 with-dash: WITH-DASH;
689 without_dash: "WITHOUT-DASH";
690 with.period: WITH.PERIOD;
691 without_period: "WITHOUT.PERIOD";
696 AT_BISON_OPTION_POPDEFS
698 # POSIX Yacc accept periods, but not dashes.
699 AT_BISON_CHECK([--yacc input.y], [1], [],
700 [[input.y:9.8-16: POSIX Yacc forbids dashes in symbol names: WITH-DASH
701 input.y:18.8-16: POSIX Yacc forbids dashes in symbol names: with-dash
704 # So warn about them.
705 AT_BISON_CHECK([-Wyacc input.y], [], [],
706 [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH
707 input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
710 # Dashes are fine for GNU Bison.
711 AT_BISON_CHECK([-o input.c input.y])
713 # Make sure we don't export silly token identifiers with periods or dashes.
714 AT_COMPILE([input.o])
717 # Periods are genuine letters, they can start identifiers.
718 # Digits and dashes cannot.
719 AT_DATA_GRAMMAR([input.y],
727 AT_BISON_CHECK([-o input.c input.y], [1], [],
728 [[input.y:10.10: error: invalid character: '-'
729 input.y:11.10-16: error: invalid identifier: '1NV4L1D'
730 input.y:12.10: error: invalid character: '-'
736 ## ----------------- ##
737 ## Numbered tokens. ##
738 ## ----------------- ##
740 AT_SETUP([Numbered tokens])
742 AT_DATA_GRAMMAR([redecl.y],
743 [[%token DECIMAL_1 11259375
744 HEXADECIMAL_1 0xabcdef
745 HEXADECIMAL_2 0xFEDCBA
748 start: DECIMAL_1 HEXADECIMAL_2;
751 AT_BISON_CHECK([redecl.y], [1], [],
752 [[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1
753 redecl.y:9.8-16: previous declaration for DECIMAL_1
754 redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2
755 redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
758 AT_DATA_GRAMMAR([too-large.y],
759 [[%token TOO_LARGE_DEC 999999999999999999999
760 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
762 start: TOO_LARGE_DEC TOO_LARGE_HEX
766 AT_BISON_CHECK([too-large.y], [1], [],
767 [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
768 too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
774 ## --------------------- ##
775 ## Unclosed constructs. ##
776 ## --------------------- ##
778 AT_SETUP([Unclosed constructs])
780 # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
781 # they were prepended to whatever it STRING_GROW'ed next. It also threw them
782 # away rather than returning them to the parser. The effect was confusing
783 # subsequent error messages.
788 %token AB "ab" // Used to complain that "ab" was already used.
791 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
797 // Used to report a syntax error because it didn't see any kind of symbol
803 // Used to report a syntax error because it didn't see braced code.
804 %destructor { free ($$)
807 AT_BISON_CHECK([-o input.c input.y], 1, [],
808 [[input.y:1.10-2.0: error: missing '"' at end of line
809 input.y:4.10-5.0: error: missing "'" at end of line
810 input.y:14.11-15.0: error: missing "'" at end of line
811 input.y:16.11-17.0: error: missing '"' at end of line
812 input.y:19.13-20.0: error: missing '}' at end of file
813 input.y:20.1: error: syntax error, unexpected end of file
816 AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [],
817 [[input.y:1.10-2.0: error: missing '"' at end of line
820 input.y:4.10-5.0: error: missing "'" at end of line
823 input.y:14.11-15.0: error: missing "'" at end of line
826 input.y:16.11-17.0: error: missing '"' at end of line
829 input.y:19.13-20.0: error: missing '}' at end of file
830 %destructor { free ($$)
832 input.y:20.1: error: syntax error, unexpected end of file
838 ## ------------------------- ##
839 ## %start after first rule. ##
840 ## ------------------------- ##
842 AT_SETUP([%start after first rule])
844 # Bison once complained that a %start after the first rule was a redeclaration
845 # of the start symbol.
854 AT_BISON_CHECK([-o input.c input.y])
859 ## --------------------- ##
860 ## %prec takes a token. ##
861 ## --------------------- ##
863 AT_SETUP([%prec takes a token])
865 # Bison once allowed %prec sym where sym was a nonterminal.
869 start: PREC %prec PREC ;
873 AT_BISON_CHECK([input.y], [1], [],
874 [[input.y:3.1-4: error: rule given for PREC, which is a token
880 ## ------------------------------- ##
881 ## %prec's token must be defined. ##
882 ## ------------------------------- ##
884 AT_SETUP([[%prec's token must be defined]])
886 # According to POSIX, a %prec token must be defined separately.
893 AT_BISON_CHECK([[input.y]], [[0]], [],
894 [[input.y:2.8-17: warning: token for %prec is not defined: PREC
900 ## -------------------------------- ##
901 ## Reject unused %code qualifiers. ##
902 ## -------------------------------- ##
904 AT_SETUP([Reject unused %code qualifiers])
914 AT_BISON_CHECK([[input-c.y]], [[1]], [],
915 [[input-c.y:1.7: error: %code qualifier 'q' is not used
916 input-c.y:2.7-9: error: %code qualifier 'bad' is not used
917 input-c.y:3.7-9: error: %code qualifier 'bad' is not used
918 input-c.y:4.7-12: error: %code qualifier 'format' is not used
921 AT_DATA([input-c-glr.y],
928 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
929 [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used
930 input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used
931 input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used
934 AT_DATA([input-c++.y],
941 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
942 [[input-c++.y:1.7: error: %code qualifier 'q' is not used
943 input-c++.y:2.7-9: error: %code qualifier 'bad' is not used
944 input-c++.y:3.8: error: %code qualifier 'q' is not used
947 AT_DATA([input-c++-glr.y],
954 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
955 [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used
956 input-c++-glr.y:2.7: error: %code qualifier 'q' is not used
957 input-c++-glr.y:3.7: error: %code qualifier 'q' is not used
960 AT_DATA([special-char-@@.y],
967 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
968 [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used
969 special-char-@@.y:2.7: error: %code qualifier 'q' is not used
970 special-char-@@.y:3.7: error: %code qualifier 'q' is not used
973 AT_DATA([special-char-@:>@.y],
980 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
981 [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used
982 special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used
983 special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used
989 ## ---------------- ##
990 ## %define errors. ##
991 ## ---------------- ##
993 AT_SETUP([%define errors])
995 AT_DATA([input-redefined.y],
996 [[%define var "value1"
999 %define special1 "@:>@"
1000 %define special2 "@<:@"
1005 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
1006 [[input-redefined.y:2.9-11: error: %define variable 'var' redefined
1007 input-redefined.y:1.9-11: previous definition
1008 input-redefined.y:3.10-12: error: %define variable 'var' redefined
1009 input-redefined.y:2.9-11: previous definition
1012 AT_DATA([input-unused.y],
1013 [[%define var "value"
1018 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
1019 [[input-unused.y:1.9-11: error: %define variable 'var' is not used
1025 ## ----------------------------------- ##
1026 ## %define, --define, --force-define. ##
1027 ## ----------------------------------- ##
1029 AT_SETUP([[%define, --define, --force-define]])
1032 [[m4@&t@_divert_push(0)@
1033 @output(b4_parser_file_name@)@
1034 [var-dd: ]b4_percent_define_get([[var-dd]])[
1035 var-ff: ]b4_percent_define_get([[var-ff]])[
1036 var-dfg: ]b4_percent_define_get([[var-dfg]])[
1037 var-fd: ]b4_percent_define_get([[var-fd]])
1038 m4@&t@_divert_pop(0)
1040 AT_DATA([[input.y]],
1041 [[%define var-dfg "gram"
1045 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
1046 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
1047 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
1048 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
1049 --skeleton ./skel.c input.y]])
1050 AT_CHECK([[cat input.tab.c]], [[0]],
1057 AT_DATA([[input-dg.y]],
1058 [[%define var "gram"
1062 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
1063 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1064 <command line>:1: previous definition
1067 AT_DATA([[input-dg.y]],
1068 [[%define var "gram"
1072 AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
1073 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1076 <command line>:2: previous definition
1079 AT_DATA([[input-unused.y]],
1083 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
1084 [[<command line>:1: error: %define variable 'unused-d' is not used
1085 <command line>:2: error: %define variable 'unused-f' is not used
1090 ## --------------------------- ##
1091 ## %define Boolean variables. ##
1092 ## --------------------------- ##
1094 AT_SETUP([[%define Boolean variables]])
1098 %define public "maybe"
1099 %define parser_class_name "Input"
1104 AT_BISON_CHECK([[Input.y]], [1], [],
1105 [[Input.y:2.9-14: error: invalid value for %define Boolean variable 'public'
1110 ## ------------------------ ##
1111 ## %define enum variables. ##
1112 ## ------------------------ ##
1114 AT_SETUP([[%define enum variables]])
1117 AT_DATA([[input.y]],
1118 [[%define lr.default-reductions bogus
1122 AT_BISON_CHECK([[input.y]], [[1]], [[]],
1123 [[input.y:1.9-29: error: invalid value for %define variable 'lr.default-reductions': 'bogus'
1124 input.y:1.9-29: accepted value: 'most'
1125 input.y:1.9-29: accepted value: 'consistent'
1126 input.y:1.9-29: accepted value: 'accepting'
1130 # FIXME: these should be indented, but we shouldn't mess with the m4 yet
1131 AT_DATA([[input.y]],
1132 [[%define api.push-pull neither
1136 AT_BISON_CHECK([[input.y]], [1], [],
1137 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1138 input.y:1.9-21: error: accepted value: 'pull'
1139 input.y:1.9-21: error: accepted value: 'push'
1140 input.y:1.9-21: error: accepted value: 'both'
1145 ## -------------------------------- ##
1146 ## %define backward compatibility. ##
1147 ## -------------------------------- ##
1149 AT_SETUP([[%define backward compatibility]])
1151 # The error messages tell us whether underscores in these variables are
1152 # being converted to dashes.
1154 AT_DATA([[input.y]],
1155 [[%define api.push_pull "neither"
1159 AT_BISON_CHECK([[input.y]], [1], [],
1160 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1161 input.y:1.9-21: error: accepted value: 'pull'
1162 input.y:1.9-21: error: accepted value: 'push'
1163 input.y:1.9-21: error: accepted value: 'both'
1166 AT_DATA([[input.y]],
1167 [[%define lr.keep_unreachable_states maybe
1171 AT_BISON_CHECK([[input.y]], [1], [],
1172 [[input.y:1.9-34: error: invalid value for %define Boolean variable 'lr.keep-unreachable-states'
1175 AT_DATA([[input.y]],
1176 [[%define foo_bar "baz"
1180 AT_BISON_CHECK([[input.y]], [[1]], [],
1181 [[input.y:1.9-15: error: %define variable 'foo_bar' is not used
1186 ## ------------------------- ##
1187 ## Unused %define api.pure. ##
1188 ## ------------------------- ##
1190 AT_SETUP([[Unused %define api.pure]])
1192 # AT_CHECK_API_PURE(DECLS, VALUE)
1193 # -------------------------------
1194 # Make sure Bison reports that `%define api.pure VALUE' is unused when DECLS
1196 m4_define([AT_CHECK_API_PURE],
1198 AT_DATA([[input.y]],
1199 [[%define api.pure ]$2[
1205 AT_BISON_CHECK([[input.y]], [[1]], [],
1206 [[input.y:1.9-16: error: %define variable 'api.pure' is not used
1210 AT_CHECK_API_PURE([[%language "c++" %defines]], [[]])
1211 AT_CHECK_API_PURE([[%language "c++" %defines]], [[false]])
1212 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[""]])
1213 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[false]])
1214 AT_CHECK_API_PURE([[%language "java"]], [[true]])
1215 AT_CHECK_API_PURE([[%language "java"]], [[false]])
1219 ## -------------------------------- ##
1220 ## C++ namespace reference errors. ##
1221 ## -------------------------------- ##
1223 AT_SETUP([[C++ namespace reference errors]])
1225 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
1226 # -------------------------------------------------------------
1227 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
1228 m4_define([AT_CHECK_NAMESPACE_ERROR],
1230 AT_DATA([[input.y]],
1233 %define namespace "]$1["
1238 AT_BISON_CHECK([[input.y]], [1], [],
1239 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
1240 [[input.y:3.9-17: error: ]b4_arg[
1244 AT_CHECK_NAMESPACE_ERROR([[]],
1245 [[namespace reference is empty]])
1246 AT_CHECK_NAMESPACE_ERROR([[ ]],
1247 [[namespace reference is empty]])
1248 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
1249 [[namespace reference has consecutive "::"]])
1250 AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]],
1251 [[namespace reference has consecutive "::"]])
1252 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
1253 [[namespace reference has consecutive "::"]])
1254 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
1255 [[namespace reference has consecutive "::"]])
1256 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]],
1257 [[namespace reference has consecutive "::"]],
1258 [[namespace reference has a trailing "::"]])
1259 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
1260 [[namespace reference has a trailing "::"]])
1261 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]],
1262 [[namespace reference has a trailing "::"]])
1263 AT_CHECK_NAMESPACE_ERROR([[::]],
1264 [[namespace reference has a trailing "::"]])
1268 ## ------------------------ ##
1269 ## Bad character literals. ##
1270 ## ------------------------ ##
1272 # Bison used to accept character literals that were empty or contained
1273 # too many characters.
1275 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
1276 # the final newline to be omitted. See the threads starting at
1277 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
1279 AT_SETUP([[Bad character literals]])
1286 AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
1288 AT_BISON_CHECK([empty.y], [1], [],
1289 [[empty.y:2.8-9: warning: empty character literal
1290 empty.y:3.8-4.0: warning: empty character literal
1291 empty.y:3.8-4.0: error: missing "'" at end of line
1292 empty.y:4.8: warning: empty character literal
1293 empty.y:4.8: error: missing "'" at end of file
1301 AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
1303 AT_BISON_CHECK([two.y], [1], [],
1304 [[two.y:2.8-11: warning: extra characters in character literal
1305 two.y:3.8-4.0: warning: extra characters in character literal
1306 two.y:3.8-4.0: error: missing "'" at end of line
1307 two.y:4.8-10: warning: extra characters in character literal
1308 two.y:4.8-10: error: missing "'" at end of file
1316 AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
1318 AT_BISON_CHECK([three.y], [1], [],
1319 [[three.y:2.8-12: warning: extra characters in character literal
1320 three.y:3.8-4.0: warning: extra characters in character literal
1321 three.y:3.8-4.0: error: missing "'" at end of line
1322 three.y:4.8-11: warning: extra characters in character literal
1323 three.y:4.8-11: error: missing "'" at end of file
1328 ## ------------------------- ##
1329 ## Bad escapes in literals. ##
1330 ## ------------------------- ##
1332 AT_SETUP([[Bad escapes in literals]])
1336 start: '\777' '\0' '\xfff' '\x0'
1337 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
1341 # It is not easy to create special characters, we cannot even trust tr.
1342 # Beside we cannot even expect "echo '\0'" to output two characters
1343 # (well three with \n): at least Bash 3.2 converts the two-character
1344 # sequence "\0" into a single NUL character.
1345 AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
1348 AT_BISON_CHECK([input.y], [1], [],
1349 [[input.y:2.9-12: error: invalid number after \-escape: 777
1350 input.y:2.8-13: warning: empty character literal
1351 input.y:2.16-17: error: invalid number after \-escape: 0
1352 input.y:2.15-18: warning: empty character literal
1353 input.y:2.21-25: error: invalid number after \-escape: xfff
1354 input.y:2.20-26: warning: empty character literal
1355 input.y:2.29-31: error: invalid number after \-escape: x0
1356 input.y:2.28-32: warning: empty character literal
1357 input.y:3.9-14: error: invalid number after \-escape: uffff
1358 input.y:3.8-15: warning: empty character literal
1359 input.y:3.18-23: error: invalid number after \-escape: u0000
1360 input.y:3.17-24: warning: empty character literal
1361 input.y:3.27-36: error: invalid number after \-escape: Uffffffff
1362 input.y:3.26-37: warning: empty character literal
1363 input.y:3.40-49: error: invalid number after \-escape: U00000000
1364 input.y:3.39-50: warning: empty character literal
1365 input.y:4.9-10: error: invalid character after \-escape: ' '
1366 input.y:4.8-11: warning: empty character literal
1367 input.y:4.14-15: error: invalid character after \-escape: A
1368 input.y:4.13-16: warning: empty character literal
1369 input.y:5.9-16: error: invalid character after \-escape: \t
1370 input.y:5.17: error: invalid character after \-escape: \f
1371 input.y:5.18: error: invalid character after \-escape: \0
1372 input.y:5.19: error: invalid character after \-escape: \001
1377 ## ------------------------- ##
1378 ## LAC: Errors for %define. ##
1379 ## ------------------------- ##
1381 AT_SETUP([[LAC: Errors for %define]])
1383 AT_DATA([[input.y]],
1388 # parse.lac.* options are useless if LAC isn't actually activated.
1389 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
1391 [[<command line>:1: error: %define variable 'parse.lac.es-capacity-initial' is not used
1393 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
1395 [[<command line>:1: error: %define variable 'parse.lac.memory-trace' is not used
1400 ## --------------------------------------------- ##
1401 ## -Werror is not affected by -Wnone and -Wall. ##
1402 ## --------------------------------------------- ##
1404 AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
1406 AT_DATA([[input.y]],
1411 # -Werror is not enabled by -Wall or equivalent.
1412 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
1413 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1415 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
1416 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1418 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
1419 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1422 # -Werror is not disabled by -Wnone or equivalent.
1423 AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]])
1424 AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]],
1425 [[bison: warnings being treated as errors
1426 input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1429 AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])
1434 ## ------------------------------------------------------ ##
1435 ## %name-prefix and %define api.prefix are incompatible. ##
1436 ## ------------------------------------------------------ ##
1438 AT_SETUP([[%name-prefix and %define api.prefix are incompatible]])
1440 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
1441 # --------------------------------------------
1442 m4_pushdef([AT_TEST],
1443 [AT_DATA([[input.y]],
1448 AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
1449 [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
1453 AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
1454 AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:1])
1455 AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:1])
1456 AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
1458 m4_popdef([AT_TEST])
1463 ## -------------- ##
1465 ## -------------- ##
1467 AT_SETUP([[Stray $ or @]])
1469 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
1470 # check that the warnings are reported once, not three times.
1472 AT_DATA_GRAMMAR([[input.y]],
1474 %destructor { $%; @%; } <*> exp TOK;
1475 %initial-action { $%; @%; };
1476 %printer { $%; @%; } <*> exp TOK;
1478 exp: TOK { $%; @%; $$ = $1; };
1481 AT_BISON_CHECK([[input.y]], 0, [],
1482 [[input.y:10.19: warning: stray '$'
1483 input.y:10.23: warning: stray '@'
1484 input.y:11.19: warning: stray '$'
1485 input.y:11.23: warning: stray '@'
1486 input.y:12.19: warning: stray '$'
1487 input.y:12.23: warning: stray '@'
1488 input.y:14.19: warning: stray '$'
1489 input.y:14.23: warning: stray '@'
1496 ## ---------------- ##
1497 ## Code injection. ##
1498 ## ---------------- ##
1501 AT_SETUP([[Code injection]])
1503 m4_pattern_allow([^m4_errprintn$])
1507 # Try to have MACRO be run by bison.
1508 m4_pushdef([AT_TEST],
1509 [AT_DATA([[input.y]],
1510 [[%type <$1(DEAD %type)> exp
1511 %token <$1(DEAD %token)> a
1515 $<$1(DEAD %initial-action)>$
1520 $<$1(DEAD %printer)>$
1528 $1(DEAD %parse-param)
1536 $<$1(DEAD action 1)>$
1537 $<$1(DEAD action 2)>1
1538 $<$1(DEAD action 3)>last
1539 $<$1(DEAD action 4)>0
1544 # FIXME: Provide a means to iterate over all the skeletons.
1545 AT_BISON_CHECK([[-d input.y]])
1546 AT_BISON_CHECK([[-d -S glr.c input.y]])
1547 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
1548 AT_BISON_CHECK([[-d -S glr.cc input.y]])
1549 AT_BISON_CHECK([[ -S lalr1.java input.y]])
1552 AT_TEST([m4_errprintn])
1553 AT_TEST([@:>@m4_errprintn])
1555 m4_popdef([AT_TEST])