1 # Checking the Bison scanner. -*- Autotest -*-
3 # Copyright (C) 2002-2013 Free Software Foundation, Inc.
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 AT_BANNER([[Input Processing.]])
20 # Mostly test that we are robust to mistakes.
23 ## ----------------- ##
24 ## Invalid options. ##
25 ## ----------------- ##
27 AT_SETUP([Invalid options])
34 # We used to accept these, as -f, --report and others were sharing
36 AT_BISON_CHECK([-ferror=caret input.y], [1], [], [ignore])
37 AT_BISON_CHECK([--report=error=itemsets input.y], [1], [], [ignore])
39 # We used to accept any character after "-Werror", instead of ensuring
41 AT_BISON_CHECK([-Werror?all input.y], [1], [], [ignore])
46 ## ---------------- ##
48 ## ---------------- ##
50 AT_SETUP([Invalid inputs])
62 AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]])
64 AT_BISON_CHECK([input.y], [1], [],
65 [[input.y:1.1-2: error: invalid characters: '\0\001\002\377?'
66 input.y:3.1: error: invalid character: '?'
67 input.y:4.14: error: invalid character: '}'
68 input.y:5.1: error: invalid character: '%'
69 input.y:5.2: error: invalid character: '&'
70 input.y:6.1-17: error: invalid directive: '%a-does-not-exist'
71 input.y:7.1: error: invalid character: '%'
72 input.y:7.2: error: invalid character: '-'
73 input.y:8.1-9.0: error: missing '%}' at end of file
74 input.y:8.1-9.0: error: syntax error, unexpected %{...%}
80 AT_SETUP([Invalid inputs with {}])
82 # We used to SEGV here. See
83 # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
95 AT_BISON_CHECK([input.y], [1], [],
96 [[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...}
107 AT_SETUP([Invalid $n and @n])
111 exp: %empty { $$ = $1 ; };
112 exp: %empty { @$ = @1 ; };
115 AT_BISON_CHECK([-fcaret input.y], [1], [],
116 [[input.y:2.20-21: error: integer out of range: '$1'
117 exp: %empty { $$ = $1 ; };
119 input.y:3.20-21: error: integer out of range: '@1'
120 exp: %empty { @$ = @1 ; };
131 AT_SETUP([Type Clashes])
134 [[%union { int bar; }
138 exp: foo { $$; } foo { $2; } foo
144 AT_BISON_CHECK([-fcaret input.y], [1], [],
145 [[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type
146 exp: foo { $$; } foo { $2; } foo
148 input.y:5.24-25: error: $2 of 'exp' has no declared type
149 exp: foo { $$; } foo { $2; } foo
151 input.y:5.6-32: warning: type clash on default action: <bar> != <> [-Wother]
152 exp: foo { $$; } foo { $2; } foo
153 ^^^^^^^^^^^^^^^^^^^^^^^^^^^
154 input.y:6.6-8: warning: type clash on default action: <bar> != <> [-Wother]
157 input.y:7.6-11: warning: empty rule for typed nonterminal, and no action [-Wother]
165 # _AT_UNUSED_VALUES_DECLARATIONS()
166 # --------------------------------
167 # Generate the token, type, and destructor
168 # declarations for the unused values tests.
169 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
170 [[[%token <integer> INT;
171 %type <integer> a b c d e f g h i j k l;
172 %destructor { destroy ($$); } INT a b c d e f g h i j k l;]]])
175 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
176 # ----------------------------------------------------------------
177 # Generate a grammar to test unused values, compile it, run it. If
178 # DECLARATIONS_AFTER is set, then the token, type, and destructor
179 # declarations are generated after the rules rather than before. If
180 # CHECK_MIDRULE_VALUES is set, then --warnings=midrule-values is set.
181 m4_define([AT_CHECK_UNUSED_VALUES],
186 ], [_AT_UNUSED_VALUES_DECLARATIONS
189 'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; }
190 | 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; }
191 | 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; }
194 a: INT | INT { } INT { } INT { };
196 c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; };
197 d: INT | INT { } INT { $]1[; } INT { $<integer>2; };
198 e: INT | INT { } INT { } INT { $]1[; };
199 f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; };
200 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
201 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
202 i: INT | INT INT { } { $]$[ = $]1[ + $]2[; };
203 j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; };
204 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
205 l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [
206 _AT_UNUSED_VALUES_DECLARATIONS])
209 AT_BISON_CHECK(m4_ifval($2, [--warnings=midrule-values ])[-fcaret input.y],
211 [[input.y:11.10-32: warning: unset value: $][$ [-Wother]
212 a: INT | INT { } INT { } INT { };
213 ^^^^^^^^^^^^^^^^^^^^^^^
214 input.y:11.10-12: warning: unused value: $][1 [-Wother]
215 a: INT | INT { } INT { } INT { };
217 input.y:11.18-20: warning: unused value: $][3 [-Wother]
218 a: INT | INT { } INT { } INT { };
220 input.y:11.26-28: warning: unused value: $][5 [-Wother]
221 a: INT | INT { } INT { } INT { };
223 input.y:12.10-15: warning: empty rule for typed nonterminal, and no action [-Wother]
226 ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $][$ [-Wmidrule-values]
227 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
229 input.y:13.26-41: warning: unset value: $][$ [-Wmidrule-values]
230 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
232 ]]])[[input.y:13.10-62: warning: unset value: $][$ [-Wother]
233 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
234 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
235 input.y:13.22-24: warning: unused value: $][3 [-Wother]
236 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
238 input.y:13.43-45: warning: unused value: $][5 [-Wother]
239 c: INT | INT { $][1; } INT { $<integer>2; } INT { $<integer>4; };
241 ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $][$ [-Wmidrule-values]
242 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
244 ]]])[[input.y:14.10-49: warning: unset value: $][$ [-Wother]
245 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
246 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
247 input.y:14.18-20: warning: unused value: $][3 [-Wother]
248 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
250 input.y:14.30-32: warning: unused value: $][5 [-Wother]
251 d: INT | INT { } INT { $][1; } INT { $<integer>2; };
253 input.y:15.10-37: warning: unset value: $][$ [-Wother]
254 e: INT | INT { } INT { } INT { $][1; };
255 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
256 input.y:15.18-20: warning: unused value: $][3 [-Wother]
257 e: INT | INT { } INT { } INT { $][1; };
259 input.y:15.27-29: warning: unused value: $][5 [-Wother]
260 e: INT | INT { } INT { } INT { $][1; };
262 input.y:17.10-58: warning: unset value: $][$ [-Wother]
263 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
264 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
265 input.y:17.10-12: warning: unused value: $][1 [-Wother]
266 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
268 ]]m4_ifval($2, [[[input.y:17.14-29: warning: unused value: $][2 [-Wmidrule-values]
269 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
271 ]]])[[input.y:17.31-33: warning: unused value: $][3 [-Wother]
272 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
274 ]]m4_ifval($2, [[[input.y:17.35-50: warning: unused value: $][4 [-Wmidrule-values]
275 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
277 ]]])[[input.y:17.52-54: warning: unused value: $][5 [-Wother]
278 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
280 input.y:18.10-72: warning: unset value: $][$ [-Wother]
281 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
282 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
283 input.y:18.10-12: warning: unused value: $][1 [-Wother]
284 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
286 input.y:18.31-33: warning: unused value: $][3 [-Wother]
287 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
289 ]]m4_ifval($2, [[[input.y:18.35-64: warning: unused value: $][4 [-Wmidrule-values]
290 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
291 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
292 ]]])[[input.y:18.66-68: warning: unused value: $][5 [-Wother]
293 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
295 ]]m4_ifval($2, [[[input.y:20.18-37: warning: unused value: $][3 [-Wmidrule-values]
296 j: INT | INT INT { $<integer>$ = 1; } { $][$ = $][1 + $][2; };
298 ]]])[[input.y:21.10-68: warning: unset value: $][$ [-Wother]
299 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
300 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
301 input.y:21.10-12: warning: unused value: $][1 [-Wother]
302 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
304 input.y:21.14-16: warning: unused value: $][2 [-Wother]
305 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
307 ]]m4_ifval($2, [[[input.y:21.35-64: warning: unused value: $][4 [-Wmidrule-values]
308 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
309 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
313 ## --------------- ##
315 ## --------------- ##
317 AT_SETUP([Unused values])
318 AT_CHECK_UNUSED_VALUES
319 AT_CHECK_UNUSED_VALUES(, [1])
323 ## ------------------------------------------ ##
324 ## Unused values before symbol declarations. ##
325 ## ------------------------------------------ ##
327 AT_SETUP([Unused values before symbol declarations])
328 AT_CHECK_UNUSED_VALUES([1])
329 AT_CHECK_UNUSED_VALUES([1], [1])
333 ## --------------------------------------------- ##
334 ## Default %printer and %destructor redeclared. ##
335 ## --------------------------------------------- ##
337 AT_SETUP([Default %printer and %destructor redeclared])
340 [[%destructor { destroy ($$); } <*> <*>
341 %printer { print ($$); } <*> <*>
343 %destructor { destroy ($$); } <*>
344 %printer { print ($$); } <*>
346 %destructor { destroy ($$); } <> <>
347 %printer { print ($$); } <> <>
349 %destructor { destroy ($$); } <>
350 %printer { print ($$); } <>
356 %destructor { destroy ($$); } <*>;
357 %printer { print ($$); } <*>;
359 %destructor { destroy ($$); } <>;
360 %printer { print ($$); } <>;
363 AT_BISON_CHECK([-fcaret input.y], [1], [],
364 [[input.y:1.13-29: error: %destructor redeclaration for <*>
365 %destructor { destroy ($$); } <*> <*>
367 input.y:1.13-29: previous declaration
368 %destructor { destroy ($$); } <*> <*>
370 input.y:2.10-24: error: %printer redeclaration for <*>
371 %printer { print ($$); } <*> <*>
373 input.y:2.10-24: previous declaration
374 %printer { print ($$); } <*> <*>
376 input.y:4.13-29: error: %destructor redeclaration for <*>
377 %destructor { destroy ($$); } <*>
379 input.y:1.13-29: previous declaration
380 %destructor { destroy ($$); } <*> <*>
382 input.y:5.10-24: error: %printer redeclaration for <*>
383 %printer { print ($$); } <*>
385 input.y:2.10-24: previous declaration
386 %printer { print ($$); } <*> <*>
388 input.y:7.13-29: error: %destructor redeclaration for <>
389 %destructor { destroy ($$); } <> <>
391 input.y:7.13-29: previous declaration
392 %destructor { destroy ($$); } <> <>
394 input.y:8.10-24: error: %printer redeclaration for <>
395 %printer { print ($$); } <> <>
397 input.y:8.10-24: previous declaration
398 %printer { print ($$); } <> <>
400 input.y:10.13-29: error: %destructor redeclaration for <>
401 %destructor { destroy ($$); } <>
403 input.y:7.13-29: previous declaration
404 %destructor { destroy ($$); } <> <>
406 input.y:11.10-24: error: %printer redeclaration for <>
407 %printer { print ($$); } <>
409 input.y:8.10-24: previous declaration
410 %printer { print ($$); } <> <>
412 input.y:17.13-29: error: %destructor redeclaration for <*>
413 %destructor { destroy ($$); } <*>;
415 input.y:4.13-29: previous declaration
416 %destructor { destroy ($$); } <*>
418 input.y:18.10-24: error: %printer redeclaration for <*>
419 %printer { print ($$); } <*>;
421 input.y:5.10-24: previous declaration
422 %printer { print ($$); } <*>
424 input.y:20.13-29: error: %destructor redeclaration for <>
425 %destructor { destroy ($$); } <>;
427 input.y:10.13-29: previous declaration
428 %destructor { destroy ($$); } <>
430 input.y:21.10-24: error: %printer redeclaration for <>
431 %printer { print ($$); } <>;
433 input.y:11.10-24: previous declaration
434 %printer { print ($$); } <>
441 ## ---------------------------------------------- ##
442 ## Per-type %printer and %destructor redeclared. ##
443 ## ---------------------------------------------- ##
445 AT_SETUP([Per-type %printer and %destructor redeclared])
448 [[%destructor { destroy ($$); } <field1> <field2>
449 %printer { print ($$); } <field1> <field2>
451 %destructor { destroy ($$); } <field1> <field1>
452 %printer { print ($$); } <field2> <field2>
458 %destructor { destroy ($$); } <field2> <field1>;
459 %printer { print ($$); } <field2> <field1>;
462 AT_BISON_CHECK([input.y], [1], [],
463 [[input.y:4.13-29: error: %destructor redeclaration for <field1>
464 input.y:1.13-29: previous declaration
465 input.y:4.13-29: error: %destructor redeclaration for <field1>
466 input.y:4.13-29: previous declaration
467 input.y:5.10-24: error: %printer redeclaration for <field2>
468 input.y:2.10-24: previous declaration
469 input.y:5.10-24: error: %printer redeclaration for <field2>
470 input.y:5.10-24: previous declaration
471 input.y:11.13-29: error: %destructor redeclaration for <field2>
472 input.y:1.13-29: previous declaration
473 input.y:11.13-29: error: %destructor redeclaration for <field1>
474 input.y:4.13-29: previous declaration
475 input.y:12.10-24: error: %printer redeclaration for <field2>
476 input.y:5.10-24: previous declaration
477 input.y:12.10-24: error: %printer redeclaration for <field1>
478 input.y:2.10-24: previous declaration
483 ## ------------------- ##
484 ## Undefined symbols. ##
485 ## ------------------- ##
487 AT_SETUP([Undefined symbols])
490 [[%printer {} foo baz
497 AT_BISON_CHECK([-fcaret input.y], [1], [],
498 [[input.y:2.16-18: error: symbol bar is used, but is not defined as a token and has no rules
501 input.y:1.17-19: warning: symbol baz is used, but is not defined as a token and has no rules [-Wother]
504 input.y:1.13-15: warning: symbol foo is used, but is not defined as a token and has no rules [-Wother]
507 input.y:3.13-15: warning: symbol qux is used, but is not defined as a token and has no rules [-Wother]
515 ## ----------------------------------------------------- ##
516 ## Unassociated types used for a printer or destructor. ##
517 ## ----------------------------------------------------- ##
519 AT_SETUP([Unassociated types used for a printer or destructor])
522 [[%token <type1> tag1
525 %printer { } <type1> <type3>
526 %destructor { } <type2> <type4>
536 AT_BISON_CHECK([input.y], [0], [],
537 [[input.y:4.22-28: warning: type <type3> is used, but is not associated to any symbol [-Wother]
538 input.y:5.25-31: warning: type <type4> is used, but is not associated to any symbol [-Wother]
544 ## --------------------------------- ##
545 ## Useless printers or destructors. ##
546 ## --------------------------------- ##
548 AT_SETUP([Useless printers or destructors])
550 # AT_TEST([INPUT], [STDERR])
551 # --------------------------
552 m4_pushdef([AT_TEST],
553 [AT_DATA([[input.y]],
556 AT_BISON_CHECK([input.y], [0], [], [$2
559 AT_TEST([[%token <type1> token1
560 %token <type2> token2
561 %token <type3> token3
562 %token <type4> token4
563 %token <type5> token51 token52
564 %token <type6> token61 token62
565 %token <type7> token7
568 %destructor {} token2
570 %destructor {} token61
575 %destructor {} <type2>
577 %destructor {} <type4>
580 %destructor {} <type6>
582 %destructor {} <type7>
586 [[input.y:16.13-19: warning: useless %printer for type <type1> [-Wother]
587 input.y:17.16-22: warning: useless %destructor for type <type2> [-Wother]]])
589 # If everybody is typed, <> is useless.
590 AT_TEST([[%type <type> exp
595 [[input.y:3.13-14: warning: useless %printer for type <> [-Wother]]])
597 # If nobody is typed, <*> is useless.
602 [[input.y:2.16-18: warning: useless %printer for type <*> [-Wother]]])
609 ## ---------------------------------------- ##
610 ## Unused values with default %destructor. ##
611 ## ---------------------------------------- ##
613 AT_SETUP([Unused values with default %destructor])
616 [[%destructor { destroy ($$); } <>
621 start: end end tagged tagged { $<tag>1; $3; } ;
626 AT_BISON_CHECK([-fcaret input.y], [0], [],
627 [[input.y:6.8-45: warning: unset value: $$ [-Wother]
628 start: end end tagged tagged { $<tag>1; $3; } ;
629 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
630 input.y:6.12-14: warning: unused value: $2 [-Wother]
631 start: end end tagged tagged { $<tag>1; $3; } ;
633 input.y:7.6-8: warning: unset value: $$ [-Wother]
639 [[%destructor { destroy ($$); } <*>
644 start: end end tagged tagged { $<tag>1; $3; } ;
649 AT_BISON_CHECK([input.y], [0], [],
650 [[input.y:6.23-28: warning: unused value: $4 [-Wother]
651 input.y:8.9-11: warning: unset value: $$ [-Wother]
657 ## ----------------------------------------- ##
658 ## Unused values with per-type %destructor. ##
659 ## ----------------------------------------- ##
661 AT_SETUP([Unused values with per-type %destructor])
664 [[%destructor { destroy ($$); } <field1>
665 %type <field1> start end
669 start: end end { $1; } ;
673 AT_BISON_CHECK([-fcaret input.y], [0], [],
674 [[input.y:6.8-22: warning: unset value: $$ [-Wother]
675 start: end end { $1; } ;
677 input.y:6.12-14: warning: unused value: $2 [-Wother]
678 start: end end { $1; } ;
680 input.y:7.6-8: warning: unset value: $$ [-Wother]
688 ## ---------------------- ##
689 ## Incompatible Aliases. ##
690 ## ---------------------- ##
692 AT_SETUP([Incompatible Aliases])
699 %destructor {bar} foo
704 %destructor {baz} "foo"
711 AT_BISON_CHECK([-fcaret input.y], [1], [],
712 [[input.y:8.7-11: error: %type redeclaration for foo
715 input.y:3.7-11: previous declaration
718 input.y:10.13-17: error: %destructor redeclaration for foo
719 %destructor {baz} "foo"
721 input.y:5.13-17: previous declaration
722 %destructor {bar} foo
724 input.y:9.10-14: error: %printer redeclaration for foo
727 input.y:4.10-14: previous declaration
730 input.y:11.1-5: error: %left redeclaration for foo
733 input.y:6.1-5: previous declaration
742 ## ----------------------- ##
743 ## Torturing the Scanner. ##
744 ## ----------------------- ##
746 # Be sure to compile and run, so that the C compiler checks what
749 AT_SETUP([Torturing the Scanner])
751 AT_BISON_OPTION_PUSHDEFS
752 AT_DATA([input.y], [])
753 AT_BISON_CHECK([input.y], [1], [],
754 [[input.y:1.1: error: syntax error, unexpected end of file
761 AT_BISON_CHECK([-fcaret input.y], [1], [],
762 [[input.y:1.1-2: error: syntax error, unexpected {...}
768 AT_DATA_GRAMMAR([input.y],
770 /* This is seen in GCC: a %{ and %} in middle of a comment. */
771 const char *foo = "So %{ and %} can be here too.";
774 /* These examples test Bison while not stressing C compilers too much.
775 Many C compilers mishandle backslash-newlines, so this part of the
776 test is inside "#if 0". The comment and string are written so that
777 the "#endif" will be seen regardless of the C compiler bugs that we
780 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
783 The Apple Darwin compiler (as of late 2002) mishandles
784 \\[newline]' within a character constant.
789 * A comment with backslash-newlines in it. %} *\
792 /* { Close the above comment, if the C compiler mishandled it. */
795 " A string with backslash-newlines in it %{ %} \\
799 char apostrophe = '\'';
806 /* %{ and %} can be here too. */
809 /* Exercise pre-prologue dependency to %union. */
813 /* Exercise M4 quoting: '@:>@@:>@', 0. */
815 /* Also exercise %union. */
818 value ival; /* A comment to exercise an old bug. */
822 /* Exercise post-prologue dependency to %union. */
824 static YYSTYPE value_as_yystype (value val);
826 /* Exercise quotes in declarations. */
827 char quote[] = "@:>@@:>@,";
837 /* Exercise quotes in strings. */
838 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
841 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
842 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
844 /* Exercise quotes in braces. */
845 char tmp[] = "@<:@%c@:>@,\n";
850 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
851 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
852 output.or.oline.opt: %empty;|oline;;|output;;;
853 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
855 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
858 value_as_yystype (value val)
868 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
871 static size_t toknum;
872 assert (toknum < sizeof input);
873 yylval = value_as_yystype (input[toknum]);
874 return input[toknum++];
878 # Pacify Emacs'font-lock-mode: "
887 AT_BISON_OPTION_POPDEFS
889 AT_BISON_CHECK([-d -v -o input.c input.y])
890 AT_COMPILE([input.o])
892 AT_COMPILE([input], [input.o main.o])
893 AT_PARSER_CHECK([./input], 0,
900 ## ---------------------- ##
901 ## Typed symbol aliases. ##
902 ## ---------------------- ##
904 AT_SETUP([Typed symbol aliases])
906 # Bison 2.0 broke typed symbol aliases - ensure they work.
908 AT_DATA_GRAMMAR([input.y],
913 %token <val> MY_TOKEN "MY TOKEN"
920 AT_BISON_CHECK([-o input.c input.y])
929 m4_define([AT_CHECK_REQUIRE],
930 [AT_SETUP([Require $1])
931 AT_DATA_GRAMMAR([input.y],
936 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
940 AT_CHECK_REQUIRE(1.0, 0)
941 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
942 ## FIXME: Some day augment this version number.
943 AT_CHECK_REQUIRE(100.0, 63)
946 ## ------------------------------------- ##
947 ## String aliases for character tokens. ##
948 ## ------------------------------------- ##
950 AT_SETUP([String aliases for character tokens])
952 # Bison once thought a character token and its alias were different
953 # symbols with the same user token number.
955 AT_DATA_GRAMMAR([input.y],
962 AT_BISON_CHECK([-o input.c input.y])
973 AT_BISON_OPTION_PUSHDEFS
974 AT_DATA_GRAMMAR([input.y],
976 %token WITHOUT_DASH "WITHOUT-DASH"
978 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
984 start: with-dash without_dash with.period without_period;
985 with-dash: WITH-DASH;
986 without_dash: "WITHOUT-DASH";
987 with.period: WITH.PERIOD;
988 without_period: "WITHOUT.PERIOD";
993 AT_BISON_OPTION_POPDEFS
995 # POSIX Yacc accept periods, but not dashes.
996 AT_BISON_CHECK([--yacc -Wno-error input.y], [], [],
997 [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc]
998 input.y:20.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc]
1001 # So warn about them.
1002 AT_BISON_CHECK([-Wyacc input.y], [], [],
1003 [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Wyacc]
1004 input.y:20.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash [-Wyacc]
1007 # Dashes are fine for GNU Bison.
1008 AT_BISON_CHECK([-o input.c input.y])
1010 # Make sure we don't export silly token identifiers with periods or dashes.
1011 AT_COMPILE([input.o])
1014 # Periods are genuine letters, they can start identifiers.
1015 # Digits and dashes cannot.
1016 AT_DATA_GRAMMAR([input.y],
1024 AT_BISON_CHECK([-o input.c input.y], [1], [],
1025 [[input.y:10.10: error: invalid character: '-'
1026 input.y:11.10-16: error: invalid identifier: '1NV4L1D'
1027 input.y:12.10: error: invalid character: '-'
1033 ## ----------------- ##
1034 ## Numbered tokens. ##
1035 ## ----------------- ##
1037 AT_SETUP([Numbered tokens])
1039 AT_DATA_GRAMMAR([redecl.y],
1040 [[%token DECIMAL_1 11259375
1041 HEXADECIMAL_1 0xabcdef
1042 HEXADECIMAL_2 0xFEDCBA
1045 start: DECIMAL_1 HEXADECIMAL_2;
1048 AT_BISON_CHECK([redecl.y], [1], [],
1049 [[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1
1050 redecl.y:9.8-16: previous declaration for DECIMAL_1
1051 redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2
1052 redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
1055 AT_DATA_GRAMMAR([too-large.y],
1056 [[%token TOO_LARGE_DEC 999999999999999999999
1057 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
1059 start: TOO_LARGE_DEC TOO_LARGE_HEX
1063 AT_BISON_CHECK([too-large.y], [1], [],
1064 [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
1065 too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
1071 ## --------------------- ##
1072 ## Unclosed constructs. ##
1073 ## --------------------- ##
1075 AT_SETUP([Unclosed constructs])
1077 # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed
1078 # constructs, so they were prepended to whatever it STRING_GROW'ed
1079 # next. It also threw them away rather than returning them to the
1080 # parser. The effect was confusing subsequent error messages.
1085 %token AB "ab" // Used to complain that "ab" was already used.
1088 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
1094 // Used to report a syntax error because it didn't see any kind of symbol
1100 // Used to report a syntax error because it didn't see braced code.
1101 %destructor { free ($$)
1104 AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [],
1105 [[input.y:1.10-2.0: error: missing '"' at end of line
1108 input.y:4.10-5.0: error: missing "'" at end of line
1111 input.y:14.11-15.0: error: missing "'" at end of line
1114 input.y:16.11-17.0: error: missing '"' at end of line
1117 input.y:19.13-20.0: error: missing '}' at end of file
1118 %destructor { free ($$)
1120 input.y:20.1: error: syntax error, unexpected end of file
1126 ## ------------------------- ##
1127 ## %start after first rule. ##
1128 ## ------------------------- ##
1130 AT_SETUP([%start after first rule])
1132 # Bison once complained that a %start after the first rule was a
1133 # redeclaration of the start symbol.
1137 false_start: %empty;
1138 start: false_start ;
1142 AT_BISON_CHECK([-o input.c input.y])
1147 ## --------------------- ##
1148 ## %prec takes a token. ##
1149 ## --------------------- ##
1151 AT_SETUP([%prec takes a token])
1153 # Bison once allowed %prec sym where sym was a nonterminal.
1157 start: PREC %prec PREC ;
1161 AT_BISON_CHECK([input.y], [1], [],
1162 [[input.y:3.1-4: error: rule given for PREC, which is a token
1168 ## ------------------------------- ##
1169 ## %prec's token must be defined. ##
1170 ## ------------------------------- ##
1172 AT_SETUP([[%prec's token must be defined]])
1174 # According to POSIX, a %prec token must be defined separately.
1176 AT_DATA([[input.y]],
1181 AT_BISON_CHECK([[input.y]], [[0]], [],
1182 [[input.y:2.8-17: warning: token for %prec is not defined: PREC [-Wother]
1188 ## -------------------------------- ##
1189 ## Reject unused %code qualifiers. ##
1190 ## -------------------------------- ##
1192 AT_SETUP([Reject unused %code qualifiers])
1194 AT_DATA([input-c.y],
1202 AT_BISON_CHECK([[input-c.y]], [[1]], [],
1203 [[input-c.y:1.7: error: %code qualifier 'q' is not used
1204 input-c.y:2.7-9: error: %code qualifier 'bad' is not used
1205 input-c.y:3.7-9: error: %code qualifier 'bad' is not used
1206 input-c.y:4.7-12: error: %code qualifier 'format' is not used
1209 AT_DATA([input-c-glr.y],
1216 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
1217 [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used
1218 input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used
1219 input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used
1222 AT_DATA([input-c++.y],
1229 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
1230 [[input-c++.y:1.7: error: %code qualifier 'q' is not used
1231 input-c++.y:2.7-9: error: %code qualifier 'bad' is not used
1232 input-c++.y:3.8: error: %code qualifier 'q' is not used
1235 AT_DATA([input-c++-glr.y],
1242 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
1243 [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used
1244 input-c++-glr.y:2.7: error: %code qualifier 'q' is not used
1245 input-c++-glr.y:3.7: error: %code qualifier 'q' is not used
1248 AT_DATA([special-char-@@.y],
1255 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
1256 [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used
1257 special-char-@@.y:2.7: error: %code qualifier 'q' is not used
1258 special-char-@@.y:3.7: error: %code qualifier 'q' is not used
1261 AT_DATA([special-char-@:>@.y],
1268 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
1269 [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used
1270 special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used
1271 special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used
1277 ## ---------------- ##
1278 ## %define errors. ##
1279 ## ---------------- ##
1281 AT_SETUP([%define errors])
1283 AT_DATA([input-redefined.y],
1284 [[%define var "value1"
1285 %define var "value1"
1286 %define var "value2"
1287 %define special1 "@:>@"
1288 %define special2 "@<:@"
1293 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
1294 [[input-redefined.y:2.9-11: error: %define variable 'var' redefined
1295 input-redefined.y:1.9-11: previous definition
1296 input-redefined.y:3.10-12: error: %define variable 'var' redefined
1297 input-redefined.y:2.9-11: previous definition
1300 AT_DATA([input-unused.y],
1301 [[%define var "value"
1306 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
1307 [[input-unused.y:1.9-11: error: %define variable 'var' is not used
1313 ## ----------------------------------- ##
1314 ## %define, --define, --force-define. ##
1315 ## ----------------------------------- ##
1317 AT_SETUP([[%define, --define, --force-define]])
1320 [[m4@&t@_divert_push(0)@
1321 @output(b4_parser_file_name@)@
1322 [var-dd: ]b4_percent_define_get([[var-dd]])[
1323 var-ff: ]b4_percent_define_get([[var-ff]])[
1324 var-dfg: ]b4_percent_define_get([[var-dfg]])[
1325 var-fd: ]b4_percent_define_get([[var-fd]])
1326 m4@&t@_divert_pop(0)
1328 AT_DATA([[input.y]],
1329 [[%define var-dfg "gram"
1333 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
1334 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
1335 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
1336 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
1337 --skeleton ./skel.c input.y]])
1338 AT_CHECK([[cat input.tab.c]], [[0]],
1345 AT_DATA([[input-dg.y]],
1346 [[%define var "gram"
1350 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
1351 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1352 <command line>:2: previous definition
1355 AT_DATA([[input-dg.y]],
1356 [[%define var "gram"
1360 AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
1361 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1364 <command line>:3: previous definition
1367 AT_DATA([[input-unused.y]],
1371 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
1372 [[<command line>:2: error: %define variable 'unused-d' is not used
1373 <command line>:3: error: %define variable 'unused-f' is not used
1378 ## --------------------------- ##
1379 ## %define Boolean variables. ##
1380 ## --------------------------- ##
1382 AT_SETUP([["%define" Boolean variables]])
1386 %define public "maybe"
1387 %define parser_class_name "Input"
1392 AT_BISON_CHECK([[Input.y]], [1], [],
1393 [[Input.y:2.9-14: error: invalid value for %define Boolean variable 'public'
1398 ## ------------------------ ##
1399 ## %define enum variables. ##
1400 ## ------------------------ ##
1402 AT_SETUP([["%define" enum variables]])
1404 # Check errors from the front-end, and the back-end. Since the
1405 # front-end quits before calling the back-end, these tests cannot be
1409 AT_DATA([[input.y]],
1410 [[%define lr.default-reduction bogus
1414 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
1415 [[input.y:1.9-28: error: invalid value for %define variable 'lr.default-reduction': 'bogus'
1416 %define lr.default-reduction bogus
1417 ^^^^^^^^^^^^^^^^^^^^
1418 input.y:1.9-28: accepted value: 'most'
1419 input.y:1.9-28: accepted value: 'consistent'
1420 input.y:1.9-28: accepted value: 'accepting'
1424 AT_DATA([[input.y]],
1425 [[%define api.push-pull neither
1429 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
1430 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1431 %define api.push-pull neither
1433 input.y:1.9-21: accepted value: 'pull'
1434 input.y:1.9-21: accepted value: 'push'
1435 input.y:1.9-21: accepted value: 'both'
1440 ## -------------------------------- ##
1441 ## %define backward compatibility. ##
1442 ## -------------------------------- ##
1444 AT_SETUP([["%define" backward compatibility]])
1446 # The error messages tell us whether the variables are properly updated.
1447 AT_DATA([[input.y]],
1448 [[%define api.push_pull both
1449 %define lr.keep_unreachable_states maybe
1450 %define namespace "foo"
1451 %define api.namespace {foo}
1456 AT_BISON_CHECK([[-fcaret input.y]], [1], [],
1457 [[input.y:1.9-21: warning: deprecated directive, use '%define api.push-pull both' [-Wdeprecated]
1458 %define api.push_pull both
1460 input.y:2.9-34: warning: deprecated directive, use '%define lr.keep-unreachable-state maybe' [-Wdeprecated]
1461 %define lr.keep_unreachable_states maybe
1462 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1463 input.y:3.9-17: warning: deprecated directive, use '%define api.namespace foo' [-Wdeprecated]
1464 %define namespace "foo"
1466 input.y:4.9-21: error: %define variable 'api.namespace' redefined
1467 %define api.namespace {foo}
1469 input.y:3.9-17: previous definition
1470 %define namespace "foo"
1472 input.y:5.9-15: warning: deprecated directive, use '%define api.value.type variant' [-Wdeprecated]
1479 ## ------------------------- ##
1480 ## Unused %define api.pure. ##
1481 ## ------------------------- ##
1483 AT_SETUP([[Unused %define api.pure]])
1485 # AT_CHECK_API_PURE(DECLS, VALUE)
1486 # -------------------------------
1487 # Make sure Bison reports that '%define api.pure VALUE' is unused when DECLS
1489 m4_define([AT_CHECK_API_PURE],
1491 AT_DATA([[input.y]],
1492 [[%define api.pure ]$2[
1498 AT_BISON_CHECK([[input.y]], [[1]], [],
1499 [[input.y:1.9-16: error: %define variable 'api.pure' is not used
1503 AT_CHECK_API_PURE([[%language "c++"]], [[]])
1504 AT_CHECK_API_PURE([[%language "c++"]], [[false]])
1505 AT_CHECK_API_PURE([[%language "c++" %glr-parser]], [[""]])
1506 AT_CHECK_API_PURE([[%language "c++" %glr-parser]], [[false]])
1507 AT_CHECK_API_PURE([[%language "java"]], [[true]])
1508 AT_CHECK_API_PURE([[%language "java"]], [[false]])
1512 ## -------------------------------- ##
1513 ## C++ namespace reference errors. ##
1514 ## -------------------------------- ##
1516 AT_SETUP([[C++ namespace reference errors]])
1518 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
1519 # -------------------------------------------------------------
1520 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
1521 m4_define([AT_CHECK_NAMESPACE_ERROR],
1523 AT_DATA([[input.y]],
1526 %define api.namespace {]$1[}
1531 AT_BISON_CHECK([[input.y]], [1], [],
1532 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
1533 [[input.y:3.9-21: error: ]b4_arg[
1537 AT_CHECK_NAMESPACE_ERROR([[]],
1538 [[namespace reference is empty]])
1539 AT_CHECK_NAMESPACE_ERROR([[ @tb@@tb@ @tb@ @tb@]],
1540 [[namespace reference is empty]])
1541 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
1542 [[namespace reference has consecutive "::"]])
1543 AT_CHECK_NAMESPACE_ERROR([[foo:: @tb@::bar]],
1544 [[namespace reference has consecutive "::"]])
1545 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
1546 [[namespace reference has consecutive "::"]])
1547 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
1548 [[namespace reference has consecutive "::"]])
1549 AT_CHECK_NAMESPACE_ERROR([[foo::bar::@tb@::]],
1550 [[namespace reference has consecutive "::"]],
1551 [[namespace reference has a trailing "::"]])
1552 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
1553 [[namespace reference has a trailing "::"]])
1554 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: @tb@]],
1555 [[namespace reference has a trailing "::"]])
1556 AT_CHECK_NAMESPACE_ERROR([[::]],
1557 [[namespace reference has a trailing "::"]])
1561 ## ------------------------ ##
1562 ## Bad character literals. ##
1563 ## ------------------------ ##
1565 # Bison used to accept character literals that were empty or contained
1566 # too many characters.
1568 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
1569 # the final newline to be omitted. See the threads starting at
1570 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
1572 AT_SETUP([[Bad character literals]])
1579 AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
1581 AT_BISON_CHECK([-fcaret empty.y], [1], [],
1582 [[empty.y:2.8-9: warning: empty character literal [-Wother]
1585 empty.y:3.8-4.0: error: missing "'" at end of line
1588 empty.y:3.8-4.0: warning: empty character literal [-Wother]
1591 empty.y:4.8: error: missing "'" at end of file
1594 empty.y:4.8: warning: empty character literal [-Wother]
1604 AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
1606 AT_BISON_CHECK([two.y], [1], [],
1607 [[two.y:2.8-11: warning: extra characters in character literal [-Wother]
1608 two.y:3.8-4.0: error: missing "'" at end of line
1609 two.y:3.8-4.0: warning: extra characters in character literal [-Wother]
1610 two.y:4.8-10: error: missing "'" at end of file
1611 two.y:4.8-10: warning: extra characters in character literal [-Wother]
1619 AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
1621 AT_BISON_CHECK([three.y], [1], [],
1622 [[three.y:2.8-12: warning: extra characters in character literal [-Wother]
1623 three.y:3.8-4.0: error: missing "'" at end of line
1624 three.y:3.8-4.0: warning: extra characters in character literal [-Wother]
1625 three.y:4.8-11: error: missing "'" at end of file
1626 three.y:4.8-11: warning: extra characters in character literal [-Wother]
1631 ## ------------------------- ##
1632 ## Bad escapes in literals. ##
1633 ## ------------------------- ##
1635 AT_SETUP([[Bad escapes in literals]])
1639 start: '\777' '\0' '\xfff' '\x0'
1640 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
1644 # It is not easy to create special characters, we cannot even trust tr.
1645 # Beside we cannot even expect "echo '\0'" to output two characters
1646 # (well three with \n): at least Bash 3.2 converts the two-character
1647 # sequence "\0" into a single NUL character.
1648 AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
1651 AT_BISON_CHECK([input.y], [1], [],
1652 [[input.y:2.9-12: error: invalid number after \-escape: 777
1653 input.y:2.8-13: warning: empty character literal [-Wother]
1654 input.y:2.16-17: error: invalid number after \-escape: 0
1655 input.y:2.15-18: warning: empty character literal [-Wother]
1656 input.y:2.21-25: error: invalid number after \-escape: xfff
1657 input.y:2.20-26: warning: empty character literal [-Wother]
1658 input.y:2.29-31: error: invalid number after \-escape: x0
1659 input.y:2.28-32: warning: empty character literal [-Wother]
1660 input.y:3.9-14: error: invalid number after \-escape: uffff
1661 input.y:3.8-15: warning: empty character literal [-Wother]
1662 input.y:3.18-23: error: invalid number after \-escape: u0000
1663 input.y:3.17-24: warning: empty character literal [-Wother]
1664 input.y:3.27-36: error: invalid number after \-escape: Uffffffff
1665 input.y:3.26-37: warning: empty character literal [-Wother]
1666 input.y:3.40-49: error: invalid number after \-escape: U00000000
1667 input.y:3.39-50: warning: empty character literal [-Wother]
1668 input.y:4.9-10: error: invalid character after \-escape: ' '
1669 input.y:4.8-11: warning: empty character literal [-Wother]
1670 input.y:4.14-15: error: invalid character after \-escape: A
1671 input.y:4.13-16: warning: empty character literal [-Wother]
1672 input.y:5.9-16: error: invalid character after \-escape: \t
1673 input.y:5.17: error: invalid character after \-escape: \f
1674 input.y:5.18: error: invalid character after \-escape: \0
1675 input.y:5.19: error: invalid character after \-escape: \001
1680 ## ------------------------- ##
1681 ## LAC: Errors for %define. ##
1682 ## ------------------------- ##
1684 AT_SETUP([[LAC: Errors for %define]])
1686 AT_DATA([[input.y]],
1691 # parse.lac.* options are useless if LAC isn't actually activated.
1692 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
1694 [[<command line>:2: error: %define variable 'parse.lac.es-capacity-initial' is not used
1696 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
1698 [[<command line>:2: error: %define variable 'parse.lac.memory-trace' is not used
1703 ## --------------------------------------------- ##
1704 ## -Werror is not affected by -Wnone and -Wall. ##
1705 ## --------------------------------------------- ##
1707 AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
1709 AT_DATA([[input.y]],
1714 # -Werror is not enabled by -Wall or equivalent.
1715 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
1716 [[input.y:2.15: warning: stray '$' [-Wother]
1718 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
1719 [[input.y:2.15: warning: stray '$' [-Wother]
1721 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
1722 [[input.y:2.15: warning: stray '$' [-Wother]
1725 # -Werror is not disabled by -Wnone or equivalent.
1726 AT_BISON_CHECK([[-Werror,none,other input.y]], [[1]], [[]],
1727 [[input.y:2.15: error: stray '$' [-Werror=other]
1729 AT_BISON_CHECK([[-Werror,no-all,other input.y]], [[1]], [[]],
1730 [[input.y:2.15: error: stray '$' [-Werror=other]
1736 ## ------------------------------------------------------ ##
1737 ## %name-prefix and %define api.prefix are incompatible. ##
1738 ## ------------------------------------------------------ ##
1740 AT_SETUP([[%name-prefix and api.prefix are incompatible]])
1742 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
1743 # --------------------------------------------
1744 m4_pushdef([AT_TEST],
1745 [AT_DATA([[input.y]],
1750 AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
1751 [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
1755 AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
1756 AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:2])
1757 AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:2])
1758 AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
1760 m4_popdef([AT_TEST])
1765 ## -------------- ##
1767 ## -------------- ##
1769 AT_SETUP([[Stray $ or @]])
1771 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
1772 # check that the warnings are reported once, not three times.
1774 AT_DATA_GRAMMAR([[input.y]],
1776 %token <TYPE> TOK TOK2
1777 %destructor { $%; @%; } <*> exp TOK;
1778 %initial-action { $%; @%; };
1779 %printer { $%; @%; } <*> exp TOK;
1780 %{ $ @ %} // Should not warn.
1782 exp: TOK { $%; @%; $$ = $1; };
1784 $ @ // Should not warn.
1787 AT_BISON_CHECK([[-Wall input.y]], 0, [],
1788 [[input.y:11.19: warning: stray '$' [-Wother]
1789 input.y:11.23: warning: stray '@' [-Wother]
1790 input.y:12.19: warning: stray '$' [-Wother]
1791 input.y:12.23: warning: stray '@' [-Wother]
1792 input.y:13.19: warning: stray '$' [-Wother]
1793 input.y:13.23: warning: stray '@' [-Wother]
1794 input.y:16.19: warning: stray '$' [-Wother]
1795 input.y:16.23: warning: stray '@' [-Wother]
1802 ## ---------------- ##
1803 ## Code injection. ##
1804 ## ---------------- ##
1807 AT_SETUP([[Code injection]])
1809 m4_pattern_allow([^m4_errprintn$])
1813 # Try to have MACRO be run by bison.
1814 m4_pushdef([AT_TEST],
1815 [AT_DATA([[input.y]],
1816 [[%type <$1(DEAD %type)> exp
1817 %token <$1(DEAD %token)> a
1822 $<$1(DEAD %initial-action)>$
1827 $<$1(DEAD %printer)>$
1835 $1(DEAD %parse-param)
1843 $<$1(DEAD action 1)>$
1844 $<$1(DEAD action 2)>1
1845 $<$1(DEAD action 3)>name
1846 $<$1(DEAD action 4)>0
1851 # FIXME: Provide a means to iterate over all the skeletons.
1852 AT_BISON_CHECK([[-d input.y]])
1853 AT_BISON_CHECK([[-d -S glr.c input.y]])
1854 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
1855 AT_BISON_CHECK([[-d -S glr.cc input.y]])
1856 AT_BISON_CHECK([[ -S lalr1.java input.y]])
1859 AT_TEST([m4_errprintn])
1860 AT_TEST([@:>@m4_errprintn])
1862 m4_popdef([AT_TEST])
1866 ##----------------------- ##
1867 ## Deprecated directives. ##
1868 ## ---------------------- ##
1870 AT_SETUP([[Deprecated directives]])
1872 AT_KEYWORDS([[deprec]])
1874 AT_DATA_GRAMMAR([[input.y]],
1879 %file-prefix = "foo"
1897 AT_BISON_CHECK([[input.y]], [[0]], [[]],
1898 [[input.y:10.1-13: warning: deprecated directive: '%default_prec', use '%default-prec' [-Wdeprecated]
1899 input.y:11.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
1900 input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
1901 input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
1902 input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file-prefix' [-Wdeprecated]
1903 input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated]
1904 input.y:18.1-19: warning: deprecated directive: '%fixed_output-files', use '%fixed-output-files' [-Wdeprecated]
1905 input.y:20.1-13: warning: deprecated directive: '%name-prefix=', use '%name-prefix' [-Wdeprecated]
1906 input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated]
1907 input.y:22.1-16: warning: deprecated directive: '%no_default-prec', use '%no-default-prec' [-Wdeprecated]
1908 input.y:23.1-9: warning: deprecated directive: '%no_lines', use '%no-lines' [-Wdeprecated]
1909 input.y:24.1-9: warning: deprecated directive: '%output =', use '%output' [-Wdeprecated]
1910 input.y:25.1-12: warning: deprecated directive: '%pure_parser', use '%pure-parser' [-Wdeprecated]
1911 input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated]
1916 ## ---------------------------- ##
1917 ## Unput's effect on locations. ##
1918 ## ---------------------------- ##
1919 dnl When the scanner detects a deprecated construct, it unputs the correct
1920 dnl version, but it should *not* have any impact on the scanner cursor. If it
1921 dnl does, the locations of directives on the same line become erroneous.
1923 AT_SETUP([[Unput's effect on locations]])
1925 AT_KEYWORDS([[deprec]])
1927 AT_DATA_GRAMMAR([[input.y]],
1930 %expect_rr 42 %expect_rr 42
1932 %error_verbose %error_verbose
1937 AT_BISON_CHECK([[input.y]], [[1]], [[]],
1938 [[input.y:11.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
1939 input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
1940 input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
1941 input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
1942 input.y:13.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
1943 input.y:13.11-21: error: %define variable 'parse.error' redefined
1944 input.y:13-6: previous definition
1945 input.y:14.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
1946 input.y:14.11-21: error: %define variable 'parse.error' redefined
1947 input.y:13.11-21: previous definition
1952 ##--------------------------- ##
1953 ## Non-deprecated directives. ##
1954 ## -------------------------- ##
1956 AT_SETUP([[Non-deprecated directives]])
1958 AT_KEYWORDS([[deprec]])
1960 AT_DATA_GRAMMAR([[input.y]],
1978 AT_BISON_CHECK([[input.y]], [[0]], [[]],
1979 [[input.y: warning: %expect-rr applies only to GLR parsers [-Wother]