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: error: invalid character: '\0'
43 input.y:1.1: error: invalid character: '\001'
44 input.y:1.1: error: invalid character: '\002'
45 input.y:1.1: error: invalid character: '\377'
46 input.y:1.2: error: invalid character: '?'
47 input.y:3.1: error: invalid character: '?'
48 input.y:4.14: error: invalid character: '}'
49 input.y:5.1: error: invalid character: '%'
50 input.y:5.2: error: invalid character: '&'
51 input.y:6.1-17: error: invalid directive: '%a-does-not-exist'
52 input.y:7.1: error: invalid character: '%'
53 input.y:7.2: error: invalid character: '-'
54 input.y:8.1-9.0: error: missing '%}' at end of file
55 input.y:8.1-9.0: error: syntax error, unexpected %{...%}
61 AT_SETUP([Invalid inputs with {}])
63 # We used to SEGV here. See
64 # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
76 AT_BISON_CHECK([input.y], [1], [],
77 [[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...}
88 AT_SETUP([Invalid $n and @n])
96 AT_BISON_CHECK([input.y], [1], [],
97 [[input.y:2.13-14: error: integer out of range: '$1'
98 input.y:3.13-14: error: integer out of range: '@1'
108 AT_SETUP([Type Clashes])
111 [[%union { int bar; }
115 exp: foo { $$; } foo { $2; } foo
121 AT_BISON_CHECK([input.y], [1], [],
122 [[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type
123 input.y:5.24-25: error: $2 of 'exp' has no declared type
124 input.y:5.6-32: warning: type clash on default action: <bar> != <>
125 input.y:6.6-8: warning: type clash on default action: <bar> != <>
126 input.y:7.5: warning: empty rule for typed nonterminal, and no action
132 # _AT_UNUSED_VALUES_DECLARATIONS()
133 # --------------------------------
134 # Generate the token, type, and destructor
135 # declarations for the unused values tests.
137 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
138 [[[%token <integer> INT;
139 %type <integer> a b c d e f g h i j k l;
140 %destructor { destroy ($$); } INT a b c d e f g h i j k l;]]])
143 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
144 # ------------------------------------------------------------------
145 # Generate a grammar to test unused values,
146 # compile it, run it. If DECLARATIONS_AFTER
147 # is set, then the token, type, and destructor
148 # declarations are generated after the rules
149 # rather than before. If CHECK_MIDRULE_VALUES
150 # is set, then --warnings=midrule-values is
153 m4_define([AT_CHECK_UNUSED_VALUES],
158 ], [_AT_UNUSED_VALUES_DECLARATIONS
161 'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; }
162 | 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; }
163 | 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; }
166 a: INT | INT { } INT { } INT { };
167 b: INT | /* empty */;
168 c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; };
169 d: INT | INT { } INT { $]1[; } INT { $<integer>2; };
170 e: INT | INT { } INT { } INT { $]1[; };
171 f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; };
172 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
173 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
174 i: INT | INT INT { } { $]$[ = $]1[ + $]2[; };
175 j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; };
176 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
177 l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [
178 _AT_UNUSED_VALUES_DECLARATIONS])
181 AT_BISON_CHECK(m4_ifval($2, [ --warnings=midrule-values ])[ input.y], [0], [],
182 [[input.y:11.10-32: warning: unset value: $]$[
183 input.y:11.10-32: warning: unused value: $]1[
184 input.y:11.10-32: warning: unused value: $]3[
185 input.y:11.10-32: warning: unused value: $]5[
186 input.y:12.9: warning: empty rule for typed nonterminal, and no action
187 ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $$
188 input.y:13.26-41: warning: unset value: $$
189 ]]])[[input.y:13.10-62: warning: unset value: $]$[
190 input.y:13.10-62: warning: unused value: $]3[
191 input.y:13.10-62: warning: unused value: $]5[
192 ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $$
193 ]]])[[input.y:14.10-49: warning: unset value: $]$[
194 input.y:14.10-49: warning: unused value: $]3[
195 input.y:14.10-49: warning: unused value: $]5[
196 input.y:15.10-37: warning: unset value: $]$[
197 input.y:15.10-37: warning: unused value: $]3[
198 input.y:15.10-37: warning: unused value: $]5[
199 input.y:17.10-58: warning: unset value: $]$[
200 input.y:17.10-58: warning: unused value: $]1[
201 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]2[
202 ]]])[[input.y:17.10-58: warning: unused value: $]3[
203 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]4[
204 ]]])[[input.y:17.10-58: warning: unused value: $]5[
205 input.y:18.10-72: warning: unset value: $]$[
206 input.y:18.10-72: warning: unused value: $]1[
207 input.y:18.10-72: warning: unused value: $]3[
208 ]]m4_ifval($2, [[[input.y:18.10-72: warning: unused value: $]4[
209 ]]])[[input.y:18.10-72: warning: unused value: $]5[
210 ]]m4_ifval($2, [[[input.y:20.10-55: warning: unused value: $]3[
211 ]]])[[input.y:21.10-68: warning: unset value: $]$[
212 input.y:21.10-68: warning: unused value: $]1[
213 input.y:21.10-68: warning: unused value: $]2[
214 ]]m4_ifval($2, [[[input.y:21.10-68: warning: unused value: $]4[
218 ## --------------- ##
220 ## --------------- ##
222 AT_SETUP([Unused values])
223 AT_CHECK_UNUSED_VALUES
224 AT_CHECK_UNUSED_VALUES(, [1])
228 ## ------------------------------------------ ##
229 ## Unused values before symbol declarations. ##
230 ## ------------------------------------------ ##
232 AT_SETUP([Unused values before symbol declarations])
233 AT_CHECK_UNUSED_VALUES([1])
234 AT_CHECK_UNUSED_VALUES([1], [1])
238 ## --------------------------------------------- ##
239 ## Default %printer and %destructor redeclared. ##
240 ## --------------------------------------------- ##
242 AT_SETUP([Default %printer and %destructor redeclared])
245 [[%destructor { destroy ($$); } <*> <*>
246 %printer { print ($$); } <*> <*>
248 %destructor { destroy ($$); } <*>
249 %printer { print ($$); } <*>
251 %destructor { destroy ($$); } <> <>
252 %printer { print ($$); } <> <>
254 %destructor { destroy ($$); } <>
255 %printer { print ($$); } <>
261 %destructor { destroy ($$); } <*>;
262 %printer { print ($$); } <*>;
264 %destructor { destroy ($$); } <>;
265 %printer { print ($$); } <>;
268 AT_BISON_CHECK([input.y], [1], [],
269 [[input.y:1.13-29: error: redeclaration for default tagged %destructor
270 input.y:1.13-29: previous declaration
271 input.y:2.10-24: error: redeclaration for default tagged %printer
272 input.y:2.10-24: previous declaration
273 input.y:4.13-29: error: redeclaration for default tagged %destructor
274 input.y:1.13-29: previous declaration
275 input.y:5.10-24: error: redeclaration for default tagged %printer
276 input.y:2.10-24: previous declaration
277 input.y:7.13-29: error: redeclaration for default tagless %destructor
278 input.y:7.13-29: previous declaration
279 input.y:8.10-24: error: redeclaration for default tagless %printer
280 input.y:8.10-24: previous declaration
281 input.y:10.13-29: error: redeclaration for default tagless %destructor
282 input.y:7.13-29: previous declaration
283 input.y:11.10-24: error: redeclaration for default tagless %printer
284 input.y:8.10-24: previous declaration
285 input.y:17.13-29: error: redeclaration for default tagged %destructor
286 input.y:4.13-29: previous declaration
287 input.y:18.10-24: error: redeclaration for default tagged %printer
288 input.y:5.10-24: previous declaration
289 input.y:20.13-29: error: redeclaration for default tagless %destructor
290 input.y:10.13-29: previous declaration
291 input.y:21.10-24: error: redeclaration for default tagless %printer
292 input.y:11.10-24: previous declaration
298 ## ---------------------------------------------- ##
299 ## Per-type %printer and %destructor redeclared. ##
300 ## ---------------------------------------------- ##
302 AT_SETUP([Per-type %printer and %destructor redeclared])
305 [[%destructor { destroy ($$); } <field1> <field2>
306 %printer { print ($$); } <field1> <field2>
308 %destructor { destroy ($$); } <field1> <field1>
309 %printer { print ($$); } <field2> <field2>
315 %destructor { destroy ($$); } <field2> <field1>;
316 %printer { print ($$); } <field2> <field1>;
319 AT_BISON_CHECK([input.y], [1], [],
320 [[input.y:4.13-29: error: %destructor redeclaration for <field1>
321 input.y:1.13-29: previous declaration
322 input.y:4.13-29: error: %destructor redeclaration for <field1>
323 input.y:4.13-29: previous declaration
324 input.y:5.10-24: error: %printer redeclaration for <field2>
325 input.y:2.10-24: previous declaration
326 input.y:5.10-24: error: %printer redeclaration for <field2>
327 input.y:5.10-24: previous declaration
328 input.y:11.13-29: error: %destructor redeclaration for <field1>
329 input.y:4.13-29: previous declaration
330 input.y:11.13-29: error: %destructor redeclaration for <field2>
331 input.y:1.13-29: previous declaration
332 input.y:12.10-24: error: %printer redeclaration for <field1>
333 input.y:2.10-24: previous declaration
334 input.y:12.10-24: error: %printer redeclaration for <field2>
335 input.y:5.10-24: previous declaration
341 ## ---------------------------------------- ##
342 ## Unused values with default %destructor. ##
343 ## ---------------------------------------- ##
345 AT_SETUP([Unused values with default %destructor])
348 [[%destructor { destroy ($$); } <>
353 start: end end tagged tagged { $<tag>1; $3; } ;
358 AT_BISON_CHECK([input.y], [0], [],
359 [[input.y:6.8-45: warning: unset value: $$
360 input.y:6.8-45: warning: unused value: $2
361 input.y:7.6-8: warning: unset value: $$
365 [[%destructor { destroy ($$); } <*>
370 start: end end tagged tagged { $<tag>1; $3; } ;
375 AT_BISON_CHECK([input.y], [0], [],
376 [[input.y:6.8-45: warning: unused value: $4
377 input.y:8.9-11: warning: unset value: $$
383 ## ----------------------------------------- ##
384 ## Unused values with per-type %destructor. ##
385 ## ----------------------------------------- ##
387 AT_SETUP([Unused values with per-type %destructor])
390 [[%destructor { destroy ($$); } <field1>
391 %type <field1> start end
395 start: end end { $1; } ;
399 AT_BISON_CHECK([input.y], [0], [],
400 [[input.y:6.8-22: warning: unset value: $$
401 input.y:6.8-22: warning: unused value: $2
402 input.y:7.6-8: warning: unset value: $$
408 ## ---------------------- ##
409 ## Incompatible Aliases. ##
410 ## ---------------------- ##
412 AT_SETUP([Incompatible Aliases])
419 %destructor {bar} foo
424 %destructor {baz} "foo"
431 AT_BISON_CHECK([input.y], [1], [],
432 [[input.y:8.7-11: error: %type redeclaration for foo
433 input.y:3.7-11: previous declaration
434 input.y:10.13-17: error: %destructor redeclaration for foo
435 input.y:5.13-17: previous declaration
436 input.y:9.10-14: error: %printer redeclaration for foo
437 input.y:4.10-14: previous declaration
438 input.y:11.1-5: error: %left redeclaration for foo
439 input.y:6.1-5: previous declaration
446 ## ----------------------- ##
447 ## Torturing the Scanner. ##
448 ## ----------------------- ##
450 # Be sure to compile and run, so that the C compiler checks what
453 AT_SETUP([Torturing the Scanner])
455 AT_BISON_OPTION_PUSHDEFS
456 AT_DATA([input.y], [])
457 AT_BISON_CHECK([input.y], [1], [],
458 [[input.y:1.1: error: syntax error, unexpected end of file
465 AT_BISON_CHECK([input.y], [1], [],
466 [[input.y:1.1-2: error: syntax error, unexpected {...}
470 AT_DATA_GRAMMAR([input.y],
472 /* This is seen in GCC: a %{ and %} in middle of a comment. */
473 const char *foo = "So %{ and %} can be here too.";
476 /* These examples test Bison while not stressing C compilers too much.
477 Many C compilers mishandle backslash-newlines, so this part of the
478 test is inside "#if 0". The comment and string are written so that
479 the "#endif" will be seen regardless of the C compiler bugs that we
482 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
485 The Apple Darwin compiler (as of late 2002) mishandles
486 \\[newline]' within a character constant.
491 * A comment with backslash-newlines in it. %} *\
494 /* { Close the above comment, if the C compiler mishandled it. */
497 " A string with backslash-newlines in it %{ %} \\
501 char apostrophe = '\'';
508 /* %{ and %} can be here too. */
511 /* Exercise pre-prologue dependency to %union. */
515 /* Exercise M4 quoting: '@:>@@:>@', 0. */
517 /* Also exercise %union. */
520 value ival; /* A comment to exercise an old bug. */
524 /* Exercise post-prologue dependency to %union. */
526 static YYSTYPE value_as_yystype (value val);
528 /* Exercise quotes in declarations. */
529 char quote[] = "@:>@@:>@,";
539 /* Exercise quotes in strings. */
540 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
543 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
544 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
546 /* Exercise quotes in braces. */
547 char tmp[] = "@<:@%c@:>@,\n";
552 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
553 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
554 output.or.oline.opt: ;|oline;;|output;;;
555 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
557 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
560 value_as_yystype (value val)
570 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
573 static size_t toknum;
574 assert (toknum < sizeof input);
575 yylval = value_as_yystype (input[toknum]);
576 return input[toknum++];
580 # Pacify Emacs' font-lock-mode: "
594 AT_BISON_OPTION_POPDEFS
596 AT_BISON_CHECK([-d -v -o input.c input.y])
597 AT_COMPILE([input.o])
599 AT_COMPILE([input], [input.o main.o])
600 AT_PARSER_CHECK([./input], 0,
607 ## ---------------------- ##
608 ## Typed symbol aliases. ##
609 ## ---------------------- ##
611 AT_SETUP([Typed symbol aliases])
613 # Bison 2.0 broke typed symbol aliases - ensure they work.
615 AT_DATA_GRAMMAR([input.y],
620 %token <val> MY_TOKEN "MY TOKEN"
627 AT_BISON_CHECK([-o input.c input.y])
636 m4_define([AT_CHECK_REQUIRE],
637 [AT_SETUP([Require $1])
638 AT_DATA_GRAMMAR([input.y],
643 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
647 AT_CHECK_REQUIRE(1.0, 0)
648 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
649 ## FIXME: Some day augment this version number.
650 AT_CHECK_REQUIRE(100.0, 63)
653 ## ------------------------------------- ##
654 ## String aliases for character tokens. ##
655 ## ------------------------------------- ##
657 AT_SETUP([String aliases for character tokens])
659 # Bison once thought a character token and its alias were different symbols
660 # with the same user token number.
662 AT_DATA_GRAMMAR([input.y],
669 AT_BISON_CHECK([-o input.c input.y])
680 AT_BISON_OPTION_PUSHDEFS
681 AT_DATA_GRAMMAR([input.y],
683 %token WITHOUT_DASH "WITHOUT-DASH"
685 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
691 start: with-dash without_dash with.period without_period;
692 with-dash: WITH-DASH;
693 without_dash: "WITHOUT-DASH";
694 with.period: WITH.PERIOD;
695 without_period: "WITHOUT.PERIOD";
700 AT_BISON_OPTION_POPDEFS
702 # POSIX Yacc accept periods, but not dashes.
703 AT_BISON_CHECK([--yacc input.y], [1], [],
704 [[input.y:9.8-16: POSIX Yacc forbids dashes in symbol names: WITH-DASH
705 input.y:18.8-16: POSIX Yacc forbids dashes in symbol names: with-dash
708 # So warn about them.
709 AT_BISON_CHECK([-Wyacc input.y], [], [],
710 [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH
711 input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
714 # Dashes are fine for GNU Bison.
715 AT_BISON_CHECK([-o input.c input.y])
717 # Make sure we don't export silly token identifiers with periods or dashes.
718 AT_COMPILE([input.o])
721 # Periods are genuine letters, they can start identifiers.
722 # Digits and dashes cannot.
723 AT_DATA_GRAMMAR([input.y],
731 AT_BISON_CHECK([-o input.c input.y], [1], [],
732 [[input.y:10.10: error: invalid character: '-'
733 input.y:11.10-16: error: invalid identifier: '1NV4L1D'
734 input.y:12.10: error: invalid character: '-'
740 ## ----------------- ##
741 ## Numbered tokens. ##
742 ## ----------------- ##
744 AT_SETUP([Numbered tokens])
746 AT_DATA_GRAMMAR([redecl.y],
747 [[%token DECIMAL_1 11259375
748 HEXADECIMAL_1 0xabcdef
749 HEXADECIMAL_2 0xFEDCBA
752 start: DECIMAL_1 HEXADECIMAL_2;
755 AT_BISON_CHECK([redecl.y], [1], [],
756 [[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1
757 redecl.y:9.8-16: previous declaration for DECIMAL_1
758 redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2
759 redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
762 AT_DATA_GRAMMAR([too-large.y],
763 [[%token TOO_LARGE_DEC 999999999999999999999
764 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
766 start: TOO_LARGE_DEC TOO_LARGE_HEX
770 AT_BISON_CHECK([too-large.y], [1], [],
771 [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
772 too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
778 ## --------------------- ##
779 ## Unclosed constructs. ##
780 ## --------------------- ##
782 AT_SETUP([Unclosed constructs])
784 # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
785 # they were prepended to whatever it STRING_GROW'ed next. It also threw them
786 # away rather than returning them to the parser. The effect was confusing
787 # subsequent error messages.
792 %token AB "ab" // Used to complain that "ab" was already used.
795 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
801 // Used to report a syntax error because it didn't see any kind of symbol
807 // Used to report a syntax error because it didn't see braced code.
808 %destructor { free ($$)
811 AT_BISON_CHECK([-o input.c input.y], 1, [],
812 [[input.y:1.10-2.0: error: missing '"' at end of line
813 input.y:4.10-5.0: error: missing "'" at end of line
814 input.y:14.11-15.0: error: missing "'" at end of line
815 input.y:16.11-17.0: error: missing '"' at end of line
816 input.y:19.13-20.0: error: missing '}' at end of file
817 input.y:20.1: error: syntax error, unexpected end of file
823 ## ------------------------- ##
824 ## %start after first rule. ##
825 ## ------------------------- ##
827 AT_SETUP([%start after first rule])
829 # Bison once complained that a %start after the first rule was a redeclaration
830 # of the start symbol.
839 AT_BISON_CHECK([-o input.c input.y])
844 ## --------------------- ##
845 ## %prec takes a token. ##
846 ## --------------------- ##
848 AT_SETUP([%prec takes a token])
850 # Bison once allowed %prec sym where sym was a nonterminal.
854 start: PREC %prec PREC ;
858 AT_BISON_CHECK([input.y], [1], [],
859 [[input.y:3.1-4: error: rule given for PREC, which is a token
865 ## ------------------------------- ##
866 ## %prec's token must be defined. ##
867 ## ------------------------------- ##
869 AT_SETUP([[%prec's token must be defined]])
871 # According to POSIX, a %prec token must be defined separately.
878 AT_BISON_CHECK([[input.y]], [[0]], [],
879 [[input.y:2.8-17: warning: token for %prec is not defined: PREC
885 ## -------------------------------- ##
886 ## Reject unused %code qualifiers. ##
887 ## -------------------------------- ##
889 AT_SETUP([Reject unused %code qualifiers])
899 AT_BISON_CHECK([[input-c.y]], [[1]], [],
900 [[input-c.y:1.7: error: %code qualifier 'q' is not used
901 input-c.y:2.7-9: error: %code qualifier 'bad' is not used
902 input-c.y:3.7-9: error: %code qualifier 'bad' is not used
903 input-c.y:4.7-12: error: %code qualifier 'format' is not used
906 AT_DATA([input-c-glr.y],
913 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
914 [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used
915 input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used
916 input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used
919 AT_DATA([input-c++.y],
926 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
927 [[input-c++.y:1.7: error: %code qualifier 'q' is not used
928 input-c++.y:2.7-9: error: %code qualifier 'bad' is not used
929 input-c++.y:3.8: error: %code qualifier 'q' is not used
932 AT_DATA([input-c++-glr.y],
939 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
940 [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used
941 input-c++-glr.y:2.7: error: %code qualifier 'q' is not used
942 input-c++-glr.y:3.7: error: %code qualifier 'q' is not used
945 AT_DATA([special-char-@@.y],
952 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
953 [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used
954 special-char-@@.y:2.7: error: %code qualifier 'q' is not used
955 special-char-@@.y:3.7: error: %code qualifier 'q' is not used
958 AT_DATA([special-char-@:>@.y],
965 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
966 [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used
967 special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used
968 special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used
974 ## ---------------- ##
975 ## %define errors. ##
976 ## ---------------- ##
978 AT_SETUP([%define errors])
980 AT_DATA([input-redefined.y],
981 [[%define var "value1"
984 %define special1 "@:>@"
985 %define special2 "@<:@"
990 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
991 [[input-redefined.y:2.9-11: error: %define variable 'var' redefined
992 input-redefined.y:1.9-11: previous definition
993 input-redefined.y:3.10-12: error: %define variable 'var' redefined
994 input-redefined.y:2.9-11: previous definition
997 AT_DATA([input-unused.y],
998 [[%define var "value"
1003 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
1004 [[input-unused.y:1.9-11: error: %define variable 'var' is not used
1010 ## ----------------------------------- ##
1011 ## %define, --define, --force-define. ##
1012 ## ----------------------------------- ##
1014 AT_SETUP([[%define, --define, --force-define]])
1017 [[m4@&t@_divert_push(0)@
1018 @output(b4_parser_file_name@)@
1019 [var-dd: ]b4_percent_define_get([[var-dd]])[
1020 var-ff: ]b4_percent_define_get([[var-ff]])[
1021 var-dfg: ]b4_percent_define_get([[var-dfg]])[
1022 var-fd: ]b4_percent_define_get([[var-fd]])
1023 m4@&t@_divert_pop(0)
1025 AT_DATA([[input.y]],
1026 [[%define var-dfg "gram"
1030 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
1031 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
1032 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
1033 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
1034 --skeleton ./skel.c input.y]])
1035 AT_CHECK([[cat input.tab.c]], [[0]],
1042 AT_DATA([[input-dg.y]],
1043 [[%define var "gram"
1047 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
1048 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1049 <command line>:2: previous definition
1052 AT_DATA([[input-unused.y]],
1056 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
1057 [[<command line>:2: error: %define variable 'unused-d' is not used
1058 <command line>:3: error: %define variable 'unused-f' is not used
1063 ## --------------------------- ##
1064 ## %define Boolean variables. ##
1065 ## --------------------------- ##
1067 AT_SETUP([[%define Boolean variables]])
1071 %define public "maybe"
1072 %define parser_class_name "Input"
1077 AT_BISON_CHECK([[Input.y]], [1], [],
1078 [[Input.y:2.9-14: error: invalid value for %define Boolean variable 'public'
1083 ## ------------------------ ##
1084 ## %define enum variables. ##
1085 ## ------------------------ ##
1087 AT_SETUP([[%define enum variables]])
1090 AT_DATA([[input.y]],
1091 [[%define lr.default-reductions bogus
1095 AT_BISON_CHECK([[input.y]], [[1]], [[]],
1096 [[input.y:1.9-29: error: invalid value for %define variable 'lr.default-reductions': 'bogus'
1097 input.y:1.9-29: accepted value: 'most'
1098 input.y:1.9-29: accepted value: 'consistent'
1099 input.y:1.9-29: accepted value: 'accepting'
1103 # FIXME: these should be indented, but we shouldn't mess with the m4 yet
1104 AT_DATA([[input.y]],
1105 [[%define api.push-pull neither
1109 AT_BISON_CHECK([[input.y]], [1], [],
1110 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1111 input.y:1.9-21: error: accepted value: 'pull'
1112 input.y:1.9-21: error: accepted value: 'push'
1113 input.y:1.9-21: error: accepted value: 'both'
1118 ## -------------------------------- ##
1119 ## %define backward compatibility. ##
1120 ## -------------------------------- ##
1122 AT_SETUP([[%define backward compatibility]])
1124 # The error messages tell us whether underscores in these variables are
1125 # being converted to dashes.
1127 AT_DATA([[input.y]],
1128 [[%define api.push_pull "neither"
1132 AT_BISON_CHECK([[input.y]], [1], [],
1133 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1134 input.y:1.9-21: error: accepted value: 'pull'
1135 input.y:1.9-21: error: accepted value: 'push'
1136 input.y:1.9-21: error: accepted value: 'both'
1139 AT_DATA([[input.y]],
1140 [[%define lr.keep_unreachable_states maybe
1144 AT_BISON_CHECK([[input.y]], [1], [],
1145 [[input.y:1.9-34: error: invalid value for %define Boolean variable 'lr.keep-unreachable-states'
1148 AT_DATA([[input.y]],
1149 [[%define foo_bar "baz"
1153 AT_BISON_CHECK([[input.y]], [[1]], [],
1154 [[input.y:1.9-15: error: %define variable 'foo_bar' is not used
1159 ## ------------------------- ##
1160 ## Unused %define api.pure. ##
1161 ## ------------------------- ##
1163 AT_SETUP([[Unused %define api.pure]])
1165 # AT_CHECK_API_PURE(DECLS, VALUE)
1166 # -------------------------------
1167 # Make sure Bison reports that `%define api.pure VALUE' is unused when DECLS
1169 m4_define([AT_CHECK_API_PURE],
1171 AT_DATA([[input.y]],
1172 [[%define api.pure ]$2[
1178 AT_BISON_CHECK([[input.y]], [[1]], [],
1179 [[input.y:1.9-16: error: %define variable 'api.pure' is not used
1183 AT_CHECK_API_PURE([[%language "c++" %defines]], [[]])
1184 AT_CHECK_API_PURE([[%language "c++" %defines]], [[false]])
1185 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[""]])
1186 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[false]])
1187 AT_CHECK_API_PURE([[%language "java"]], [[true]])
1188 AT_CHECK_API_PURE([[%language "java"]], [[false]])
1192 ## -------------------------------- ##
1193 ## C++ namespace reference errors. ##
1194 ## -------------------------------- ##
1196 AT_SETUP([[C++ namespace reference errors]])
1198 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
1199 # -------------------------------------------------------------
1200 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
1201 m4_define([AT_CHECK_NAMESPACE_ERROR],
1203 AT_DATA([[input.y]],
1206 %define namespace "]$1["
1211 AT_BISON_CHECK([[input.y]], [1], [],
1212 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
1213 [[input.y:3.9-17: error: ]b4_arg[
1217 AT_CHECK_NAMESPACE_ERROR([[]],
1218 [[namespace reference is empty]])
1219 AT_CHECK_NAMESPACE_ERROR([[ ]],
1220 [[namespace reference is empty]])
1221 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
1222 [[namespace reference has consecutive "::"]])
1223 AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]],
1224 [[namespace reference has consecutive "::"]])
1225 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
1226 [[namespace reference has consecutive "::"]])
1227 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
1228 [[namespace reference has consecutive "::"]])
1229 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]],
1230 [[namespace reference has consecutive "::"]],
1231 [[namespace reference has a trailing "::"]])
1232 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
1233 [[namespace reference has a trailing "::"]])
1234 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]],
1235 [[namespace reference has a trailing "::"]])
1236 AT_CHECK_NAMESPACE_ERROR([[::]],
1237 [[namespace reference has a trailing "::"]])
1241 ## ------------------------ ##
1242 ## Bad character literals. ##
1243 ## ------------------------ ##
1245 # Bison used to accept character literals that were empty or contained
1246 # too many characters.
1248 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
1249 # the final newline to be omitted. See the threads starting at
1250 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
1252 AT_SETUP([[Bad character literals]])
1259 AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
1261 AT_BISON_CHECK([empty.y], [1], [],
1262 [[empty.y:2.8-9: warning: empty character literal
1263 empty.y:3.8-4.0: warning: empty character literal
1264 empty.y:3.8-4.0: error: missing "'" at end of line
1265 empty.y:4.8: warning: empty character literal
1266 empty.y:4.8: error: missing "'" at end of file
1274 AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
1276 AT_BISON_CHECK([two.y], [1], [],
1277 [[two.y:2.8-11: warning: extra characters in character literal
1278 two.y:3.8-4.0: warning: extra characters in character literal
1279 two.y:3.8-4.0: error: missing "'" at end of line
1280 two.y:4.8-10: warning: extra characters in character literal
1281 two.y:4.8-10: error: missing "'" at end of file
1289 AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
1291 AT_BISON_CHECK([three.y], [1], [],
1292 [[three.y:2.8-12: warning: extra characters in character literal
1293 three.y:3.8-4.0: warning: extra characters in character literal
1294 three.y:3.8-4.0: error: missing "'" at end of line
1295 three.y:4.8-11: warning: extra characters in character literal
1296 three.y:4.8-11: error: missing "'" at end of file
1301 ## ------------------------- ##
1302 ## Bad escapes in literals. ##
1303 ## ------------------------- ##
1305 AT_SETUP([[Bad escapes in literals]])
1309 start: '\777' '\0' '\xfff' '\x0'
1310 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
1314 # It is not easy to create special characters, we cannot even trust tr.
1315 # Beside we cannot even expect "echo '\0'" to output two characters
1316 # (well three with \n): at least Bash 3.2 converts the two-character
1317 # sequence "\0" into a single NUL character.
1318 AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
1321 AT_BISON_CHECK([input.y], [1], [],
1322 [[input.y:2.9-12: error: invalid number after \-escape: 777
1323 input.y:2.8-13: warning: empty character literal
1324 input.y:2.16-17: error: invalid number after \-escape: 0
1325 input.y:2.15-18: warning: empty character literal
1326 input.y:2.21-25: error: invalid number after \-escape: xfff
1327 input.y:2.20-26: warning: empty character literal
1328 input.y:2.29-31: error: invalid number after \-escape: x0
1329 input.y:2.28-32: warning: empty character literal
1330 input.y:3.9-14: error: invalid number after \-escape: uffff
1331 input.y:3.8-15: warning: empty character literal
1332 input.y:3.18-23: error: invalid number after \-escape: u0000
1333 input.y:3.17-24: warning: empty character literal
1334 input.y:3.27-36: error: invalid number after \-escape: Uffffffff
1335 input.y:3.26-37: warning: empty character literal
1336 input.y:3.40-49: error: invalid number after \-escape: U00000000
1337 input.y:3.39-50: warning: empty character literal
1338 input.y:4.9-10: error: invalid character after \-escape: ' '
1339 input.y:4.8-11: warning: empty character literal
1340 input.y:4.14-15: error: invalid character after \-escape: A
1341 input.y:4.13-16: warning: empty character literal
1342 input.y:5.9-16: error: invalid character after \-escape: \t
1343 input.y:5.17: error: invalid character after \-escape: \f
1344 input.y:5.18: error: invalid character after \-escape: \0
1345 input.y:5.19: error: invalid character after \-escape: \001
1350 ## ------------------------- ##
1351 ## LAC: Errors for %define. ##
1352 ## ------------------------- ##
1354 AT_SETUP([[LAC: Errors for %define]])
1356 AT_DATA([[input.y]],
1361 # parse.lac.* options are useless if LAC isn't actually activated.
1362 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
1364 [[<command line>:2: error: %define variable 'parse.lac.es-capacity-initial' is not used
1366 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
1368 [[<command line>:2: error: %define variable 'parse.lac.memory-trace' is not used
1373 ## --------------------------------------------- ##
1374 ## -Werror is not affected by -Wnone and -Wall. ##
1375 ## --------------------------------------------- ##
1377 AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
1379 AT_DATA([[input.y]],
1384 # -Werror is not enabled by -Wall or equivalent.
1385 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
1386 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1388 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
1389 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1391 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
1392 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1395 # -Werror is not disabled by -Wnone or equivalent.
1396 AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]])
1397 AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]],
1398 [[bison: warnings being treated as errors
1399 input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1402 AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])
1407 ## ------------------------------------------------------ ##
1408 ## %name-prefix and %define api.prefix are incompatible. ##
1409 ## ------------------------------------------------------ ##
1411 AT_SETUP([[%name-prefix and %define api.prefix are incompatible]])
1413 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
1414 # --------------------------------------------
1415 m4_pushdef([AT_TEST],
1416 [AT_DATA([[input.y]],
1421 AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
1422 [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
1426 AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
1427 AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:2])
1428 AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:2])
1429 AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
1431 m4_popdef([AT_TEST])
1436 ## -------------- ##
1438 ## -------------- ##
1440 AT_SETUP([[Stray $ or @]])
1442 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
1443 # check that the warnings are reported once, not three times.
1445 AT_DATA_GRAMMAR([[input.y]],
1447 %destructor { $%; @%; } <*> exp TOK;
1448 %initial-action { $%; @%; };
1449 %printer { $%; @%; } <*> exp TOK;
1451 exp: TOK { $%; @%; $$ = $1; };
1454 AT_BISON_CHECK([[input.y]], 0, [],
1455 [[input.y:10.19: warning: stray '$'
1456 input.y:10.23: warning: stray '@'
1457 input.y:11.19: warning: stray '$'
1458 input.y:11.23: warning: stray '@'
1459 input.y:12.19: warning: stray '$'
1460 input.y:12.23: warning: stray '@'
1461 input.y:14.19: warning: stray '$'
1462 input.y:14.23: warning: stray '@'
1469 ## ---------------- ##
1470 ## Code injection. ##
1471 ## ---------------- ##
1474 AT_SETUP([[Code injection]])
1476 m4_pattern_allow([^m4_errprintn$])
1480 # Try to have MACRO be run by bison.
1481 m4_pushdef([AT_TEST],
1482 [AT_DATA([[input.y]],
1483 [[%type <$1(DEAD %type)> exp
1484 %token <$1(DEAD %token)> a
1488 $<$1(DEAD %initial-action)>$
1493 $<$1(DEAD %printer)>$
1501 $1(DEAD %parse-param)
1509 $<$1(DEAD action 1)>$
1510 $<$1(DEAD action 2)>1
1511 $<$1(DEAD action 3)>last
1512 $<$1(DEAD action 4)>0
1517 # FIXME: Provide a means to iterate over all the skeletons.
1518 AT_BISON_CHECK([[-d input.y]])
1519 AT_BISON_CHECK([[-d -S glr.c input.y]])
1520 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
1521 AT_BISON_CHECK([[-d -S glr.cc input.y]])
1522 AT_BISON_CHECK([[ -S lalr1.java input.y]])
1525 AT_TEST([m4_errprintn])
1526 AT_TEST([@:>@m4_errprintn])
1528 m4_popdef([AT_TEST])