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_BISON_CHECK([input.y], [1], [],
40 [[input.y:2.1: invalid character: '?'
41 input.y:3.14: invalid character: '}'
42 input.y:4.1: invalid character: '%'
43 input.y:4.2: invalid character: '&'
44 input.y:5.1-17: invalid directive: '%a-does-not-exist'
45 input.y:6.1: invalid character: '%'
46 input.y:6.2: invalid character: '-'
47 input.y:7.1-8.0: missing '%}' at end of file
48 input.y:7.1-8.0: syntax error, unexpected %{...%}
54 AT_SETUP([Invalid inputs with {}])
56 # We used to SEGV here. See
57 # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
69 AT_BISON_CHECK([input.y], [1], [],
70 [[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
81 AT_SETUP([Invalid $n and @n])
89 AT_BISON_CHECK([input.y], [1], [],
90 [[input.y:2.13-14: integer out of range: '$1'
91 input.y:3.13-14: integer out of range: '@1'
101 AT_SETUP([Type Clashes])
104 [[%union { int bar; }
108 exp: foo { $$; } foo { $2; } foo
114 AT_BISON_CHECK([input.y], [1], [],
115 [[input.y:5.12-13: $$ for the midrule at $2 of 'exp' has no declared type
116 input.y:5.24-25: $2 of 'exp' has no declared type
117 input.y:5.6-32: warning: type clash on default action: <bar> != <>
118 input.y:6.6-8: warning: type clash on default action: <bar> != <>
119 input.y:7.5: warning: empty rule for typed nonterminal, and no action
125 # _AT_UNUSED_VALUES_DECLARATIONS()
126 # --------------------------------
127 # Generate the token, type, and destructor
128 # declarations for the unused values tests.
130 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
131 [[[%token <integer> INT;
132 %type <integer> a b c d e f g h i j k l;
133 %destructor { destroy ($$); } INT a b c d e f g h i j k l;]]])
136 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
137 # ------------------------------------------------------------------
138 # Generate a grammar to test unused values,
139 # compile it, run it. If DECLARATIONS_AFTER
140 # is set, then the token, type, and destructor
141 # declarations are generated after the rules
142 # rather than before. If CHECK_MIDRULE_VALUES
143 # is set, then --warnings=midrule-values is
146 m4_define([AT_CHECK_UNUSED_VALUES],
151 ], [_AT_UNUSED_VALUES_DECLARATIONS
154 'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; }
155 | 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; }
156 | 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; }
159 a: INT | INT { } INT { } INT { };
160 b: INT | /* empty */;
161 c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; };
162 d: INT | INT { } INT { $]1[; } INT { $<integer>2; };
163 e: INT | INT { } INT { } INT { $]1[; };
164 f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; };
165 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
166 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
167 i: INT | INT INT { } { $]$[ = $]1[ + $]2[; };
168 j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; };
169 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
170 l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [
171 _AT_UNUSED_VALUES_DECLARATIONS])
174 AT_BISON_CHECK(m4_ifval($2, [ --warnings=midrule-values ])[ input.y], [0], [],
175 [[input.y:11.10-32: warning: unset value: $]$[
176 input.y:11.10-32: warning: unused value: $]1[
177 input.y:11.10-32: warning: unused value: $]3[
178 input.y:11.10-32: warning: unused value: $]5[
179 input.y:12.9: warning: empty rule for typed nonterminal, and no action
180 ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $$
181 input.y:13.26-41: warning: unset value: $$
182 ]]])[[input.y:13.10-62: warning: unset value: $]$[
183 input.y:13.10-62: warning: unused value: $]3[
184 input.y:13.10-62: warning: unused value: $]5[
185 ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $$
186 ]]])[[input.y:14.10-49: warning: unset value: $]$[
187 input.y:14.10-49: warning: unused value: $]3[
188 input.y:14.10-49: warning: unused value: $]5[
189 input.y:15.10-37: warning: unset value: $]$[
190 input.y:15.10-37: warning: unused value: $]3[
191 input.y:15.10-37: warning: unused value: $]5[
192 input.y:17.10-58: warning: unset value: $]$[
193 input.y:17.10-58: warning: unused value: $]1[
194 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]2[
195 ]]])[[input.y:17.10-58: warning: unused value: $]3[
196 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]4[
197 ]]])[[input.y:17.10-58: warning: unused value: $]5[
198 input.y:18.10-72: warning: unset value: $]$[
199 input.y:18.10-72: warning: unused value: $]1[
200 input.y:18.10-72: warning: unused value: $]3[
201 ]]m4_ifval($2, [[[input.y:18.10-72: warning: unused value: $]4[
202 ]]])[[input.y:18.10-72: warning: unused value: $]5[
203 ]]m4_ifval($2, [[[input.y:20.10-55: warning: unused value: $]3[
204 ]]])[[input.y:21.10-68: warning: unset value: $]$[
205 input.y:21.10-68: warning: unused value: $]1[
206 input.y:21.10-68: warning: unused value: $]2[
207 ]]m4_ifval($2, [[[input.y:21.10-68: warning: unused value: $]4[
211 ## --------------- ##
213 ## --------------- ##
215 AT_SETUP([Unused values])
216 AT_CHECK_UNUSED_VALUES
217 AT_CHECK_UNUSED_VALUES(, [1])
221 ## ------------------------------------------ ##
222 ## Unused values before symbol declarations. ##
223 ## ------------------------------------------ ##
225 AT_SETUP([Unused values before symbol declarations])
226 AT_CHECK_UNUSED_VALUES([1])
227 AT_CHECK_UNUSED_VALUES([1], [1])
231 ## --------------------------------------------- ##
232 ## Default %printer and %destructor redeclared. ##
233 ## --------------------------------------------- ##
235 AT_SETUP([Default %printer and %destructor redeclared])
238 [[%destructor { destroy ($$); } <*> <*>
239 %printer { print ($$); } <*> <*>
241 %destructor { destroy ($$); } <*>
242 %printer { print ($$); } <*>
244 %destructor { destroy ($$); } <> <>
245 %printer { print ($$); } <> <>
247 %destructor { destroy ($$); } <>
248 %printer { print ($$); } <>
254 %destructor { destroy ($$); } <*>;
255 %printer { print ($$); } <*>;
257 %destructor { destroy ($$); } <>;
258 %printer { print ($$); } <>;
261 AT_BISON_CHECK([input.y], [1], [],
262 [[input.y:1.13-29: redeclaration for default tagged %destructor
263 input.y:1.13-29: previous declaration
264 input.y:2.10-24: redeclaration for default tagged %printer
265 input.y:2.10-24: previous declaration
266 input.y:4.13-29: redeclaration for default tagged %destructor
267 input.y:1.13-29: previous declaration
268 input.y:5.10-24: redeclaration for default tagged %printer
269 input.y:2.10-24: previous declaration
270 input.y:7.13-29: redeclaration for default tagless %destructor
271 input.y:7.13-29: previous declaration
272 input.y:8.10-24: redeclaration for default tagless %printer
273 input.y:8.10-24: previous declaration
274 input.y:10.13-29: redeclaration for default tagless %destructor
275 input.y:7.13-29: previous declaration
276 input.y:11.10-24: redeclaration for default tagless %printer
277 input.y:8.10-24: previous declaration
278 input.y:17.13-29: redeclaration for default tagged %destructor
279 input.y:4.13-29: previous declaration
280 input.y:18.10-24: redeclaration for default tagged %printer
281 input.y:5.10-24: previous declaration
282 input.y:20.13-29: redeclaration for default tagless %destructor
283 input.y:10.13-29: previous declaration
284 input.y:21.10-24: redeclaration for default tagless %printer
285 input.y:11.10-24: previous declaration
291 ## ---------------------------------------------- ##
292 ## Per-type %printer and %destructor redeclared. ##
293 ## ---------------------------------------------- ##
295 AT_SETUP([Per-type %printer and %destructor redeclared])
298 [[%destructor { destroy ($$); } <field1> <field2>
299 %printer { print ($$); } <field1> <field2>
301 %destructor { destroy ($$); } <field1> <field1>
302 %printer { print ($$); } <field2> <field2>
308 %destructor { destroy ($$); } <field2> <field1>;
309 %printer { print ($$); } <field2> <field1>;
312 AT_BISON_CHECK([input.y], [1], [],
313 [[input.y:4.13-29: %destructor redeclaration for <field1>
314 input.y:1.13-29: previous declaration
315 input.y:4.13-29: %destructor redeclaration for <field1>
316 input.y:4.13-29: previous declaration
317 input.y:5.10-24: %printer redeclaration for <field2>
318 input.y:2.10-24: previous declaration
319 input.y:5.10-24: %printer redeclaration for <field2>
320 input.y:5.10-24: previous declaration
321 input.y:11.13-29: %destructor redeclaration for <field1>
322 input.y:4.13-29: previous declaration
323 input.y:11.13-29: %destructor redeclaration for <field2>
324 input.y:1.13-29: previous declaration
325 input.y:12.10-24: %printer redeclaration for <field1>
326 input.y:2.10-24: previous declaration
327 input.y:12.10-24: %printer redeclaration for <field2>
328 input.y:5.10-24: previous declaration
334 ## ---------------------------------------- ##
335 ## Unused values with default %destructor. ##
336 ## ---------------------------------------- ##
338 AT_SETUP([Unused values with default %destructor])
341 [[%destructor { destroy ($$); } <>
346 start: end end tagged tagged { $<tag>1; $3; } ;
351 AT_BISON_CHECK([input.y], [0], [],
352 [[input.y:6.8-45: warning: unset value: $$
353 input.y:6.8-45: warning: unused value: $2
354 input.y:7.6-8: warning: unset value: $$
358 [[%destructor { destroy ($$); } <*>
363 start: end end tagged tagged { $<tag>1; $3; } ;
368 AT_BISON_CHECK([input.y], [0], [],
369 [[input.y:6.8-45: warning: unused value: $4
370 input.y:8.9-11: warning: unset value: $$
376 ## ----------------------------------------- ##
377 ## Unused values with per-type %destructor. ##
378 ## ----------------------------------------- ##
380 AT_SETUP([Unused values with per-type %destructor])
383 [[%destructor { destroy ($$); } <field1>
384 %type <field1> start end
388 start: end end { $1; } ;
392 AT_BISON_CHECK([input.y], [0], [],
393 [[input.y:6.8-22: warning: unset value: $$
394 input.y:6.8-22: warning: unused value: $2
395 input.y:7.6-8: warning: unset value: $$
401 ## ---------------------- ##
402 ## Incompatible Aliases. ##
403 ## ---------------------- ##
405 AT_SETUP([Incompatible Aliases])
412 %destructor {bar} foo
417 %destructor {baz} "foo"
424 AT_BISON_CHECK([input.y], [1], [],
425 [[input.y:8.7-11: %type redeclaration for foo
426 input.y:3.7-11: previous declaration
427 input.y:10.13-17: %destructor redeclaration for foo
428 input.y:5.13-17: previous declaration
429 input.y:9.10-14: %printer redeclaration for foo
430 input.y:4.10-14: previous declaration
431 input.y:11.1-5: %left redeclaration for foo
432 input.y:6.1-5: previous declaration
439 ## ----------------------- ##
440 ## Torturing the Scanner. ##
441 ## ----------------------- ##
443 # Be sure to compile and run, so that the C compiler checks what
446 AT_SETUP([Torturing the Scanner])
448 AT_BISON_OPTION_PUSHDEFS
449 AT_DATA([input.y], [])
450 AT_BISON_CHECK([input.y], [1], [],
451 [[input.y:1.1: syntax error, unexpected end of file
458 AT_BISON_CHECK([input.y], [1], [],
459 [[input.y:1.1-2: syntax error, unexpected {...}
463 AT_DATA_GRAMMAR([input.y],
465 /* This is seen in GCC: a %{ and %} in middle of a comment. */
466 const char *foo = "So %{ and %} can be here too.";
469 /* These examples test Bison while not stressing C compilers too much.
470 Many C compilers mishandle backslash-newlines, so this part of the
471 test is inside "#if 0". The comment and string are written so that
472 the "#endif" will be seen regardless of the C compiler bugs that we
475 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
478 The Apple Darwin compiler (as of late 2002) mishandles
479 \\[newline]' within a character constant.
484 * A comment with backslash-newlines in it. %} *\
487 /* { Close the above comment, if the C compiler mishandled it. */
490 " A string with backslash-newlines in it %{ %} \\
494 char apostrophe = '\'';
501 /* %{ and %} can be here too. */
504 /* Exercise pre-prologue dependency to %union. */
508 /* Exercise M4 quoting: '@:>@@:>@', 0. */
510 /* Also exercise %union. */
513 value ival; /* A comment to exercise an old bug. */
517 /* Exercise post-prologue dependency to %union. */
519 static YYSTYPE value_as_yystype (value val);
521 /* Exercise quotes in declarations. */
522 char quote[] = "@:>@@:>@,";
532 /* Exercise quotes in strings. */
533 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
536 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
537 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
539 /* Exercise quotes in braces. */
540 char tmp[] = "@<:@%c@:>@,\n";
545 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
546 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
547 output.or.oline.opt: ;|oline;;|output;;;
548 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
550 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
553 value_as_yystype (value val)
563 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
566 static size_t toknum;
567 assert (toknum < sizeof input);
568 yylval = value_as_yystype (input[toknum]);
569 return input[toknum++];
573 # Pacify Emacs' font-lock-mode: "
587 AT_BISON_OPTION_POPDEFS
589 AT_BISON_CHECK([-d -v -o input.c input.y])
590 AT_COMPILE([input.o])
592 AT_COMPILE([input], [input.o main.o])
593 AT_PARSER_CHECK([./input], 0,
600 ## ---------------------- ##
601 ## Typed symbol aliases. ##
602 ## ---------------------- ##
604 AT_SETUP([Typed symbol aliases])
606 # Bison 2.0 broke typed symbol aliases - ensure they work.
608 AT_DATA_GRAMMAR([input.y],
613 %token <val> MY_TOKEN "MY TOKEN"
620 AT_BISON_CHECK([-o input.c input.y])
629 m4_define([AT_CHECK_REQUIRE],
630 [AT_SETUP([Require $1])
631 AT_DATA_GRAMMAR([input.y],
636 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
640 AT_CHECK_REQUIRE(1.0, 0)
641 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
642 ## FIXME: Some day augment this version number.
643 AT_CHECK_REQUIRE(100.0, 63)
646 ## ------------------------------------- ##
647 ## String aliases for character tokens. ##
648 ## ------------------------------------- ##
650 AT_SETUP([String aliases for character tokens])
652 # Bison once thought a character token and its alias were different symbols
653 # with the same user token number.
655 AT_DATA_GRAMMAR([input.y],
662 AT_BISON_CHECK([-o input.c input.y])
673 AT_BISON_OPTION_PUSHDEFS
674 AT_DATA_GRAMMAR([input.y],
676 %token WITHOUT_DASH "WITHOUT-DASH"
678 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
684 start: with-dash without_dash with.period without_period;
685 with-dash: WITH-DASH;
686 without_dash: "WITHOUT-DASH";
687 with.period: WITH.PERIOD;
688 without_period: "WITHOUT.PERIOD";
693 AT_BISON_OPTION_POPDEFS
695 # POSIX Yacc accept periods, but not dashes.
696 AT_BISON_CHECK([--yacc input.y], [1], [],
697 [[input.y:9.8-16: POSIX Yacc forbids dashes in symbol names: WITH-DASH
698 input.y:18.8-16: POSIX Yacc forbids dashes in symbol names: with-dash
701 # So warn about them.
702 AT_BISON_CHECK([-Wyacc input.y], [], [],
703 [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH
704 input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
707 # Dashes are fine for GNU Bison.
708 AT_BISON_CHECK([-o input.c input.y])
710 # Make sure we don't export silly token identifiers with periods or dashes.
711 AT_COMPILE([input.o])
714 # Periods are genuine letters, they can start identifiers.
715 # Digits and dashes cannot.
716 AT_DATA_GRAMMAR([input.y],
724 AT_BISON_CHECK([-o input.c input.y], [1], [],
725 [[input.y:10.10: invalid character: '-'
726 input.y:11.10-16: invalid identifier: '1NV4L1D'
727 input.y:12.10: invalid character: '-'
733 ## ----------------- ##
734 ## Numbered tokens. ##
735 ## ----------------- ##
737 AT_SETUP([Numbered tokens])
739 AT_DATA_GRAMMAR([redecl.y],
740 [[%token DECIMAL_1 11259375
741 HEXADECIMAL_1 0xabcdef
742 HEXADECIMAL_2 0xFEDCBA
745 start: DECIMAL_1 HEXADECIMAL_2;
748 AT_BISON_CHECK([redecl.y], [1], [],
749 [[redecl.y:10.10-22: user token number 11259375 redeclaration for HEXADECIMAL_1
750 redecl.y:9.8-16: previous declaration for DECIMAL_1
751 redecl.y:12.10-18: user token number 16702650 redeclaration for DECIMAL_2
752 redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
755 AT_DATA_GRAMMAR([too-large.y],
756 [[%token TOO_LARGE_DEC 999999999999999999999
757 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
759 start: TOO_LARGE_DEC TOO_LARGE_HEX
763 AT_BISON_CHECK([too-large.y], [1], [],
764 [[too-large.y:9.22-42: integer out of range: '999999999999999999999'
765 too-large.y:10.24-44: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
771 ## --------------------- ##
772 ## Unclosed constructs. ##
773 ## --------------------- ##
775 AT_SETUP([Unclosed constructs])
777 # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
778 # they were prepended to whatever it STRING_GROW'ed next. It also threw them
779 # away rather than returning them to the parser. The effect was confusing
780 # subsequent error messages.
785 %token AB "ab" // Used to complain that "ab" was already used.
788 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
794 // Used to report a syntax error because it didn't see any kind of symbol
800 // Used to report a syntax error because it didn't see braced code.
801 %destructor { free ($$)
804 AT_BISON_CHECK([-o input.c input.y], 1, [],
805 [[input.y:1.10-2.0: missing '"' at end of line
806 input.y:4.10-5.0: missing "'" at end of line
807 input.y:14.11-15.0: missing "'" at end of line
808 input.y:16.11-17.0: missing '"' at end of line
809 input.y:19.13-20.0: missing '}' at end of file
810 input.y:20.1: syntax error, unexpected end of file
816 ## ------------------------- ##
817 ## %start after first rule. ##
818 ## ------------------------- ##
820 AT_SETUP([%start after first rule])
822 # Bison once complained that a %start after the first rule was a redeclaration
823 # of the start symbol.
832 AT_BISON_CHECK([-o input.c input.y])
837 ## --------------------- ##
838 ## %prec takes a token. ##
839 ## --------------------- ##
841 AT_SETUP([%prec takes a token])
843 # Bison once allowed %prec sym where sym was a nonterminal.
847 start: PREC %prec PREC ;
851 AT_BISON_CHECK([input.y], [1], [],
852 [[input.y:3.1-4: rule given for PREC, which is a token
858 ## ------------------------------- ##
859 ## %prec's token must be defined. ##
860 ## ------------------------------- ##
862 AT_SETUP([[%prec's token must be defined]])
864 # According to POSIX, a %prec token must be defined separately.
871 AT_BISON_CHECK([[input.y]], [[0]], [],
872 [[input.y:2.8-17: warning: token for %prec is not defined: PREC
878 ## -------------------------------- ##
879 ## Reject unused %code qualifiers. ##
880 ## -------------------------------- ##
882 AT_SETUP([Reject unused %code qualifiers])
892 AT_BISON_CHECK([[input-c.y]], [[1]], [],
893 [[input-c.y:1.7: %code qualifier 'q' is not used
894 input-c.y:2.7-9: %code qualifier 'bad' is not used
895 input-c.y:3.7-9: %code qualifier 'bad' is not used
896 input-c.y:4.7-12: %code qualifier 'format' is not used
899 AT_DATA([input-c-glr.y],
906 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
907 [[input-c-glr.y:1.7: %code qualifier 'q' is not used
908 input-c-glr.y:2.7-9: %code qualifier 'bad' is not used
909 input-c-glr.y:3.8-10: %code qualifier 'bad' is not used
912 AT_DATA([input-c++.y],
919 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
920 [[input-c++.y:1.7: %code qualifier 'q' is not used
921 input-c++.y:2.7-9: %code qualifier 'bad' is not used
922 input-c++.y:3.8: %code qualifier 'q' is not used
925 AT_DATA([input-c++-glr.y],
932 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
933 [[input-c++-glr.y:1.7-9: %code qualifier 'bad' is not used
934 input-c++-glr.y:2.7: %code qualifier 'q' is not used
935 input-c++-glr.y:3.7: %code qualifier 'q' is not used
938 AT_DATA([special-char-@@.y],
945 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
946 [[special-char-@@.y:1.7-9: %code qualifier 'bad' is not used
947 special-char-@@.y:2.7: %code qualifier 'q' is not used
948 special-char-@@.y:3.7: %code qualifier 'q' is not used
951 AT_DATA([special-char-@:>@.y],
958 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
959 [[special-char-@:>@.y:1.7-9: %code qualifier 'bad' is not used
960 special-char-@:>@.y:2.7: %code qualifier 'q' is not used
961 special-char-@:>@.y:3.7: %code qualifier 'q' is not used
967 ## ---------------- ##
968 ## %define errors. ##
969 ## ---------------- ##
971 AT_SETUP([%define errors])
973 AT_DATA([input-redefined.y],
974 [[%define var "value1"
977 %define special1 "@:>@"
978 %define special2 "@<:@"
983 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
984 [[input-redefined.y:2.9-11: %define variable 'var' redefined
985 input-redefined.y:1.9-11: previous definition
986 input-redefined.y:3.10-12: %define variable 'var' redefined
987 input-redefined.y:2.9-11: previous definition
990 AT_DATA([input-unused.y],
991 [[%define var "value"
996 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
997 [[input-unused.y:1.9-11: %define variable 'var' is not used
1003 ## ----------------------------------- ##
1004 ## %define, --define, --force-define. ##
1005 ## ----------------------------------- ##
1007 AT_SETUP([[%define, --define, --force-define]])
1010 [[m4@&t@_divert_push(0)@
1011 @output(b4_parser_file_name@)@
1012 [var-dd: ]b4_percent_define_get([[var-dd]])[
1013 var-ff: ]b4_percent_define_get([[var-ff]])[
1014 var-dfg: ]b4_percent_define_get([[var-dfg]])[
1015 var-fd: ]b4_percent_define_get([[var-fd]])
1016 m4@&t@_divert_pop(0)
1018 AT_DATA([[input.y]],
1019 [[%define var-dfg "gram"
1023 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
1024 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
1025 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
1026 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
1027 --skeleton ./skel.c input.y]])
1028 AT_CHECK([[cat input.tab.c]], [[0]],
1035 AT_DATA([[input-dg.y]],
1036 [[%define var "gram"
1040 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
1041 [[input-dg.y:1.9-11: %define variable 'var' redefined
1042 <command line>:2: previous definition
1045 AT_DATA([[input-unused.y]],
1049 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
1050 [[<command line>:2: %define variable 'unused-d' is not used
1051 <command line>:3: %define variable 'unused-f' is not used
1056 ## --------------------------- ##
1057 ## %define Boolean variables. ##
1058 ## --------------------------- ##
1060 AT_SETUP([[%define Boolean variables]])
1064 %define public "maybe"
1065 %define parser_class_name "Input"
1070 AT_BISON_CHECK([[Input.y]], [1], [],
1071 [[Input.y:2.9-14: invalid value for %define Boolean variable 'public'
1076 ## ------------------------ ##
1077 ## %define enum variables. ##
1078 ## ------------------------ ##
1080 AT_SETUP([[%define enum variables]])
1083 AT_DATA([[input.y]],
1084 [[%define lr.default-reductions bogus
1088 AT_BISON_CHECK([[input.y]], [[1]], [[]],
1089 [[input.y:1.9-29: invalid value for %define variable 'lr.default-reductions': 'bogus'
1090 input.y:1.9-29: accepted value: 'most'
1091 input.y:1.9-29: accepted value: 'consistent'
1092 input.y:1.9-29: accepted value: 'accepting'
1096 AT_DATA([[input.y]],
1097 [[%define api.push-pull neither
1101 AT_BISON_CHECK([[input.y]], [1], [],
1102 [[input.y:1.9-21: invalid value for %define variable 'api.push-pull': 'neither'
1103 input.y:1.9-21: accepted value: 'pull'
1104 input.y:1.9-21: accepted value: 'push'
1105 input.y:1.9-21: accepted value: 'both'
1110 ## -------------------------------- ##
1111 ## %define backward compatibility. ##
1112 ## -------------------------------- ##
1114 AT_SETUP([[%define backward compatibility]])
1116 # The error messages tell us whether underscores in these variables are
1117 # being converted to dashes.
1119 AT_DATA([[input.y]],
1120 [[%define api.push_pull "neither"
1124 AT_BISON_CHECK([[input.y]], [1], [],
1125 [[input.y:1.9-21: invalid value for %define variable 'api.push-pull': 'neither'
1126 input.y:1.9-21: accepted value: 'pull'
1127 input.y:1.9-21: accepted value: 'push'
1128 input.y:1.9-21: accepted value: 'both'
1131 AT_DATA([[input.y]],
1132 [[%define lr.keep_unreachable_states maybe
1136 AT_BISON_CHECK([[input.y]], [1], [],
1137 [[input.y:1.9-34: invalid value for %define Boolean variable 'lr.keep-unreachable-states'
1140 AT_DATA([[input.y]],
1141 [[%define foo_bar "baz"
1145 AT_BISON_CHECK([[input.y]], [[1]], [],
1146 [[input.y:1.9-15: %define variable 'foo_bar' is not used
1151 ## ------------------------- ##
1152 ## Unused %define api.pure. ##
1153 ## ------------------------- ##
1155 AT_SETUP([[Unused %define api.pure]])
1157 # AT_CHECK_API_PURE(DECLS, VALUE)
1158 # -------------------------------
1159 # Make sure Bison reports that `%define api.pure VALUE' is unused when DECLS
1161 m4_define([AT_CHECK_API_PURE],
1163 AT_DATA([[input.y]],
1164 [[%define api.pure ]$2[
1170 AT_BISON_CHECK([[input.y]], [[1]], [],
1171 [[input.y:1.9-16: %define variable 'api.pure' is not used
1175 AT_CHECK_API_PURE([[%language "c++" %defines]], [[]])
1176 AT_CHECK_API_PURE([[%language "c++" %defines]], [[false]])
1177 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[""]])
1178 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[false]])
1179 AT_CHECK_API_PURE([[%language "java"]], [[true]])
1180 AT_CHECK_API_PURE([[%language "java"]], [[false]])
1184 ## -------------------------------- ##
1185 ## C++ namespace reference errors. ##
1186 ## -------------------------------- ##
1188 AT_SETUP([[C++ namespace reference errors]])
1190 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
1191 # -------------------------------------------------------------
1192 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
1193 m4_define([AT_CHECK_NAMESPACE_ERROR],
1195 AT_DATA([[input.y]],
1198 %define namespace "]$1["
1203 AT_BISON_CHECK([[input.y]], [1], [],
1204 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
1205 [[input.y:3.9-17: ]b4_arg[
1209 AT_CHECK_NAMESPACE_ERROR([[]],
1210 [[namespace reference is empty]])
1211 AT_CHECK_NAMESPACE_ERROR([[ ]],
1212 [[namespace reference is empty]])
1213 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
1214 [[namespace reference has consecutive "::"]])
1215 AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]],
1216 [[namespace reference has consecutive "::"]])
1217 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
1218 [[namespace reference has consecutive "::"]])
1219 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
1220 [[namespace reference has consecutive "::"]])
1221 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]],
1222 [[namespace reference has consecutive "::"]],
1223 [[namespace reference has a trailing "::"]])
1224 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
1225 [[namespace reference has a trailing "::"]])
1226 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]],
1227 [[namespace reference has a trailing "::"]])
1228 AT_CHECK_NAMESPACE_ERROR([[::]],
1229 [[namespace reference has a trailing "::"]])
1233 ## ------------------------ ##
1234 ## Bad character literals. ##
1235 ## ------------------------ ##
1237 # Bison used to accept character literals that were empty or contained
1238 # too many characters.
1240 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
1241 # the final newline to be omitted. See the threads starting at
1242 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
1244 AT_SETUP([[Bad character literals]])
1251 AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
1253 AT_BISON_CHECK([empty.y], [1], [],
1254 [[empty.y:2.8-9: warning: empty character literal
1255 empty.y:3.8-4.0: warning: empty character literal
1256 empty.y:3.8-4.0: missing "'" at end of line
1257 empty.y:4.8: warning: empty character literal
1258 empty.y:4.8: missing "'" at end of file
1266 AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
1268 AT_BISON_CHECK([two.y], [1], [],
1269 [[two.y:2.8-11: warning: extra characters in character literal
1270 two.y:3.8-4.0: warning: extra characters in character literal
1271 two.y:3.8-4.0: missing "'" at end of line
1272 two.y:4.8-10: warning: extra characters in character literal
1273 two.y:4.8-10: missing "'" at end of file
1281 AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
1283 AT_BISON_CHECK([three.y], [1], [],
1284 [[three.y:2.8-12: warning: extra characters in character literal
1285 three.y:3.8-4.0: warning: extra characters in character literal
1286 three.y:3.8-4.0: missing "'" at end of line
1287 three.y:4.8-11: warning: extra characters in character literal
1288 three.y:4.8-11: missing "'" at end of file
1293 ## ------------------------- ##
1294 ## Bad escapes in literals. ##
1295 ## ------------------------- ##
1297 AT_SETUP([[Bad escapes in literals]])
1301 start: '\777' '\0' '\xfff' '\x0'
1302 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
1306 # It is not easy to create special characters, we cannot even trust tr.
1307 # Beside we cannot even expect "echo '\0'" to output two characters
1308 # (well three with \n): at least Bash 3.2 converts the two-character
1309 # sequence "\0" into a single NUL character.
1310 AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
1313 AT_BISON_CHECK([input.y], [1], [],
1314 [[input.y:2.9-12: invalid number after \-escape: 777
1315 input.y:2.8-13: warning: empty character literal
1316 input.y:2.16-17: invalid number after \-escape: 0
1317 input.y:2.15-18: warning: empty character literal
1318 input.y:2.21-25: invalid number after \-escape: xfff
1319 input.y:2.20-26: warning: empty character literal
1320 input.y:2.29-31: invalid number after \-escape: x0
1321 input.y:2.28-32: warning: empty character literal
1322 input.y:3.9-14: invalid number after \-escape: uffff
1323 input.y:3.8-15: warning: empty character literal
1324 input.y:3.18-23: invalid number after \-escape: u0000
1325 input.y:3.17-24: warning: empty character literal
1326 input.y:3.27-36: invalid number after \-escape: Uffffffff
1327 input.y:3.26-37: warning: empty character literal
1328 input.y:3.40-49: invalid number after \-escape: U00000000
1329 input.y:3.39-50: warning: empty character literal
1330 input.y:4.9-10: invalid character after \-escape: ' '
1331 input.y:4.8-11: warning: empty character literal
1332 input.y:4.14-15: invalid character after \-escape: A
1333 input.y:4.13-16: warning: empty character literal
1334 input.y:5.9-16: invalid character after \-escape: \t
1335 input.y:5.17: invalid character after \-escape: \f
1336 input.y:5.18: invalid character after \-escape: \0
1337 input.y:5.19: invalid character after \-escape: \001
1342 ## ------------------------- ##
1343 ## LAC: Errors for %define. ##
1344 ## ------------------------- ##
1346 AT_SETUP([[LAC: Errors for %define]])
1348 AT_DATA([[input.y]],
1353 # parse.lac.* options are useless if LAC isn't actually activated.
1354 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
1356 [[<command line>:2: %define variable 'parse.lac.es-capacity-initial' is not used
1358 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
1360 [[<command line>:2: %define variable 'parse.lac.memory-trace' is not used
1365 ## --------------------------------------------- ##
1366 ## -Werror is not affected by -Wnone and -Wall. ##
1367 ## --------------------------------------------- ##
1369 AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
1371 AT_DATA([[input.y]],
1376 # -Werror is not enabled by -Wall or equivalent.
1377 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
1378 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1380 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
1381 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1383 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
1384 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1387 # -Werror is not disabled by -Wnone or equivalent.
1388 AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]])
1389 AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]],
1390 [[bison: warnings being treated as errors
1391 input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1394 AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])
1399 ## ------------------------------------------------------ ##
1400 ## %name-prefix and %define api.prefix are incompatible. ##
1401 ## ------------------------------------------------------ ##
1403 AT_SETUP([[%name-prefix and %define api.prefix are incompatible]])
1405 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
1406 # --------------------------------------------
1407 m4_pushdef([AT_TEST],
1408 [AT_DATA([[input.y]],
1413 AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
1414 [[$3: '%name-prefix' and '%define api.prefix' cannot be used together
1418 AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
1419 AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:2])
1420 AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:2])
1421 AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
1423 m4_popdef([AT_TEST])
1428 ## -------------- ##
1430 ## -------------- ##
1432 AT_SETUP([[Stray $ or @]])
1434 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
1435 # check that the warnings are reported once, not three times.
1437 AT_DATA_GRAMMAR([[input.y]],
1439 %destructor { $%; @%; } <*> exp TOK;
1440 %initial-action { $%; @%; };
1441 %printer { $%; @%; } <*> exp TOK;
1443 exp: TOK { $%; @%; $$ = $1; };
1446 AT_BISON_CHECK([[input.y]], 0, [],
1447 [[input.y:10.19: warning: stray '$'
1448 input.y:10.23: warning: stray '@'
1449 input.y:11.19: warning: stray '$'
1450 input.y:11.23: warning: stray '@'
1451 input.y:12.19: warning: stray '$'
1452 input.y:12.23: warning: stray '@'
1453 input.y:14.19: warning: stray '$'
1454 input.y:14.23: warning: stray '@'
1461 ## ---------------- ##
1462 ## Code injection. ##
1463 ## ---------------- ##
1466 AT_SETUP([[Code injection]])
1468 m4_pattern_allow([^m4_errprintn$])
1472 # Try to have MACRO be run by bison.
1473 m4_pushdef([AT_TEST],
1474 [AT_DATA([[input.y]],
1475 [[%type <$1(DEAD %type)> exp
1476 %token <$1(DEAD %token)> a
1480 $<$1(DEAD %initial-action)>$
1485 $<$1(DEAD %printer)>$
1493 $1(DEAD %parse-param)
1501 $<$1(DEAD action 1)>$
1502 $<$1(DEAD action 2)>1
1503 $<$1(DEAD action 3)>last
1504 $<$1(DEAD action 4)>0
1509 # FIXME: Provide a means to iterate over all the skeletons.
1510 AT_BISON_CHECK([[-d input.y]])
1511 AT_BISON_CHECK([[-d -S glr.c input.y]])
1512 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
1513 AT_BISON_CHECK([[-d -S glr.cc input.y]])
1514 AT_BISON_CHECK([[ -S lalr1.java input.y]])
1517 AT_TEST([m4_errprintn])
1518 AT_TEST([@:>@m4_errprintn])
1520 m4_popdef([AT_TEST])