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])
341 m4_pushdef([AT_TEST],
342 [AT_DATA([[input.y]],
343 [[%destructor { destroy ($$); } <$1> <$1>
344 %printer { print ($$); } <$1> <$1>
346 %destructor { destroy ($$); } <$1>
347 %printer { print ($$); } <$1>
353 %destructor { destroy ($$); } <$1>;
354 %printer { print ($$); } <$1>;
357 AT_BISON_CHECK([-fcaret input.y], [1], [],
358 [[input.y:1.13-29: error: %destructor redeclaration for <>
359 %destructor { destroy ($$); } <> <>
361 input.y:1.13-29: previous declaration
362 %destructor { destroy ($$); } <> <>
364 input.y:2.10-24: error: %printer redeclaration for <>
365 %printer { print ($$); } <> <>
367 input.y:2.10-24: previous declaration
368 %printer { print ($$); } <> <>
370 input.y:4.13-29: error: %destructor redeclaration for <>
371 %destructor { destroy ($$); } <>
373 input.y:1.13-29: previous declaration
374 %destructor { destroy ($$); } <> <>
376 input.y:5.10-24: error: %printer redeclaration for <>
377 %printer { print ($$); } <>
379 input.y:2.10-24: previous declaration
380 %printer { print ($$); } <> <>
382 input.y:11.13-29: error: %destructor redeclaration for <>
383 %destructor { destroy ($$); } <>;
385 input.y:1.13-29: previous declaration
386 %destructor { destroy ($$); } <> <>
388 input.y:12.10-24: error: %printer redeclaration for <>
389 %printer { print ($$); } <>;
391 input.y:2.10-24: previous declaration
392 %printer { print ($$); } <> <>
398 AT_TEST([], [*], [*])
404 ## ---------------------------------------------- ##
405 ## Per-type %printer and %destructor redeclared. ##
406 ## ---------------------------------------------- ##
408 AT_SETUP([Per-type %printer and %destructor redeclared])
411 [[%destructor { destroy ($$); } <field1> <field2>
412 %printer { print ($$); } <field1> <field2>
414 %destructor { destroy ($$); } <field1> <field1>
415 %printer { print ($$); } <field2> <field2>
421 %destructor { destroy ($$); } <field2> <field1>;
422 %printer { print ($$); } <field2> <field1>;
425 AT_BISON_CHECK([input.y], [1], [],
426 [[input.y:4.13-29: error: %destructor redeclaration for <field1>
427 input.y:1.13-29: previous declaration
428 input.y:4.13-29: error: %destructor redeclaration for <field1>
429 input.y:1.13-29: previous declaration
430 input.y:5.10-24: error: %printer redeclaration for <field2>
431 input.y:2.10-24: previous declaration
432 input.y:5.10-24: error: %printer redeclaration for <field2>
433 input.y:2.10-24: previous declaration
434 input.y:11.13-29: error: %destructor redeclaration for <field2>
435 input.y:1.13-29: previous declaration
436 input.y:11.13-29: error: %destructor redeclaration for <field1>
437 input.y:1.13-29: previous declaration
438 input.y:12.10-24: error: %printer redeclaration for <field2>
439 input.y:2.10-24: previous declaration
440 input.y:12.10-24: error: %printer redeclaration for <field1>
441 input.y:2.10-24: previous declaration
446 ## ------------------- ##
447 ## Undefined symbols. ##
448 ## ------------------- ##
450 AT_SETUP([Undefined symbols])
453 [[%printer {} foo baz
460 AT_BISON_CHECK([-fcaret input.y], [1], [],
461 [[input.y:2.16-18: error: symbol bar is used, but is not defined as a token and has no rules
464 input.y:1.17-19: warning: symbol baz is used, but is not defined as a token and has no rules [-Wother]
467 input.y:1.13-15: warning: symbol foo is used, but is not defined as a token and has no rules [-Wother]
470 input.y:3.13-15: warning: symbol qux is used, but is not defined as a token and has no rules [-Wother]
478 ## ----------------------------------------------------- ##
479 ## Unassociated types used for a printer or destructor. ##
480 ## ----------------------------------------------------- ##
482 AT_SETUP([Unassociated types used for a printer or destructor])
485 [[%token <type1> tag1
488 %printer { } <type1> <type3>
489 %destructor { } <type2> <type4>
499 AT_BISON_CHECK([input.y], [0], [],
500 [[input.y:4.22-28: warning: type <type3> is used, but is not associated to any symbol [-Wother]
501 input.y:5.25-31: warning: type <type4> is used, but is not associated to any symbol [-Wother]
507 ## --------------------------------- ##
508 ## Useless printers or destructors. ##
509 ## --------------------------------- ##
511 AT_SETUP([Useless printers or destructors])
513 # AT_TEST([INPUT], [STDERR])
514 # --------------------------
515 m4_pushdef([AT_TEST],
516 [AT_DATA([[input.y]],
519 AT_BISON_CHECK([input.y], [0], [], [$2
522 AT_TEST([[%token <type1> token1
523 %token <type2> token2
524 %token <type3> token3
525 %token <type4> token4
526 %token <type5> token51 token52
527 %token <type6> token61 token62
528 %token <type7> token7
531 %destructor {} token2
533 %destructor {} token61
538 %destructor {} <type2>
540 %destructor {} <type4>
543 %destructor {} <type6>
545 %destructor {} <type7>
549 [[input.y:16.13-19: warning: useless %printer for type <type1> [-Wother]
550 input.y:17.16-22: warning: useless %destructor for type <type2> [-Wother]]])
552 # If everybody is typed, <> is useless.
553 AT_TEST([[%type <type> exp
558 [[input.y:3.13-14: warning: useless %printer for type <> [-Wother]]])
560 # If nobody is typed, <*> is useless.
565 [[input.y:2.16-18: warning: useless %printer for type <*> [-Wother]]])
572 ## ---------------------------------------- ##
573 ## Unused values with default %destructor. ##
574 ## ---------------------------------------- ##
576 AT_SETUP([Unused values with default %destructor])
579 [[%destructor { destroy ($$); } <>
584 start: end end tagged tagged { $<tag>1; $3; } ;
589 AT_BISON_CHECK([-fcaret input.y], [0], [],
590 [[input.y:6.8-45: warning: unset value: $$ [-Wother]
591 start: end end tagged tagged { $<tag>1; $3; } ;
592 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
593 input.y:6.12-14: warning: unused value: $2 [-Wother]
594 start: end end tagged tagged { $<tag>1; $3; } ;
596 input.y:7.6-8: warning: unset value: $$ [-Wother]
602 [[%destructor { destroy ($$); } <*>
607 start: end end tagged tagged { $<tag>1; $3; } ;
612 AT_BISON_CHECK([input.y], [0], [],
613 [[input.y:6.23-28: warning: unused value: $4 [-Wother]
614 input.y:8.9-11: warning: unset value: $$ [-Wother]
620 ## ----------------------------------------- ##
621 ## Unused values with per-type %destructor. ##
622 ## ----------------------------------------- ##
624 AT_SETUP([Unused values with per-type %destructor])
627 [[%destructor { destroy ($$); } <field1>
628 %type <field1> start end
632 start: end end { $1; } ;
636 AT_BISON_CHECK([-fcaret input.y], [0], [],
637 [[input.y:6.8-22: warning: unset value: $$ [-Wother]
638 start: end end { $1; } ;
640 input.y:6.12-14: warning: unused value: $2 [-Wother]
641 start: end end { $1; } ;
643 input.y:7.6-8: warning: unset value: $$ [-Wother]
651 ## ---------------------- ##
652 ## Incompatible Aliases. ##
653 ## ---------------------- ##
655 AT_SETUP([Incompatible Aliases])
662 %destructor {bar} foo
667 %destructor {baz} "foo"
674 AT_BISON_CHECK([-fcaret input.y], [1], [],
675 [[input.y:8.7-11: error: %type redeclaration for foo
678 input.y:3.7-11: previous declaration
681 input.y:10.13-17: error: %destructor redeclaration for foo
682 %destructor {baz} "foo"
684 input.y:5.13-17: previous declaration
685 %destructor {bar} foo
687 input.y:9.10-14: error: %printer redeclaration for foo
690 input.y:4.10-14: previous declaration
693 input.y:11.1-5: error: %left redeclaration for foo
696 input.y:6.1-5: previous declaration
705 ## ----------------------- ##
706 ## Torturing the Scanner. ##
707 ## ----------------------- ##
709 # Be sure to compile and run, so that the C compiler checks what
712 AT_SETUP([Torturing the Scanner])
714 AT_BISON_OPTION_PUSHDEFS
715 AT_DATA([input.y], [])
716 AT_BISON_CHECK([input.y], [1], [],
717 [[input.y:1.1: error: syntax error, unexpected end of file
724 AT_BISON_CHECK([-fcaret input.y], [1], [],
725 [[input.y:1.1-2: error: syntax error, unexpected {...}
731 AT_DATA_GRAMMAR([input.y],
733 /* This is seen in GCC: a %{ and %} in middle of a comment. */
734 const char *foo = "So %{ and %} can be here too.";
737 /* These examples test Bison while not stressing C compilers too much.
738 Many C compilers mishandle backslash-newlines, so this part of the
739 test is inside "#if 0". The comment and string are written so that
740 the "#endif" will be seen regardless of the C compiler bugs that we
743 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
746 The Apple Darwin compiler (as of late 2002) mishandles
747 \\[newline]' within a character constant.
752 * A comment with backslash-newlines in it. %} *\
755 /* { Close the above comment, if the C compiler mishandled it. */
758 " A string with backslash-newlines in it %{ %} \\
762 char apostrophe = '\'';
769 /* %{ and %} can be here too. */
772 /* Exercise pre-prologue dependency to %union. */
776 /* Exercise M4 quoting: '@:>@@:>@', 0. */
778 /* Also exercise %union. */
781 value ival; /* A comment to exercise an old bug. */
785 /* Exercise post-prologue dependency to %union. */
787 static YYSTYPE value_as_yystype (value val);
789 /* Exercise quotes in declarations. */
790 char quote[] = "@:>@@:>@,";
800 /* Exercise quotes in strings. */
801 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
804 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
805 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
807 /* Exercise quotes in braces. */
808 char tmp[] = "@<:@%c@:>@,\n";
813 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
814 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
815 output.or.oline.opt: %empty;|oline;;|output;;;
816 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
818 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
821 value_as_yystype (value val)
831 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
834 static size_t toknum;
835 assert (toknum < sizeof input);
836 yylval = value_as_yystype (input[toknum]);
837 return input[toknum++];
841 # Pacify Emacs'font-lock-mode: "
850 AT_BISON_OPTION_POPDEFS
852 AT_BISON_CHECK([-d -v -o input.c input.y])
853 AT_COMPILE([input.o])
855 AT_COMPILE([input], [input.o main.o])
856 AT_PARSER_CHECK([./input], 0,
863 ## ---------------------- ##
864 ## Typed symbol aliases. ##
865 ## ---------------------- ##
867 AT_SETUP([Typed symbol aliases])
869 # Bison 2.0 broke typed symbol aliases - ensure they work.
871 AT_DATA_GRAMMAR([input.y],
876 %token <val> MY_TOKEN "MY TOKEN"
883 AT_BISON_CHECK([-o input.c input.y])
892 m4_define([AT_CHECK_REQUIRE],
893 [AT_SETUP([Require $1])
894 AT_DATA_GRAMMAR([input.y],
899 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
903 AT_CHECK_REQUIRE(1.0, 0)
904 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
905 ## FIXME: Some day augment this version number.
906 AT_CHECK_REQUIRE(100.0, 63)
909 ## ------------------------------------- ##
910 ## String aliases for character tokens. ##
911 ## ------------------------------------- ##
913 AT_SETUP([String aliases for character tokens])
915 # Bison once thought a character token and its alias were different
916 # symbols with the same user token number.
918 AT_DATA_GRAMMAR([input.y],
925 AT_BISON_CHECK([-o input.c input.y])
936 AT_BISON_OPTION_PUSHDEFS
937 AT_DATA_GRAMMAR([input.y],
939 %token WITHOUT_DASH "WITHOUT-DASH"
941 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
947 start: with-dash without_dash with.period without_period;
948 with-dash: WITH-DASH;
949 without_dash: "WITHOUT-DASH";
950 with.period: WITH.PERIOD;
951 without_period: "WITHOUT.PERIOD";
956 AT_BISON_OPTION_POPDEFS
958 # POSIX Yacc accept periods, but not dashes.
959 AT_BISON_CHECK([--yacc input.y], [1], [],
960 [[input.y:9.8-16: error: POSIX Yacc forbids dashes in symbol names: WITH-DASH [-Werror=yacc]
961 input.y:20.8-16: error: POSIX Yacc forbids dashes in symbol names: with-dash [-Werror=yacc]
964 # Dashes are fine for GNU Bison.
965 AT_BISON_CHECK([-o input.c input.y])
967 # Make sure we don't export silly token identifiers with periods or dashes.
968 AT_COMPILE([input.o])
971 # Periods are genuine letters, they can start identifiers.
972 # Digits and dashes cannot.
973 AT_DATA_GRAMMAR([input.y],
981 AT_BISON_CHECK([-o input.c input.y], [1], [],
982 [[input.y:10.10: error: invalid character: '-'
983 input.y:11.10-16: error: invalid identifier: '1NV4L1D'
984 input.y:12.10: error: invalid character: '-'
990 ## ----------------- ##
991 ## Numbered tokens. ##
992 ## ----------------- ##
994 AT_SETUP([Numbered tokens])
996 AT_DATA_GRAMMAR([redecl.y],
997 [[%token DECIMAL_1 11259375
998 HEXADECIMAL_1 0xabcdef
999 HEXADECIMAL_2 0xFEDCBA
1002 start: DECIMAL_1 HEXADECIMAL_2;
1005 AT_BISON_CHECK([redecl.y], [1], [],
1006 [[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1
1007 redecl.y:9.8-16: previous declaration for DECIMAL_1
1008 redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2
1009 redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
1012 AT_DATA_GRAMMAR([too-large.y],
1013 [[%token TOO_LARGE_DEC 999999999999999999999
1014 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
1016 start: TOO_LARGE_DEC TOO_LARGE_HEX
1020 AT_BISON_CHECK([too-large.y], [1], [],
1021 [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
1022 too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
1028 ## --------------------- ##
1029 ## Unclosed constructs. ##
1030 ## --------------------- ##
1032 AT_SETUP([Unclosed constructs])
1034 # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed
1035 # constructs, so they were prepended to whatever it STRING_GROW'ed
1036 # next. It also threw them away rather than returning them to the
1037 # parser. The effect was confusing subsequent error messages.
1042 %token AB "ab" // Used to complain that "ab" was already used.
1045 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
1051 // Used to report a syntax error because it didn't see any kind of symbol
1057 // Used to report a syntax error because it didn't see braced code.
1058 %destructor { free ($$)
1061 AT_BISON_CHECK([-fcaret -o input.c input.y], 1, [],
1062 [[input.y:1.10-2.0: error: missing '"' at end of line
1065 input.y:4.10-5.0: error: missing "'" at end of line
1068 input.y:14.11-15.0: error: missing "'" at end of line
1071 input.y:16.11-17.0: error: missing '"' at end of line
1074 input.y:19.13-20.0: error: missing '}' at end of file
1075 %destructor { free ($$)
1077 input.y:20.1: error: syntax error, unexpected end of file
1083 ## ------------------------- ##
1084 ## %start after first rule. ##
1085 ## ------------------------- ##
1087 AT_SETUP([%start after first rule])
1089 # Bison once complained that a %start after the first rule was a
1090 # redeclaration of the start symbol.
1094 false_start: %empty;
1095 start: false_start ;
1099 AT_BISON_CHECK([-o input.c input.y])
1104 ## --------------------- ##
1105 ## %prec takes a token. ##
1106 ## --------------------- ##
1108 AT_SETUP([%prec takes a token])
1110 # Bison once allowed %prec sym where sym was a nonterminal.
1114 start: PREC %prec PREC ;
1118 AT_BISON_CHECK([input.y], [1], [],
1119 [[input.y:3.1-4: error: rule given for PREC, which is a token
1125 ## ------------------------------- ##
1126 ## %prec's token must be defined. ##
1127 ## ------------------------------- ##
1129 AT_SETUP([[%prec's token must be defined]])
1131 # According to POSIX, a %prec token must be defined separately.
1133 AT_DATA([[input.y]],
1138 AT_BISON_CHECK([[input.y]], [[0]], [],
1139 [[input.y:2.8-17: warning: token for %prec is not defined: PREC [-Wother]
1145 ## -------------------------------- ##
1146 ## Reject unused %code qualifiers. ##
1147 ## -------------------------------- ##
1149 AT_SETUP([Reject unused %code qualifiers])
1151 AT_DATA([input-c.y],
1159 AT_BISON_CHECK([[input-c.y]], [[1]], [],
1160 [[input-c.y:1.7: error: %code qualifier 'q' is not used
1161 input-c.y:2.7-9: error: %code qualifier 'bad' is not used
1162 input-c.y:3.7-9: error: %code qualifier 'bad' is not used
1163 input-c.y:4.7-12: error: %code qualifier 'format' is not used
1166 AT_DATA([input-c-glr.y],
1173 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
1174 [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used
1175 input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used
1176 input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used
1179 AT_DATA([input-c++.y],
1186 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
1187 [[input-c++.y:1.7: error: %code qualifier 'q' is not used
1188 input-c++.y:2.7-9: error: %code qualifier 'bad' is not used
1189 input-c++.y:3.8: error: %code qualifier 'q' is not used
1192 AT_DATA([input-c++-glr.y],
1199 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
1200 [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used
1201 input-c++-glr.y:2.7: error: %code qualifier 'q' is not used
1202 input-c++-glr.y:3.7: error: %code qualifier 'q' is not used
1205 AT_DATA([special-char-@@.y],
1212 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
1213 [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used
1214 special-char-@@.y:2.7: error: %code qualifier 'q' is not used
1215 special-char-@@.y:3.7: error: %code qualifier 'q' is not used
1218 AT_DATA([special-char-@:>@.y],
1225 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
1226 [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used
1227 special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used
1228 special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used
1234 ## ---------------- ##
1235 ## Multiple %code. ##
1236 ## ---------------- ##
1238 AT_SETUP([Multiple %code])
1240 # Make sure that repeated arguments to %code are separated by
1241 # end-of-lines. At some point, a missing eol would leave synclines
1242 # appended to the previous value. Here, we use CPP directive to
1243 # introduce dependency on the absence/presence of the eol.
1244 AT_BISON_OPTION_PUSHDEFS
1247 [[%code {#include <assert.h>}
1251 %code {#define D 42}
1253 ]AT_YYERROR_DECLARE[
1267 AT_FULL_COMPILE([input])
1268 AT_PARSER_CHECK([./input])
1270 AT_BISON_OPTION_POPDEFS
1273 ## ---------------- ##
1274 ## %define errors. ##
1275 ## ---------------- ##
1277 AT_SETUP([%define errors])
1279 AT_DATA([input-redefined.y],
1280 [[%define var "value1"
1281 %define var "value1"
1282 %define var "value2"
1283 %define special1 "@:>@"
1284 %define special2 "@<:@"
1289 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
1290 [[input-redefined.y:2.9-11: error: %define variable 'var' redefined
1291 input-redefined.y:1.9-11: previous definition
1292 input-redefined.y:3.10-12: error: %define variable 'var' redefined
1293 input-redefined.y:2.9-11: previous definition
1296 AT_DATA([input-unused.y],
1297 [[%define var "value"
1302 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
1303 [[input-unused.y:1.9-11: error: %define variable 'var' is not used
1309 ## ----------------------------------- ##
1310 ## %define, --define, --force-define. ##
1311 ## ----------------------------------- ##
1313 AT_SETUP([[%define, --define, --force-define]])
1316 [[m4@&t@_divert_push(0)@
1317 @output(b4_parser_file_name@)@
1318 [var-dd: ]b4_percent_define_get([[var-dd]])[
1319 var-ff: ]b4_percent_define_get([[var-ff]])[
1320 var-dfg: ]b4_percent_define_get([[var-dfg]])[
1321 var-fd: ]b4_percent_define_get([[var-fd]])
1322 m4@&t@_divert_pop(0)
1324 AT_DATA([[input.y]],
1325 [[%define var-dfg "gram"
1329 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
1330 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
1331 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
1332 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
1333 --skeleton ./skel.c input.y]])
1334 AT_CHECK([[cat input.tab.c]], [[0]],
1341 AT_DATA([[input-dg.y]],
1342 [[%define var "gram"
1346 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
1347 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1348 <command line>:2: previous definition
1351 AT_DATA([[input-dg.y]],
1352 [[%define var "gram"
1356 AT_BISON_CHECK([[-fcaret -Dvar=cmd-d input-dg.y]], [[1]], [],
1357 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1360 <command line>:3: previous definition
1363 AT_DATA([[input-unused.y]],
1367 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
1368 [[<command line>:2: error: %define variable 'unused-d' is not used
1369 <command line>:3: error: %define variable 'unused-f' is not used
1374 ## --------------------------- ##
1375 ## %define Boolean variables. ##
1376 ## --------------------------- ##
1378 AT_SETUP([["%define" Boolean variables]])
1382 %define public maybe
1383 %define parser_class_name {Input}
1388 AT_BISON_CHECK([[Input.y]], [1], [],
1389 [[Input.y:2.9-14: error: invalid value for %define Boolean variable 'public'
1394 ## ------------------------ ##
1395 ## %define code variables. ##
1396 ## ------------------------ ##
1398 AT_SETUP([["%define" code variables]])
1400 m4_pushdef([AT_TEST],
1401 [AT_DATA([input.yy],
1402 [[%skeleton "lalr1.cc" %locations
1403 %define api.location.type ]$1[quux]$2[
1404 %define api.namespace ]$1[quux]$2[
1405 %define api.prefix ]$1[quux]$2[
1406 %define api.token.prefix ]$1[quux]$2[
1407 %token TOK // Otherwise api.token.prefix is unused.
1412 AT_BISON_CHECK([[input.yy]], [0], [],
1413 [[input.yy:2.9-25: warning: %define variable 'api.location.type' requires '{...}' values [-Wdeprecated]
1414 input.yy:4.9-18: warning: %define variable 'api.prefix' requires '{...}' values [-Wdeprecated]
1415 input.yy:5.9-24: warning: %define variable 'api.token.prefix' requires '{...}' values [-Wdeprecated]
1416 input.yy:3.9-21: warning: %define variable 'api.namespace' requires '{...}' values [-Wdeprecated]
1422 m4_popdef([AT_TEST])
1427 ## --------------------------- ##
1428 ## %define keyword variables. ##
1429 ## --------------------------- ##
1431 AT_SETUP([["%define" keyword variables]])
1433 m4_pushdef([AT_TEST],
1435 [[%define api.pure ]$1[true]$2[
1436 %define api.push-pull ]$1[both]$2[
1437 %define lr.default-reduction ]$1[most]$2[
1438 %define lr.keep-unreachable-state ]$1[true]$2[
1439 %define lr.type ]$1[lalr]$2[
1444 AT_BISON_CHECK([[input.y]], [0], [],
1445 [[input.y:5.9-15: warning: %define variable 'lr.type' requires keyword values [-Wdeprecated]
1446 input.y:3.9-28: warning: %define variable 'lr.default-reduction' requires keyword values [-Wdeprecated]
1447 input.y:4.9-33: warning: %define variable 'lr.keep-unreachable-state' requires keyword values [-Wdeprecated]
1448 input.y:2.9-21: warning: %define variable 'api.push-pull' requires keyword values [-Wdeprecated]
1449 input.y:1.9-16: warning: %define variable 'api.pure' requires keyword values [-Wdeprecated]
1455 m4_popdef([AT_TEST])
1460 ## ------------------------ ##
1461 ## %define enum variables. ##
1462 ## ------------------------ ##
1464 AT_SETUP([["%define" enum variables]])
1466 # Check errors from the front-end, and the back-end. Since the
1467 # front-end quits before calling the back-end, these tests cannot be
1471 AT_DATA([[input.y]],
1472 [[%define lr.default-reduction bogus
1476 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
1477 [[input.y:1.9-28: error: invalid value for %define variable 'lr.default-reduction': 'bogus'
1478 %define lr.default-reduction bogus
1479 ^^^^^^^^^^^^^^^^^^^^
1480 input.y:1.9-28: accepted value: 'most'
1481 input.y:1.9-28: accepted value: 'consistent'
1482 input.y:1.9-28: accepted value: 'accepting'
1486 AT_DATA([[input.y]],
1487 [[%define api.push-pull neither
1491 AT_BISON_CHECK([[-fcaret input.y]], [[1]], [[]],
1492 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1493 %define api.push-pull neither
1495 input.y:1.9-21: accepted value: 'pull'
1496 input.y:1.9-21: accepted value: 'push'
1497 input.y:1.9-21: accepted value: 'both'
1502 ## -------------------------------- ##
1503 ## %define backward compatibility. ##
1504 ## -------------------------------- ##
1506 AT_SETUP([["%define" backward compatibility]])
1508 # The error messages tell us whether the variables are properly updated.
1509 AT_DATA([[input.y]],
1510 [[%define api.push_pull both
1511 %define lr.keep_unreachable_states maybe
1512 %define namespace "foo"
1513 %define api.namespace {foo}
1518 AT_BISON_CHECK([[-fcaret input.y]], [1], [],
1519 [[input.y:1.9-21: warning: deprecated directive, use '%define api.push-pull both' [-Wdeprecated]
1520 %define api.push_pull both
1522 input.y:2.9-34: warning: deprecated directive, use '%define lr.keep-unreachable-state maybe' [-Wdeprecated]
1523 %define lr.keep_unreachable_states maybe
1524 ^^^^^^^^^^^^^^^^^^^^^^^^^^
1525 input.y:3.9-17: warning: deprecated directive, use '%define api.namespace foo' [-Wdeprecated]
1526 %define namespace "foo"
1528 input.y:4.9-21: error: %define variable 'api.namespace' redefined
1529 %define api.namespace {foo}
1531 input.y:3.9-17: previous definition
1532 %define namespace "foo"
1534 input.y:5.9-15: warning: deprecated directive, use '%define api.value.type variant' [-Wdeprecated]
1541 ## ------------------------- ##
1542 ## Unused %define api.pure. ##
1543 ## ------------------------- ##
1545 AT_SETUP([[Unused %define api.pure]])
1547 # AT_CHECK_API_PURE(DECLS, VALUE)
1548 # -------------------------------
1549 # Make sure Bison reports that '%define api.pure VALUE' is unused when DECLS
1551 m4_define([AT_CHECK_API_PURE],
1553 AT_DATA([[input.y]],
1554 [[%define api.pure ]$2[
1560 AT_BISON_CHECK([[input.y]], [[1]], [],
1561 [[input.y:1.9-16: error: %define variable 'api.pure' is not used
1565 AT_CHECK_API_PURE([[%language "c++"]], [[]])
1566 AT_CHECK_API_PURE([[%language "c++"]], [[false]])
1567 AT_CHECK_API_PURE([[%language "c++" %glr-parser]], [[""]])
1568 AT_CHECK_API_PURE([[%language "c++" %glr-parser]], [[false]])
1569 AT_CHECK_API_PURE([[%language "java"]], [[true]])
1570 AT_CHECK_API_PURE([[%language "java"]], [[false]])
1574 ## -------------------------------- ##
1575 ## C++ namespace reference errors. ##
1576 ## -------------------------------- ##
1578 AT_SETUP([[C++ namespace reference errors]])
1580 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
1581 # -------------------------------------------------------------
1582 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
1583 m4_define([AT_CHECK_NAMESPACE_ERROR],
1585 AT_DATA([[input.y]],
1588 %define api.namespace {]$1[}
1593 AT_BISON_CHECK([[input.y]], [1], [],
1594 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
1595 [[input.y:3.9-21: error: ]b4_arg[
1599 AT_CHECK_NAMESPACE_ERROR([[]],
1600 [[namespace reference is empty]])
1601 AT_CHECK_NAMESPACE_ERROR([[ @tb@@tb@ @tb@ @tb@]],
1602 [[namespace reference is empty]])
1603 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
1604 [[namespace reference has consecutive "::"]])
1605 AT_CHECK_NAMESPACE_ERROR([[foo:: @tb@::bar]],
1606 [[namespace reference has consecutive "::"]])
1607 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
1608 [[namespace reference has consecutive "::"]])
1609 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
1610 [[namespace reference has consecutive "::"]])
1611 AT_CHECK_NAMESPACE_ERROR([[foo::bar::@tb@::]],
1612 [[namespace reference has consecutive "::"]],
1613 [[namespace reference has a trailing "::"]])
1614 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
1615 [[namespace reference has a trailing "::"]])
1616 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: @tb@]],
1617 [[namespace reference has a trailing "::"]])
1618 AT_CHECK_NAMESPACE_ERROR([[::]],
1619 [[namespace reference has a trailing "::"]])
1623 ## ------------------------ ##
1624 ## Bad character literals. ##
1625 ## ------------------------ ##
1627 # Bison used to accept character literals that were empty or contained
1628 # too many characters.
1630 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
1631 # the final newline to be omitted. See the threads starting at
1632 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
1634 AT_SETUP([[Bad character literals]])
1641 AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
1643 AT_BISON_CHECK([-fcaret empty.y], [1], [],
1644 [[empty.y:2.8-9: warning: empty character literal [-Wother]
1647 empty.y:3.8-4.0: error: missing "'" at end of line
1650 empty.y:3.8-4.0: warning: empty character literal [-Wother]
1653 empty.y:4.8: error: missing "'" at end of file
1656 empty.y:4.8: warning: empty character literal [-Wother]
1666 AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
1668 AT_BISON_CHECK([two.y], [1], [],
1669 [[two.y:2.8-11: warning: extra characters in character literal [-Wother]
1670 two.y:3.8-4.0: error: missing "'" at end of line
1671 two.y:3.8-4.0: warning: extra characters in character literal [-Wother]
1672 two.y:4.8-10: error: missing "'" at end of file
1673 two.y:4.8-10: warning: extra characters in character literal [-Wother]
1681 AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
1683 AT_BISON_CHECK([three.y], [1], [],
1684 [[three.y:2.8-12: warning: extra characters in character literal [-Wother]
1685 three.y:3.8-4.0: error: missing "'" at end of line
1686 three.y:3.8-4.0: warning: extra characters in character literal [-Wother]
1687 three.y:4.8-11: error: missing "'" at end of file
1688 three.y:4.8-11: warning: extra characters in character literal [-Wother]
1693 ## ------------------------- ##
1694 ## Bad escapes in literals. ##
1695 ## ------------------------- ##
1697 AT_SETUP([[Bad escapes in literals]])
1701 start: '\777' '\0' '\xfff' '\x0'
1702 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
1706 # It is not easy to create special characters, we cannot even trust tr.
1707 # Beside we cannot even expect "echo '\0'" to output two characters
1708 # (well three with \n): at least Bash 3.2 converts the two-character
1709 # sequence "\0" into a single NUL character.
1710 AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
1713 AT_BISON_CHECK([input.y], [1], [],
1714 [[input.y:2.9-12: error: invalid number after \-escape: 777
1715 input.y:2.8-13: warning: empty character literal [-Wother]
1716 input.y:2.16-17: error: invalid number after \-escape: 0
1717 input.y:2.15-18: warning: empty character literal [-Wother]
1718 input.y:2.21-25: error: invalid number after \-escape: xfff
1719 input.y:2.20-26: warning: empty character literal [-Wother]
1720 input.y:2.29-31: error: invalid number after \-escape: x0
1721 input.y:2.28-32: warning: empty character literal [-Wother]
1722 input.y:3.9-14: error: invalid number after \-escape: uffff
1723 input.y:3.8-15: warning: empty character literal [-Wother]
1724 input.y:3.18-23: error: invalid number after \-escape: u0000
1725 input.y:3.17-24: warning: empty character literal [-Wother]
1726 input.y:3.27-36: error: invalid number after \-escape: Uffffffff
1727 input.y:3.26-37: warning: empty character literal [-Wother]
1728 input.y:3.40-49: error: invalid number after \-escape: U00000000
1729 input.y:3.39-50: warning: empty character literal [-Wother]
1730 input.y:4.9-10: error: invalid character after \-escape: ' '
1731 input.y:4.8-11: warning: empty character literal [-Wother]
1732 input.y:4.14-15: error: invalid character after \-escape: A
1733 input.y:4.13-16: warning: empty character literal [-Wother]
1734 input.y:5.9-16: error: invalid character after \-escape: \t
1735 input.y:5.17: error: invalid character after \-escape: \f
1736 input.y:5.18: error: invalid character after \-escape: \0
1737 input.y:5.19: error: invalid character after \-escape: \001
1742 ## ------------------------- ##
1743 ## LAC: Errors for %define. ##
1744 ## ------------------------- ##
1746 AT_SETUP([[LAC: Errors for %define]])
1748 AT_DATA([[input.y]],
1753 # parse.lac.* options are useless if LAC isn't actually activated.
1754 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
1756 [[<command line>:2: error: %define variable 'parse.lac.es-capacity-initial' is not used
1758 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
1760 [[<command line>:2: error: %define variable 'parse.lac.memory-trace' is not used
1765 ## ---------------------- ##
1766 ## -Werror combinations. ##
1767 ## ---------------------- ##
1769 AT_SETUP([[-Werror combinations]])
1771 AT_DATA([[input.y]],
1776 # -Werror is not enabled by -Wall or equivalent.
1777 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
1778 [[input.y:2.15: warning: stray '$' [-Wother]
1780 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
1781 [[input.y:2.15: warning: stray '$' [-Wother]
1783 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
1784 [[input.y:2.15: warning: stray '$' [-Wother]
1787 # -Werror is not disabled by -Wnone or equivalent.
1788 AT_BISON_CHECK([[-Werror,none,other input.y]], [[1]], [[]],
1789 [[input.y:2.15: error: stray '$' [-Werror=other]
1791 AT_BISON_CHECK([[-Werror,no-all,other input.y]], [[1]], [[]],
1792 [[input.y:2.15: error: stray '$' [-Werror=other]
1795 # Check that -Wno-error keeps warnings enabled, but non fatal.
1796 AT_BISON_CHECK([[-Werror -Wno-error=other input.y]], [[0]], [[]],
1797 [[input.y:2.15: warning: stray '$' [-Wother]
1800 AT_BISON_CHECK([[-Wno-error=other -Werror input.y]], [[0]], [[]],
1801 [[input.y:2.15: warning: stray '$' [-Wother]
1804 AT_BISON_CHECK([[-Werror=other -Wno-other input.y]], [[0]], [[]],
1810 ## ------------------------------------------------------ ##
1811 ## %name-prefix and %define api.prefix are incompatible. ##
1812 ## ------------------------------------------------------ ##
1814 AT_SETUP([[%name-prefix and api.prefix are incompatible]])
1816 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
1817 # --------------------------------------------
1818 m4_pushdef([AT_TEST],
1819 [AT_DATA([[input.y]],
1824 AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
1825 [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
1829 AT_TEST([%define api.prefix {foo} %name-prefix "bar"], [], [input.y:1.9-18])
1830 AT_TEST([], [-Dapi.prefix={foo} -p bar], [<command line>:2])
1831 AT_TEST([%name-prefix "bar"], [-Dapi.prefix={foo}], [<command line>:2])
1832 AT_TEST([%define api.prefix {foo}], [-p bar], [input.y:1.9-18])
1834 m4_popdef([AT_TEST])
1839 ## -------------- ##
1841 ## -------------- ##
1843 AT_SETUP([[Stray $ or @]])
1845 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
1846 # check that the warnings are reported once, not three times.
1848 AT_DATA_GRAMMAR([[input.y]],
1850 %token <TYPE> TOK TOK2
1851 %destructor { $%; @%; } <*> exp TOK;
1852 %initial-action { $%; @%; };
1853 %printer { $%; @%; } <*> exp TOK;
1854 %{ $ @ %} // Should not warn.
1856 exp: TOK { $%; @%; $$ = $1; };
1858 $ @ // Should not warn.
1861 AT_BISON_CHECK([[-Wall input.y]], 0, [],
1862 [[input.y:11.19: warning: stray '$' [-Wother]
1863 input.y:11.23: warning: stray '@' [-Wother]
1864 input.y:12.19: warning: stray '$' [-Wother]
1865 input.y:12.23: warning: stray '@' [-Wother]
1866 input.y:13.19: warning: stray '$' [-Wother]
1867 input.y:13.23: warning: stray '@' [-Wother]
1868 input.y:16.19: warning: stray '$' [-Wother]
1869 input.y:16.23: warning: stray '@' [-Wother]
1876 ## ---------------- ##
1877 ## Code injection. ##
1878 ## ---------------- ##
1881 AT_SETUP([[Code injection]])
1883 m4_pattern_allow([^m4_errprintn$])
1887 # Try to have MACRO be run by bison.
1888 m4_pushdef([AT_TEST],
1889 [AT_DATA([[input.y]],
1890 [[%type <$1(DEAD %type)> exp
1891 %token <$1(DEAD %token)> a
1896 $<$1(DEAD %initial-action)>$
1901 $<$1(DEAD %printer)>$
1909 $1(DEAD %parse-param)
1917 $<$1(DEAD action 1)>$
1918 $<$1(DEAD action 2)>1
1919 $<$1(DEAD action 3)>name
1920 $<$1(DEAD action 4)>0
1925 # FIXME: Provide a means to iterate over all the skeletons.
1926 AT_BISON_CHECK([[-d input.y]])
1927 AT_BISON_CHECK([[-d -S glr.c input.y]])
1928 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
1929 AT_BISON_CHECK([[-d -S glr.cc input.y]])
1930 AT_BISON_CHECK([[ -S lalr1.java input.y]])
1933 AT_TEST([m4_errprintn])
1934 AT_TEST([@:>@m4_errprintn])
1936 m4_popdef([AT_TEST])
1940 ##----------------------- ##
1941 ## Deprecated directives. ##
1942 ## ---------------------- ##
1944 AT_SETUP([[Deprecated directives]])
1946 AT_KEYWORDS([[deprec]])
1948 AT_DATA_GRAMMAR([[input.y]],
1953 %file-prefix = "foo"
1971 AT_BISON_CHECK([[input.y]], [[0]], [[]],
1972 [[input.y:10.1-13: warning: deprecated directive: '%default_prec', use '%default-prec' [-Wdeprecated]
1973 input.y:11.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
1974 input.y:12.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
1975 input.y:13.1-14: warning: deprecated directive: '%file-prefix =', use '%file-prefix' [-Wdeprecated]
1976 input.y:14.1-15.2: warning: deprecated directive: '%file-prefix\n =', use '%file-prefix' [-Wdeprecated]
1977 input.y:17.1-19: warning: deprecated directive: '%fixed-output_files', use '%fixed-output-files' [-Wdeprecated]
1978 input.y:18.1-19: warning: deprecated directive: '%fixed_output-files', use '%fixed-output-files' [-Wdeprecated]
1979 input.y:20.1-13: warning: deprecated directive: '%name-prefix=', use '%name-prefix' [-Wdeprecated]
1980 input.y:21.1-16: warning: deprecated directive: '%no-default_prec', use '%no-default-prec' [-Wdeprecated]
1981 input.y:22.1-16: warning: deprecated directive: '%no_default-prec', use '%no-default-prec' [-Wdeprecated]
1982 input.y:23.1-9: warning: deprecated directive: '%no_lines', use '%no-lines' [-Wdeprecated]
1983 input.y:24.1-9: warning: deprecated directive: '%output =', use '%output' [-Wdeprecated]
1984 input.y:25.1-12: warning: deprecated directive: '%pure_parser', use '%pure-parser' [-Wdeprecated]
1985 input.y:26.1-12: warning: deprecated directive: '%token_table', use '%token-table' [-Wdeprecated]
1990 ## ---------------------------- ##
1991 ## Unput's effect on locations. ##
1992 ## ---------------------------- ##
1993 dnl When the scanner detects a deprecated construct, it unputs the correct
1994 dnl version, but it should *not* have any impact on the scanner cursor. If it
1995 dnl does, the locations of directives on the same line become erroneous.
1997 AT_SETUP([[Unput's effect on locations]])
1999 AT_KEYWORDS([[deprec]])
2001 AT_DATA_GRAMMAR([[input.y]],
2004 %expect_rr 42 %expect_rr 42
2006 %error_verbose %error_verbose
2011 AT_BISON_CHECK([[input.y]], [[1]], [[]],
2012 [[input.y:11.1-10: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
2013 input.y:11.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
2014 input.y:12.15-24: warning: deprecated directive: '%expect_rr', use '%expect-rr' [-Wdeprecated]
2015 input.y:13.1-14: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
2016 input.y:13.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
2017 input.y:13.11-21: error: %define variable 'parse.error' redefined
2018 input.y:13-6: previous definition
2019 input.y:14.16-29: warning: deprecated directive: '%error_verbose', use '%define parse.error verbose' [-Wdeprecated]
2020 input.y:14.11-21: error: %define variable 'parse.error' redefined
2021 input.y:13.11-21: previous definition
2026 ##--------------------------- ##
2027 ## Non-deprecated directives. ##
2028 ## -------------------------- ##
2030 AT_SETUP([[Non-deprecated directives]])
2032 AT_KEYWORDS([[deprec]])
2034 AT_DATA_GRAMMAR([[input.y]],
2052 AT_BISON_CHECK([[input.y]], [[0]], [[]],
2053 [[input.y: warning: %expect-rr applies only to GLR parsers [-Wother]