]> git.saurik.com Git - bison.git/blob - tests/input.at
yacc.c, glr.c: check and fix the display of locations
[bison.git] / tests / input.at
1 # Checking the Bison scanner. -*- Autotest -*-
2
3 # Copyright (C) 2002-2012 Free Software Foundation, Inc.
4
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.
9 #
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.
14 #
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/>.
17
18 AT_BANNER([[Input Processing.]])
19
20 # Mostly test that we are robust to mistakes.
21
22
23 ## ---------------- ##
24 ## Invalid inputs. ##
25 ## ---------------- ##
26
27 AT_SETUP([Invalid inputs])
28
29 AT_DATA([input.y],
30 [[\000\001\002\377?
31 %%
32 ?
33 default: 'a' }
34 %&
35 %a-does-not-exist
36 %-
37 %{
38 ]])
39 AT_CHECK([[$PERL -pi -e 's/\\(\d{3})/chr(oct($1))/ge' input.y || exit 77]])
40
41 AT_BISON_CHECK([input.y], [1], [],
42 [[input.y:1.1-2: error: invalid characters: '\0\001\002\377?'
43 input.y:3.1: error: invalid character: '?'
44 input.y:4.14: error: invalid character: '}'
45 input.y:5.1: error: invalid character: '%'
46 input.y:5.2: error: invalid character: '&'
47 input.y:6.1-17: error: invalid directive: '%a-does-not-exist'
48 input.y:7.1: error: invalid character: '%'
49 input.y:7.2: error: invalid character: '-'
50 input.y:8.1-9.0: error: missing '%}' at end of file
51 input.y:8.1-9.0: error: syntax error, unexpected %{...%}
52 ]])
53
54 AT_CLEANUP
55
56
57 AT_SETUP([Invalid inputs with {}])
58
59 # We used to SEGV here. See
60 # http://lists.gnu.org/archive/html/bug-bison/2005-07/msg00053.html
61
62 AT_DATA([input.y],
63 [[
64 %destructor
65 %initial-action
66 %lex-param
67 %parse-param
68 %printer
69 %union
70 ]])
71
72 AT_BISON_CHECK([input.y], [1], [],
73 [[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...}
74 ]])
75
76 AT_CLEANUP
77
78
79
80 ## ------------ ##
81 ## Invalid $n. ##
82 ## ------------ ##
83
84 AT_SETUP([Invalid $n and @n])
85
86 AT_DATA([input.y],
87 [[%%
88 exp: { $$ = $1 ; };
89 exp: { @$ = @1 ; };
90 ]])
91
92 AT_BISON_CHECK([input.y], [1], [],
93 [[input.y:2.13-14: error: integer out of range: '$1'
94 input.y:3.13-14: error: integer out of range: '@1'
95 ]])
96
97 AT_CLEANUP
98
99
100 ## -------------- ##
101 ## Type Clashes. ##
102 ## -------------- ##
103
104 AT_SETUP([Type Clashes])
105
106 AT_DATA([input.y],
107 [[%union { int bar; }
108 %token foo
109 %type <bar> exp
110 %%
111 exp: foo { $$; } foo { $2; } foo
112 | foo
113 | /* Empty. */
114 ;
115 ]])
116
117 AT_BISON_CHECK([input.y], [1], [],
118 [[input.y:5.12-13: error: $$ for the midrule at $2 of 'exp' has no declared type
119 input.y:5.24-25: error: $2 of 'exp' has no declared type
120 input.y:5.6-32: warning: type clash on default action: <bar> != <>
121 input.y:6.6-8: warning: type clash on default action: <bar> != <>
122 input.y:7.5: warning: empty rule for typed nonterminal, and no action
123 ]])
124
125 AT_CLEANUP
126
127
128 # _AT_UNUSED_VALUES_DECLARATIONS()
129 # --------------------------------
130 # Generate the token, type, and destructor
131 # declarations for the unused values tests.
132
133 m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
134 [[[%token <integer> INT;
135 %type <integer> a b c d e f g h i j k l;
136 %destructor { destroy ($$); } INT a b c d e f g h i j k l;]]])
137
138
139 # AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
140 # ------------------------------------------------------------------
141 # Generate a grammar to test unused values,
142 # compile it, run it. If DECLARATIONS_AFTER
143 # is set, then the token, type, and destructor
144 # declarations are generated after the rules
145 # rather than before. If CHECK_MIDRULE_VALUES
146 # is set, then --warnings=midrule-values is
147 # set.
148
149 m4_define([AT_CHECK_UNUSED_VALUES],
150 [AT_DATA([input.y],
151 m4_ifval($1, [
152
153
154 ], [_AT_UNUSED_VALUES_DECLARATIONS
155 ])[[%%
156 start:
157 'a' a { $]2[; } | 'b' b { $]2[; } | 'c' c { $]2[; } | 'd' d { $]2[; }
158 | 'e' e { $]2[; } | 'f' f { $]2[; } | 'g' g { $]2[; } | 'h' h { $]2[; }
159 | 'i' i { $]2[; } | 'j' j { $]2[; } | 'k' k { $]2[; } | 'l' l { $]2[; }
160 ;
161
162 a: INT | INT { } INT { } INT { };
163 b: INT | /* empty */;
164 c: INT | INT { $]1[; } INT { $<integer>2; } INT { $<integer>4; };
165 d: INT | INT { } INT { $]1[; } INT { $<integer>2; };
166 e: INT | INT { } INT { } INT { $]1[; };
167 f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; };
168 g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
169 h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
170 i: INT | INT INT { } { $]$[ = $]1[ + $]2[; };
171 j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; };
172 k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
173 l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [
174 _AT_UNUSED_VALUES_DECLARATIONS])
175 )
176
177 AT_BISON_CHECK(m4_ifval($2, [ --warnings=midrule-values ])[ input.y], [0], [],
178 [[input.y:11.10-32: warning: unset value: $]$[
179 input.y:11.10-32: warning: unused value: $]1[
180 input.y:11.10-32: warning: unused value: $]3[
181 input.y:11.10-32: warning: unused value: $]5[
182 input.y:12.9: warning: empty rule for typed nonterminal, and no action
183 ]]m4_ifval($2, [[[input.y:13.14-20: warning: unset value: $$
184 input.y:13.26-41: warning: unset value: $$
185 ]]])[[input.y:13.10-62: warning: unset value: $]$[
186 input.y:13.10-62: warning: unused value: $]3[
187 input.y:13.10-62: warning: unused value: $]5[
188 ]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $$
189 ]]])[[input.y:14.10-49: warning: unset value: $]$[
190 input.y:14.10-49: warning: unused value: $]3[
191 input.y:14.10-49: warning: unused value: $]5[
192 input.y:15.10-37: warning: unset value: $]$[
193 input.y:15.10-37: warning: unused value: $]3[
194 input.y:15.10-37: warning: unused value: $]5[
195 input.y:17.10-58: warning: unset value: $]$[
196 input.y:17.10-58: warning: unused value: $]1[
197 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]2[
198 ]]])[[input.y:17.10-58: warning: unused value: $]3[
199 ]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]4[
200 ]]])[[input.y:17.10-58: warning: unused value: $]5[
201 input.y:18.10-72: warning: unset value: $]$[
202 input.y:18.10-72: warning: unused value: $]1[
203 input.y:18.10-72: warning: unused value: $]3[
204 ]]m4_ifval($2, [[[input.y:18.10-72: warning: unused value: $]4[
205 ]]])[[input.y:18.10-72: warning: unused value: $]5[
206 ]]m4_ifval($2, [[[input.y:20.10-55: warning: unused value: $]3[
207 ]]])[[input.y:21.10-68: warning: unset value: $]$[
208 input.y:21.10-68: warning: unused value: $]1[
209 input.y:21.10-68: warning: unused value: $]2[
210 ]]m4_ifval($2, [[[input.y:21.10-68: warning: unused value: $]4[
211 ]]]))])
212
213
214 ## --------------- ##
215 ## Unused values. ##
216 ## --------------- ##
217
218 AT_SETUP([Unused values])
219 AT_CHECK_UNUSED_VALUES
220 AT_CHECK_UNUSED_VALUES(, [1])
221 AT_CLEANUP
222
223
224 ## ------------------------------------------ ##
225 ## Unused values before symbol declarations. ##
226 ## ------------------------------------------ ##
227
228 AT_SETUP([Unused values before symbol declarations])
229 AT_CHECK_UNUSED_VALUES([1])
230 AT_CHECK_UNUSED_VALUES([1], [1])
231 AT_CLEANUP
232
233
234 ## --------------------------------------------- ##
235 ## Default %printer and %destructor redeclared. ##
236 ## --------------------------------------------- ##
237
238 AT_SETUP([Default %printer and %destructor redeclared])
239
240 AT_DATA([[input.y]],
241 [[%destructor { destroy ($$); } <*> <*>
242 %printer { print ($$); } <*> <*>
243
244 %destructor { destroy ($$); } <*>
245 %printer { print ($$); } <*>
246
247 %destructor { destroy ($$); } <> <>
248 %printer { print ($$); } <> <>
249
250 %destructor { destroy ($$); } <>
251 %printer { print ($$); } <>
252
253 %%
254
255 start: ;
256
257 %destructor { destroy ($$); } <*>;
258 %printer { print ($$); } <*>;
259
260 %destructor { destroy ($$); } <>;
261 %printer { print ($$); } <>;
262 ]])
263
264 AT_BISON_CHECK([input.y], [1], [],
265 [[input.y:1.13-29: error: redeclaration for default tagged %destructor
266 input.y:1.13-29: previous declaration
267 input.y:2.10-24: error: redeclaration for default tagged %printer
268 input.y:2.10-24: previous declaration
269 input.y:4.13-29: error: redeclaration for default tagged %destructor
270 input.y:1.13-29: previous declaration
271 input.y:5.10-24: error: redeclaration for default tagged %printer
272 input.y:2.10-24: previous declaration
273 input.y:7.13-29: error: redeclaration for default tagless %destructor
274 input.y:7.13-29: previous declaration
275 input.y:8.10-24: error: redeclaration for default tagless %printer
276 input.y:8.10-24: previous declaration
277 input.y:10.13-29: error: redeclaration for default tagless %destructor
278 input.y:7.13-29: previous declaration
279 input.y:11.10-24: error: redeclaration for default tagless %printer
280 input.y:8.10-24: previous declaration
281 input.y:17.13-29: error: redeclaration for default tagged %destructor
282 input.y:4.13-29: previous declaration
283 input.y:18.10-24: error: redeclaration for default tagged %printer
284 input.y:5.10-24: previous declaration
285 input.y:20.13-29: error: redeclaration for default tagless %destructor
286 input.y:10.13-29: previous declaration
287 input.y:21.10-24: error: redeclaration for default tagless %printer
288 input.y:11.10-24: previous declaration
289 ]])
290
291 AT_CLEANUP
292
293
294 ## ---------------------------------------------- ##
295 ## Per-type %printer and %destructor redeclared. ##
296 ## ---------------------------------------------- ##
297
298 AT_SETUP([Per-type %printer and %destructor redeclared])
299
300 AT_DATA([[input.y]],
301 [[%destructor { destroy ($$); } <field1> <field2>
302 %printer { print ($$); } <field1> <field2>
303
304 %destructor { destroy ($$); } <field1> <field1>
305 %printer { print ($$); } <field2> <field2>
306
307 %%
308
309 start: ;
310
311 %destructor { destroy ($$); } <field2> <field1>;
312 %printer { print ($$); } <field2> <field1>;
313 ]])
314
315 AT_BISON_CHECK([input.y], [1], [],
316 [[input.y:4.13-29: error: %destructor redeclaration for <field1>
317 input.y:1.13-29: previous declaration
318 input.y:4.13-29: error: %destructor redeclaration for <field1>
319 input.y:4.13-29: previous declaration
320 input.y:5.10-24: error: %printer redeclaration for <field2>
321 input.y:2.10-24: previous declaration
322 input.y:5.10-24: error: %printer redeclaration for <field2>
323 input.y:5.10-24: previous declaration
324 input.y:11.13-29: error: %destructor redeclaration for <field1>
325 input.y:4.13-29: previous declaration
326 input.y:11.13-29: error: %destructor redeclaration for <field2>
327 input.y:1.13-29: previous declaration
328 input.y:12.10-24: error: %printer redeclaration for <field1>
329 input.y:2.10-24: previous declaration
330 input.y:12.10-24: error: %printer redeclaration for <field2>
331 input.y:5.10-24: previous declaration
332 ]])
333
334 AT_CLEANUP
335
336
337 ## ---------------------------------------- ##
338 ## Unused values with default %destructor. ##
339 ## ---------------------------------------- ##
340
341 AT_SETUP([Unused values with default %destructor])
342
343 AT_DATA([[input.y]],
344 [[%destructor { destroy ($$); } <>
345 %type <tag> tagged
346
347 %%
348
349 start: end end tagged tagged { $<tag>1; $3; } ;
350 end: { } ;
351 tagged: { } ;
352 ]])
353
354 AT_BISON_CHECK([input.y], [0], [],
355 [[input.y:6.8-45: warning: unset value: $$
356 input.y:6.8-45: warning: unused value: $2
357 input.y:7.6-8: warning: unset value: $$
358 ]])
359
360 AT_DATA([[input.y]],
361 [[%destructor { destroy ($$); } <*>
362 %type <tag> tagged
363
364 %%
365
366 start: end end tagged tagged { $<tag>1; $3; } ;
367 end: { } ;
368 tagged: { } ;
369 ]])
370
371 AT_BISON_CHECK([input.y], [0], [],
372 [[input.y:6.8-45: warning: unused value: $4
373 input.y:8.9-11: warning: unset value: $$
374 ]])
375
376 AT_CLEANUP
377
378
379 ## ----------------------------------------- ##
380 ## Unused values with per-type %destructor. ##
381 ## ----------------------------------------- ##
382
383 AT_SETUP([Unused values with per-type %destructor])
384
385 AT_DATA([[input.y]],
386 [[%destructor { destroy ($$); } <field1>
387 %type <field1> start end
388
389 %%
390
391 start: end end { $1; } ;
392 end: { } ;
393 ]])
394
395 AT_BISON_CHECK([input.y], [0], [],
396 [[input.y:6.8-22: warning: unset value: $$
397 input.y:6.8-22: warning: unused value: $2
398 input.y:7.6-8: warning: unset value: $$
399 ]])
400
401 AT_CLEANUP
402
403
404 ## ---------------------- ##
405 ## Incompatible Aliases. ##
406 ## ---------------------- ##
407
408 AT_SETUP([Incompatible Aliases])
409
410 AT_DATA([input.y],
411 [[%token foo "foo"
412
413 %type <bar> foo
414 %printer {bar} foo
415 %destructor {bar} foo
416 %left foo
417
418 %type <baz> "foo"
419 %printer {baz} "foo"
420 %destructor {baz} "foo"
421 %left "foo"
422
423 %%
424 exp: foo;
425 ]])
426
427 AT_BISON_CHECK([input.y], [1], [],
428 [[input.y:8.7-11: error: %type redeclaration for foo
429 input.y:3.7-11: previous declaration
430 input.y:10.13-17: error: %destructor redeclaration for foo
431 input.y:5.13-17: previous declaration
432 input.y:9.10-14: error: %printer redeclaration for foo
433 input.y:4.10-14: previous declaration
434 input.y:11.1-5: error: %left redeclaration for foo
435 input.y:6.1-5: previous declaration
436 ]])
437
438 AT_CLEANUP
439
440
441
442 ## ----------------------- ##
443 ## Torturing the Scanner. ##
444 ## ----------------------- ##
445
446 # Be sure to compile and run, so that the C compiler checks what
447 # we do.
448
449 AT_SETUP([Torturing the Scanner])
450
451 AT_BISON_OPTION_PUSHDEFS
452 AT_DATA([input.y], [])
453 AT_BISON_CHECK([input.y], [1], [],
454 [[input.y:1.1: error: syntax error, unexpected end of file
455 ]])
456
457
458 AT_DATA([input.y],
459 [{}
460 ])
461 AT_BISON_CHECK([input.y], [1], [],
462 [[input.y:1.1-2: error: syntax error, unexpected {...}
463 ]])
464
465
466 AT_DATA_GRAMMAR([input.y],
467 [[%{
468 /* This is seen in GCC: a %{ and %} in middle of a comment. */
469 const char *foo = "So %{ and %} can be here too.";
470
471 #if 0
472 /* These examples test Bison while not stressing C compilers too much.
473 Many C compilers mishandle backslash-newlines, so this part of the
474 test is inside "#if 0". The comment and string are written so that
475 the "#endif" will be seen regardless of the C compiler bugs that we
476 know about, namely:
477
478 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
479 comment.
480
481 The Apple Darwin compiler (as of late 2002) mishandles
482 \\[newline]' within a character constant.
483
484 */
485
486 /\
487 * A comment with backslash-newlines in it. %} *\
488 \
489 /
490 /* { Close the above comment, if the C compiler mishandled it. */
491
492 char str[] = "\\
493 " A string with backslash-newlines in it %{ %} \\
494 \
495 "";
496
497 char apostrophe = '\'';
498 #endif
499
500 #include <stdio.h>
501 #include <stdlib.h>
502 #include <assert.h>
503 %}
504 /* %{ and %} can be here too. */
505
506 %{
507 /* Exercise pre-prologue dependency to %union. */
508 typedef int value;
509 %}
510
511 /* Exercise M4 quoting: '@:>@@:>@', 0. */
512
513 /* Also exercise %union. */
514 %union
515 {
516 value ival; /* A comment to exercise an old bug. */
517 };
518
519
520 /* Exercise post-prologue dependency to %union. */
521 %{
522 static YYSTYPE value_as_yystype (value val);
523
524 /* Exercise quotes in declarations. */
525 char quote[] = "@:>@@:>@,";
526 %}
527
528 %{
529 ]AT_YYERROR_DECLARE[
530 ]AT_YYLEX_DECLARE[
531 %}
532
533 %type <ival> '@<:@'
534
535 /* Exercise quotes in strings. */
536 %token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
537
538 %%
539 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
540 exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
541 {
542 /* Exercise quotes in braces. */
543 char tmp[] = "@<:@%c@:>@,\n";
544 printf (tmp, $1);
545 }
546 ;
547
548 two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
549 oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
550 output.or.oline.opt: ;|oline;;|output;;;
551 output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
552 %%
553 /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
554
555 static YYSTYPE
556 value_as_yystype (value val)
557 {
558 YYSTYPE res;
559 res.ival = val;
560 return res;
561 }
562 ]AT_YYERROR_DEFINE[
563 static int
564 yylex (void)
565 {
566 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
567 #output "; /* "
568 */
569 static size_t toknum;
570 assert (toknum < sizeof input);
571 yylval = value_as_yystype (input[toknum]);
572 return input[toknum++];
573 }
574 ]])
575
576 # Pacify Emacs' font-lock-mode: "
577
578 AT_DATA([main.c],
579 [[typedef int value;
580 #include "input.h"
581
582 int yyparse (void);
583
584 int
585 main (void)
586 {
587 return yyparse ();
588 }
589 ]])
590 AT_BISON_OPTION_POPDEFS
591
592 AT_BISON_CHECK([-d -v -o input.c input.y])
593 AT_COMPILE([input.o])
594 AT_COMPILE([main.o])
595 AT_COMPILE([input], [input.o main.o])
596 AT_PARSER_CHECK([./input], 0,
597 [[[@<:@],
598 ]])
599
600 AT_CLEANUP
601
602
603 ## ---------------------- ##
604 ## Typed symbol aliases. ##
605 ## ---------------------- ##
606
607 AT_SETUP([Typed symbol aliases])
608
609 # Bison 2.0 broke typed symbol aliases - ensure they work.
610
611 AT_DATA_GRAMMAR([input.y],
612 [[%union
613 {
614 int val;
615 };
616 %token <val> MY_TOKEN "MY TOKEN"
617 %type <val> exp
618 %%
619 exp: "MY TOKEN";
620 %%
621 ]])
622
623 AT_BISON_CHECK([-o input.c input.y])
624
625 AT_CLEANUP
626
627
628 ## --------- ##
629 ## Require. ##
630 ## --------- ##
631
632 m4_define([AT_CHECK_REQUIRE],
633 [AT_SETUP([Require $1])
634 AT_DATA_GRAMMAR([input.y],
635 [[%require "$1";
636 %%
637 empty_file:;
638 ]])
639 AT_BISON_CHECK([-o input.c input.y], $2, [], ignore)
640 AT_CLEANUP
641 ])
642
643 AT_CHECK_REQUIRE(1.0, 0)
644 AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
645 ## FIXME: Some day augment this version number.
646 AT_CHECK_REQUIRE(100.0, 63)
647
648
649 ## ------------------------------------- ##
650 ## String aliases for character tokens. ##
651 ## ------------------------------------- ##
652
653 AT_SETUP([String aliases for character tokens])
654
655 # Bison once thought a character token and its alias were different symbols
656 # with the same user token number.
657
658 AT_DATA_GRAMMAR([input.y],
659 [[%token 'a' "a"
660 %%
661 start: 'a';
662 %%
663 ]])
664
665 AT_BISON_CHECK([-o input.c input.y])
666
667 AT_CLEANUP
668
669
670 ## -------------- ##
671 ## Symbol names. ##
672 ## -------------- ##
673
674 AT_SETUP([Symbols])
675
676 AT_BISON_OPTION_PUSHDEFS
677 AT_DATA_GRAMMAR([input.y],
678 [[%token WITH-DASH
679 %token WITHOUT_DASH "WITHOUT-DASH"
680 %token WITH.PERIOD
681 %token WITHOUT_PERIOD "WITHOUT.PERIOD"
682 %code {
683 ]AT_YYERROR_DECLARE[
684 ]AT_YYLEX_DECLARE[
685 }
686 %%
687 start: with-dash without_dash with.period without_period;
688 with-dash: WITH-DASH;
689 without_dash: "WITHOUT-DASH";
690 with.period: WITH.PERIOD;
691 without_period: "WITHOUT.PERIOD";
692 %%
693 ]AT_YYERROR_DEFINE[
694 ]AT_YYLEX_DEFINE[
695 ]])
696 AT_BISON_OPTION_POPDEFS
697
698 # POSIX Yacc accept periods, but not dashes.
699 AT_BISON_CHECK([--yacc input.y], [1], [],
700 [[input.y:9.8-16: POSIX Yacc forbids dashes in symbol names: WITH-DASH
701 input.y:18.8-16: POSIX Yacc forbids dashes in symbol names: with-dash
702 ]])
703
704 # So warn about them.
705 AT_BISON_CHECK([-Wyacc input.y], [], [],
706 [[input.y:9.8-16: warning: POSIX Yacc forbids dashes in symbol names: WITH-DASH
707 input.y:18.8-16: warning: POSIX Yacc forbids dashes in symbol names: with-dash
708 ]])
709
710 # Dashes are fine for GNU Bison.
711 AT_BISON_CHECK([-o input.c input.y])
712
713 # Make sure we don't export silly token identifiers with periods or dashes.
714 AT_COMPILE([input.o])
715
716
717 # Periods are genuine letters, they can start identifiers.
718 # Digits and dashes cannot.
719 AT_DATA_GRAMMAR([input.y],
720 [[%token .GOOD
721 -GOOD
722 1NV4L1D
723 -123
724 %%
725 start: .GOOD GOOD
726 ]])
727 AT_BISON_CHECK([-o input.c input.y], [1], [],
728 [[input.y:10.10: error: invalid character: '-'
729 input.y:11.10-16: error: invalid identifier: '1NV4L1D'
730 input.y:12.10: error: invalid character: '-'
731 ]])
732
733 AT_CLEANUP
734
735
736 ## ----------------- ##
737 ## Numbered tokens. ##
738 ## ----------------- ##
739
740 AT_SETUP([Numbered tokens])
741
742 AT_DATA_GRAMMAR([redecl.y],
743 [[%token DECIMAL_1 11259375
744 HEXADECIMAL_1 0xabcdef
745 HEXADECIMAL_2 0xFEDCBA
746 DECIMAL_2 16702650
747 %%
748 start: DECIMAL_1 HEXADECIMAL_2;
749 ]])
750
751 AT_BISON_CHECK([redecl.y], [1], [],
752 [[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1
753 redecl.y:9.8-16: previous declaration for DECIMAL_1
754 redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2
755 redecl.y:11.10-22: previous declaration for HEXADECIMAL_2
756 ]])
757
758 AT_DATA_GRAMMAR([too-large.y],
759 [[%token TOO_LARGE_DEC 999999999999999999999
760 TOO_LARGE_HEX 0xFFFFFFFFFFFFFFFFFFF
761 %%
762 start: TOO_LARGE_DEC TOO_LARGE_HEX
763 %%
764 ]])
765
766 AT_BISON_CHECK([too-large.y], [1], [],
767 [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999'
768 too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF'
769 ]])
770
771 AT_CLEANUP
772
773
774 ## --------------------- ##
775 ## Unclosed constructs. ##
776 ## --------------------- ##
777
778 AT_SETUP([Unclosed constructs])
779
780 # Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
781 # they were prepended to whatever it STRING_GROW'ed next. It also threw them
782 # away rather than returning them to the parser. The effect was confusing
783 # subsequent error messages.
784
785 AT_DATA([input.y],
786 [[%token A "a
787 %token B "b"
788 %token AB "ab" // Used to complain that "ab" was already used.
789 %token C '1
790 %token TWO "2"
791 %token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
792
793 %%
794
795 start: ;
796
797 // Used to report a syntax error because it didn't see any kind of symbol
798 // identifier.
799 %type <f> 'a
800 ;
801 %type <f> "a
802 ;
803 // Used to report a syntax error because it didn't see braced code.
804 %destructor { free ($$)
805 ]])
806
807 AT_BISON_CHECK([-o input.c input.y], 1, [],
808 [[input.y:1.10-2.0: error: missing '"' at end of line
809 input.y:4.10-5.0: error: missing "'" at end of line
810 input.y:14.11-15.0: error: missing "'" at end of line
811 input.y:16.11-17.0: error: missing '"' at end of line
812 input.y:19.13-20.0: error: missing '}' at end of file
813 input.y:20.1: error: syntax error, unexpected end of file
814 ]])
815
816 AT_CLEANUP
817
818
819 ## ------------------------- ##
820 ## %start after first rule. ##
821 ## ------------------------- ##
822
823 AT_SETUP([%start after first rule])
824
825 # Bison once complained that a %start after the first rule was a redeclaration
826 # of the start symbol.
827
828 AT_DATA([input.y],
829 [[%%
830 false_start: ;
831 start: false_start ;
832 %start start;
833 ]])
834
835 AT_BISON_CHECK([-o input.c input.y])
836
837 AT_CLEANUP
838
839
840 ## --------------------- ##
841 ## %prec takes a token. ##
842 ## --------------------- ##
843
844 AT_SETUP([%prec takes a token])
845
846 # Bison once allowed %prec sym where sym was a nonterminal.
847
848 AT_DATA([input.y],
849 [[%%
850 start: PREC %prec PREC ;
851 PREC: ;
852 ]])
853
854 AT_BISON_CHECK([input.y], [1], [],
855 [[input.y:3.1-4: error: rule given for PREC, which is a token
856 ]])
857
858 AT_CLEANUP
859
860
861 ## ------------------------------- ##
862 ## %prec's token must be defined. ##
863 ## ------------------------------- ##
864
865 AT_SETUP([[%prec's token must be defined]])
866
867 # According to POSIX, a %prec token must be defined separately.
868
869 AT_DATA([[input.y]],
870 [[%%
871 start: %prec PREC ;
872 ]])
873
874 AT_BISON_CHECK([[input.y]], [[0]], [],
875 [[input.y:2.8-17: warning: token for %prec is not defined: PREC
876 ]])
877
878 AT_CLEANUP
879
880
881 ## -------------------------------- ##
882 ## Reject unused %code qualifiers. ##
883 ## -------------------------------- ##
884
885 AT_SETUP([Reject unused %code qualifiers])
886
887 AT_DATA([input-c.y],
888 [[%code q {}
889 %code bad {}
890 %code bad {}
891 %code format {}
892 %%
893 start: ;
894 ]])
895 AT_BISON_CHECK([[input-c.y]], [[1]], [],
896 [[input-c.y:1.7: error: %code qualifier 'q' is not used
897 input-c.y:2.7-9: error: %code qualifier 'bad' is not used
898 input-c.y:3.7-9: error: %code qualifier 'bad' is not used
899 input-c.y:4.7-12: error: %code qualifier 'format' is not used
900 ]])
901
902 AT_DATA([input-c-glr.y],
903 [[%code q {}
904 %code bad {}
905 %code bad {}
906 %%
907 start: ;
908 ]])
909 AT_BISON_CHECK([[input-c-glr.y]], [[1]], [],
910 [[input-c-glr.y:1.7: error: %code qualifier 'q' is not used
911 input-c-glr.y:2.7-9: error: %code qualifier 'bad' is not used
912 input-c-glr.y:3.8-10: error: %code qualifier 'bad' is not used
913 ]])
914
915 AT_DATA([input-c++.y],
916 [[%code q {}
917 %code bad {}
918 %code q {}
919 %%
920 start: ;
921 ]])
922 AT_BISON_CHECK([[input-c++.y]], [[1]], [],
923 [[input-c++.y:1.7: error: %code qualifier 'q' is not used
924 input-c++.y:2.7-9: error: %code qualifier 'bad' is not used
925 input-c++.y:3.8: error: %code qualifier 'q' is not used
926 ]])
927
928 AT_DATA([input-c++-glr.y],
929 [[%code bad {}
930 %code q {}
931 %code q {}
932 %%
933 start: ;
934 ]])
935 AT_BISON_CHECK([[input-c++-glr.y]], [[1]], [],
936 [[input-c++-glr.y:1.7-9: error: %code qualifier 'bad' is not used
937 input-c++-glr.y:2.7: error: %code qualifier 'q' is not used
938 input-c++-glr.y:3.7: error: %code qualifier 'q' is not used
939 ]])
940
941 AT_DATA([special-char-@@.y],
942 [[%code bad {}
943 %code q {}
944 %code q {}
945 %%
946 start: ;
947 ]])
948 AT_BISON_CHECK([[special-char-@@.y]], [[1]], [],
949 [[special-char-@@.y:1.7-9: error: %code qualifier 'bad' is not used
950 special-char-@@.y:2.7: error: %code qualifier 'q' is not used
951 special-char-@@.y:3.7: error: %code qualifier 'q' is not used
952 ]])
953
954 AT_DATA([special-char-@:>@.y],
955 [[%code bad {}
956 %code q {}
957 %code q {}
958 %%
959 start: ;
960 ]])
961 AT_BISON_CHECK([[special-char-@:>@.y]], [[1]], [],
962 [[special-char-@:>@.y:1.7-9: error: %code qualifier 'bad' is not used
963 special-char-@:>@.y:2.7: error: %code qualifier 'q' is not used
964 special-char-@:>@.y:3.7: error: %code qualifier 'q' is not used
965 ]])
966
967 AT_CLEANUP
968
969
970 ## ---------------- ##
971 ## %define errors. ##
972 ## ---------------- ##
973
974 AT_SETUP([%define errors])
975
976 AT_DATA([input-redefined.y],
977 [[%define var "value1"
978 %define var "value1"
979 %define var "value2"
980 %define special1 "@:>@"
981 %define special2 "@<:@"
982 %%
983 start: ;
984 ]])
985
986 AT_BISON_CHECK([[input-redefined.y]], [[1]], [],
987 [[input-redefined.y:2.9-11: error: %define variable 'var' redefined
988 input-redefined.y:1.9-11: previous definition
989 input-redefined.y:3.10-12: error: %define variable 'var' redefined
990 input-redefined.y:2.9-11: previous definition
991 ]])
992
993 AT_DATA([input-unused.y],
994 [[%define var "value"
995 %%
996 start: ;
997 ]])
998
999 AT_BISON_CHECK([[input-unused.y]], [[1]], [],
1000 [[input-unused.y:1.9-11: error: %define variable 'var' is not used
1001 ]])
1002
1003 AT_CLEANUP
1004
1005
1006 ## ----------------------------------- ##
1007 ## %define, --define, --force-define. ##
1008 ## ----------------------------------- ##
1009
1010 AT_SETUP([[%define, --define, --force-define]])
1011
1012 AT_DATA([[skel.c]],
1013 [[m4@&t@_divert_push(0)@
1014 @output(b4_parser_file_name@)@
1015 [var-dd: ]b4_percent_define_get([[var-dd]])[
1016 var-ff: ]b4_percent_define_get([[var-ff]])[
1017 var-dfg: ]b4_percent_define_get([[var-dfg]])[
1018 var-fd: ]b4_percent_define_get([[var-fd]])
1019 m4@&t@_divert_pop(0)
1020 ]])
1021 AT_DATA([[input.y]],
1022 [[%define var-dfg "gram"
1023 %%
1024 start: ;
1025 ]])
1026 AT_BISON_CHECK([[-Dvar-dd=cmd-d1 -Dvar-dd=cmd-d2 \
1027 -Fvar-ff=cmd-f1 -Fvar-ff=cmd-f2 \
1028 -Dvar-dfg=cmd-d -Fvar-dfg=cmd-f \
1029 -Fvar-fd=cmd-f -Dvar-fd=cmd-d \
1030 --skeleton ./skel.c input.y]])
1031 AT_CHECK([[cat input.tab.c]], [[0]],
1032 [[var-dd: cmd-d2
1033 var-ff: cmd-f2
1034 var-dfg: cmd-f
1035 var-fd: cmd-d
1036 ]])
1037
1038 AT_DATA([[input-dg.y]],
1039 [[%define var "gram"
1040 %%
1041 start: ;
1042 ]])
1043 AT_BISON_CHECK([[-Dvar=cmd-d input-dg.y]], [[1]], [],
1044 [[input-dg.y:1.9-11: error: %define variable 'var' redefined
1045 <command line>:2: previous definition
1046 ]])
1047
1048 AT_DATA([[input-unused.y]],
1049 [[%%
1050 start: ;
1051 ]])
1052 AT_BISON_CHECK([[-Dunused-d -Funused-f input-unused.y]], [[1]], [],
1053 [[<command line>:2: error: %define variable 'unused-d' is not used
1054 <command line>:3: error: %define variable 'unused-f' is not used
1055 ]])
1056
1057 AT_CLEANUP
1058
1059 ## --------------------------- ##
1060 ## %define Boolean variables. ##
1061 ## --------------------------- ##
1062
1063 AT_SETUP([[%define Boolean variables]])
1064
1065 AT_DATA([Input.y],
1066 [[%language "Java"
1067 %define public "maybe"
1068 %define parser_class_name "Input"
1069 %%
1070 start: ;
1071 ]])
1072
1073 AT_BISON_CHECK([[Input.y]], [1], [],
1074 [[Input.y:2.9-14: error: invalid value for %define Boolean variable 'public'
1075 ]])
1076
1077 AT_CLEANUP
1078
1079 ## ------------------------ ##
1080 ## %define enum variables. ##
1081 ## ------------------------ ##
1082
1083 AT_SETUP([[%define enum variables]])
1084
1085 # Front-end.
1086 AT_DATA([[input.y]],
1087 [[%define lr.default-reductions bogus
1088 %%
1089 start: ;
1090 ]])
1091 AT_BISON_CHECK([[input.y]], [[1]], [[]],
1092 [[input.y:1.9-29: error: invalid value for %define variable 'lr.default-reductions': 'bogus'
1093 input.y:1.9-29: accepted value: 'most'
1094 input.y:1.9-29: accepted value: 'consistent'
1095 input.y:1.9-29: accepted value: 'accepting'
1096 ]])
1097
1098 # Back-end.
1099 # FIXME: these should be indented, but we shouldn't mess with the m4 yet
1100 AT_DATA([[input.y]],
1101 [[%define api.push-pull neither
1102 %%
1103 start: ;
1104 ]])
1105 AT_BISON_CHECK([[input.y]], [1], [],
1106 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1107 input.y:1.9-21: error: accepted value: 'pull'
1108 input.y:1.9-21: error: accepted value: 'push'
1109 input.y:1.9-21: error: accepted value: 'both'
1110 ]])
1111
1112 AT_CLEANUP
1113
1114 ## -------------------------------- ##
1115 ## %define backward compatibility. ##
1116 ## -------------------------------- ##
1117
1118 AT_SETUP([[%define backward compatibility]])
1119
1120 # The error messages tell us whether underscores in these variables are
1121 # being converted to dashes.
1122
1123 AT_DATA([[input.y]],
1124 [[%define api.push_pull "neither"
1125 %%
1126 start: ;
1127 ]])
1128 AT_BISON_CHECK([[input.y]], [1], [],
1129 [[input.y:1.9-21: error: invalid value for %define variable 'api.push-pull': 'neither'
1130 input.y:1.9-21: error: accepted value: 'pull'
1131 input.y:1.9-21: error: accepted value: 'push'
1132 input.y:1.9-21: error: accepted value: 'both'
1133 ]])
1134
1135 AT_DATA([[input.y]],
1136 [[%define lr.keep_unreachable_states maybe
1137 %%
1138 start: ;
1139 ]])
1140 AT_BISON_CHECK([[input.y]], [1], [],
1141 [[input.y:1.9-34: error: invalid value for %define Boolean variable 'lr.keep-unreachable-states'
1142 ]])
1143
1144 AT_DATA([[input.y]],
1145 [[%define foo_bar "baz"
1146 %%
1147 start: ;
1148 ]])
1149 AT_BISON_CHECK([[input.y]], [[1]], [],
1150 [[input.y:1.9-15: error: %define variable 'foo_bar' is not used
1151 ]])
1152
1153 AT_CLEANUP
1154
1155 ## ------------------------- ##
1156 ## Unused %define api.pure. ##
1157 ## ------------------------- ##
1158
1159 AT_SETUP([[Unused %define api.pure]])
1160
1161 # AT_CHECK_API_PURE(DECLS, VALUE)
1162 # -------------------------------
1163 # Make sure Bison reports that `%define api.pure VALUE' is unused when DECLS
1164 # are specified.
1165 m4_define([AT_CHECK_API_PURE],
1166 [
1167 AT_DATA([[input.y]],
1168 [[%define api.pure ]$2[
1169 ]$1[
1170 %%
1171 start: ;
1172 ]])
1173
1174 AT_BISON_CHECK([[input.y]], [[1]], [],
1175 [[input.y:1.9-16: error: %define variable 'api.pure' is not used
1176 ]])
1177 ])
1178
1179 AT_CHECK_API_PURE([[%language "c++" %defines]], [[]])
1180 AT_CHECK_API_PURE([[%language "c++" %defines]], [[false]])
1181 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[""]])
1182 AT_CHECK_API_PURE([[%language "c++" %defines %glr-parser]], [[false]])
1183 AT_CHECK_API_PURE([[%language "java"]], [[true]])
1184 AT_CHECK_API_PURE([[%language "java"]], [[false]])
1185
1186 AT_CLEANUP
1187
1188 ## -------------------------------- ##
1189 ## C++ namespace reference errors. ##
1190 ## -------------------------------- ##
1191
1192 AT_SETUP([[C++ namespace reference errors]])
1193
1194 # AT_CHECK_NAMESPACE_ERROR(NAMESPACE-DECL, ERROR, [ERROR], ...)
1195 # -------------------------------------------------------------
1196 # Make sure Bison reports all ERROR's for %define namespace "NAMESPACE-DECL".
1197 m4_define([AT_CHECK_NAMESPACE_ERROR],
1198 [
1199 AT_DATA([[input.y]],
1200 [[%language "C++"
1201 %defines
1202 %define namespace "]$1["
1203 %%
1204 start: ;
1205 ]])
1206
1207 AT_BISON_CHECK([[input.y]], [1], [],
1208 [m4_foreach([b4_arg], m4_dquote(m4_shift($@)),
1209 [[input.y:3.9-17: error: ]b4_arg[
1210 ]])])
1211 ])
1212
1213 AT_CHECK_NAMESPACE_ERROR([[]],
1214 [[namespace reference is empty]])
1215 AT_CHECK_NAMESPACE_ERROR([[ ]],
1216 [[namespace reference is empty]])
1217 AT_CHECK_NAMESPACE_ERROR([[foo::::bar]],
1218 [[namespace reference has consecutive "::"]])
1219 AT_CHECK_NAMESPACE_ERROR([[foo:: ::bar]],
1220 [[namespace reference has consecutive "::"]])
1221 AT_CHECK_NAMESPACE_ERROR([[::::bar]],
1222 [[namespace reference has consecutive "::"]])
1223 AT_CHECK_NAMESPACE_ERROR([[:: ::bar]],
1224 [[namespace reference has consecutive "::"]])
1225 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ::]],
1226 [[namespace reference has consecutive "::"]],
1227 [[namespace reference has a trailing "::"]])
1228 AT_CHECK_NAMESPACE_ERROR([[foo::bar::]],
1229 [[namespace reference has a trailing "::"]])
1230 AT_CHECK_NAMESPACE_ERROR([[foo::bar:: ]],
1231 [[namespace reference has a trailing "::"]])
1232 AT_CHECK_NAMESPACE_ERROR([[::]],
1233 [[namespace reference has a trailing "::"]])
1234
1235 AT_CLEANUP
1236
1237 ## ------------------------ ##
1238 ## Bad character literals. ##
1239 ## ------------------------ ##
1240
1241 # Bison used to accept character literals that were empty or contained
1242 # too many characters.
1243
1244 # FIXME: AT_DATA or some variant of AT_DATA may eventually permit
1245 # the final newline to be omitted. See the threads starting at
1246 # <http://lists.gnu.org/archive/html/bison-patches/2009-07/msg00019.html>.
1247
1248 AT_SETUP([[Bad character literals]])
1249
1250 AT_DATA([empty.y],
1251 [[%%
1252 start: '';
1253 start: '
1254 ]])
1255 AT_CHECK([[$PERL -e "print 'start: \'';" >> empty.y || exit 77]])
1256
1257 AT_BISON_CHECK([empty.y], [1], [],
1258 [[empty.y:2.8-9: warning: empty character literal
1259 empty.y:3.8-4.0: warning: empty character literal
1260 empty.y:3.8-4.0: error: missing "'" at end of line
1261 empty.y:4.8: warning: empty character literal
1262 empty.y:4.8: error: missing "'" at end of file
1263 ]])
1264
1265 AT_DATA([two.y],
1266 [[%%
1267 start: 'ab';
1268 start: 'ab
1269 ]])
1270 AT_CHECK([[$PERL -e "print 'start: \'ab';" >> two.y || exit 77]])
1271
1272 AT_BISON_CHECK([two.y], [1], [],
1273 [[two.y:2.8-11: warning: extra characters in character literal
1274 two.y:3.8-4.0: warning: extra characters in character literal
1275 two.y:3.8-4.0: error: missing "'" at end of line
1276 two.y:4.8-10: warning: extra characters in character literal
1277 two.y:4.8-10: error: missing "'" at end of file
1278 ]])
1279
1280 AT_DATA([three.y],
1281 [[%%
1282 start: 'abc';
1283 start: 'abc
1284 ]])
1285 AT_CHECK([[$PERL -e "print 'start: \'abc';" >> three.y || exit 77]])
1286
1287 AT_BISON_CHECK([three.y], [1], [],
1288 [[three.y:2.8-12: warning: extra characters in character literal
1289 three.y:3.8-4.0: warning: extra characters in character literal
1290 three.y:3.8-4.0: error: missing "'" at end of line
1291 three.y:4.8-11: warning: extra characters in character literal
1292 three.y:4.8-11: error: missing "'" at end of file
1293 ]])
1294
1295 AT_CLEANUP
1296
1297 ## ------------------------- ##
1298 ## Bad escapes in literals. ##
1299 ## ------------------------- ##
1300
1301 AT_SETUP([[Bad escapes in literals]])
1302
1303 AT_DATA([input.y],
1304 [[%%
1305 start: '\777' '\0' '\xfff' '\x0'
1306 '\uffff' '\u0000' '\Uffffffff' '\U00000000'
1307 '\ ' '\A';
1308 ]])
1309
1310 # It is not easy to create special characters, we cannot even trust tr.
1311 # Beside we cannot even expect "echo '\0'" to output two characters
1312 # (well three with \n): at least Bash 3.2 converts the two-character
1313 # sequence "\0" into a single NUL character.
1314 AT_CHECK([[$PERL -e 'print "start: \"\\\t\\\f\\\0\\\1\" ;";' >> input.y \
1315 || exit 77]])
1316
1317 AT_BISON_CHECK([input.y], [1], [],
1318 [[input.y:2.9-12: error: invalid number after \-escape: 777
1319 input.y:2.8-13: warning: empty character literal
1320 input.y:2.16-17: error: invalid number after \-escape: 0
1321 input.y:2.15-18: warning: empty character literal
1322 input.y:2.21-25: error: invalid number after \-escape: xfff
1323 input.y:2.20-26: warning: empty character literal
1324 input.y:2.29-31: error: invalid number after \-escape: x0
1325 input.y:2.28-32: warning: empty character literal
1326 input.y:3.9-14: error: invalid number after \-escape: uffff
1327 input.y:3.8-15: warning: empty character literal
1328 input.y:3.18-23: error: invalid number after \-escape: u0000
1329 input.y:3.17-24: warning: empty character literal
1330 input.y:3.27-36: error: invalid number after \-escape: Uffffffff
1331 input.y:3.26-37: warning: empty character literal
1332 input.y:3.40-49: error: invalid number after \-escape: U00000000
1333 input.y:3.39-50: warning: empty character literal
1334 input.y:4.9-10: error: invalid character after \-escape: ' '
1335 input.y:4.8-11: warning: empty character literal
1336 input.y:4.14-15: error: invalid character after \-escape: A
1337 input.y:4.13-16: warning: empty character literal
1338 input.y:5.9-16: error: invalid character after \-escape: \t
1339 input.y:5.17: error: invalid character after \-escape: \f
1340 input.y:5.18: error: invalid character after \-escape: \0
1341 input.y:5.19: error: invalid character after \-escape: \001
1342 ]])
1343
1344 AT_CLEANUP
1345
1346 ## ------------------------- ##
1347 ## LAC: Errors for %define. ##
1348 ## ------------------------- ##
1349
1350 AT_SETUP([[LAC: Errors for %define]])
1351
1352 AT_DATA([[input.y]],
1353 [[%%
1354 start: ;
1355 ]])
1356
1357 # parse.lac.* options are useless if LAC isn't actually activated.
1358 AT_BISON_CHECK([[-Dparse.lac.es-capacity-initial=1 input.y]],
1359 [[1]], [],
1360 [[<command line>:2: error: %define variable 'parse.lac.es-capacity-initial' is not used
1361 ]])
1362 AT_BISON_CHECK([[-Dparse.lac.memory-trace=full input.y]],
1363 [[1]], [],
1364 [[<command line>:2: error: %define variable 'parse.lac.memory-trace' is not used
1365 ]])
1366
1367 AT_CLEANUP
1368
1369 ## --------------------------------------------- ##
1370 ## -Werror is not affected by -Wnone and -Wall. ##
1371 ## --------------------------------------------- ##
1372
1373 AT_SETUP([[-Werror is not affected by -Wnone and -Wall]])
1374
1375 AT_DATA([[input.y]],
1376 [[%%
1377 foo-bar: ;
1378 ]])
1379
1380 # -Werror is not enabled by -Wall or equivalent.
1381 AT_BISON_CHECK([[-Wall input.y]], [[0]], [[]],
1382 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1383 ]])
1384 AT_BISON_CHECK([[-W input.y]], [[0]], [[]],
1385 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1386 ]])
1387 AT_BISON_CHECK([[-Wno-none input.y]], [[0]], [[]],
1388 [[input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1389 ]])
1390
1391 # -Werror is not disabled by -Wnone or equivalent.
1392 AT_BISON_CHECK([[-Werror,none,yacc input.y]], [[1]], [[]], [[stderr]])
1393 AT_CHECK([[sed 's/^.*bison:/bison:/' stderr]], [[0]],
1394 [[bison: warnings being treated as errors
1395 input.y:2.1-7: warning: POSIX Yacc forbids dashes in symbol names: foo-bar
1396 ]])
1397 [mv stderr experr]
1398 AT_BISON_CHECK([[-Werror,no-all,yacc input.y]], [[1]], [[]], [[experr]])
1399
1400 AT_CLEANUP
1401
1402
1403 ## ------------------------------------------------------ ##
1404 ## %name-prefix and %define api.prefix are incompatible. ##
1405 ## ------------------------------------------------------ ##
1406
1407 AT_SETUP([[%name-prefix and %define api.prefix are incompatible]])
1408
1409 # AT_TEST(DIRECTIVES, OPTIONS, ERROR-LOCATION)
1410 # --------------------------------------------
1411 m4_pushdef([AT_TEST],
1412 [AT_DATA([[input.y]],
1413 [[$1
1414 %%
1415 exp:;
1416 ]])
1417 AT_BISON_CHECK([[$2 input.y]], [[1]], [[]],
1418 [[$3: error: '%name-prefix' and '%define api.prefix' cannot be used together
1419 ]])
1420 ])
1421
1422 AT_TEST([%define api.prefix foo %name-prefix "bar"], [], [input.y:1.9-18])
1423 AT_TEST([], [-Dapi.prefix=foo -p bar], [<command line>:2])
1424 AT_TEST([%name-prefix "bar"], [-Dapi.prefix=foo], [<command line>:2])
1425 AT_TEST([%define api.prefix foo], [-p bar], [input.y:1.9-18])
1426
1427 m4_popdef([AT_TEST])
1428
1429 AT_CLEANUP
1430
1431
1432 ## -------------- ##
1433 ## Stray $ or @. ##
1434 ## -------------- ##
1435
1436 AT_SETUP([[Stray $ or @]])
1437
1438 # Give %printer and %destructor "<*> exp TOK" instead of "<*>" to
1439 # check that the warnings are reported once, not three times.
1440
1441 AT_DATA_GRAMMAR([[input.y]],
1442 [[%token TOK
1443 %destructor { $%; @%; } <*> exp TOK;
1444 %initial-action { $%; @%; };
1445 %printer { $%; @%; } <*> exp TOK;
1446 %%
1447 exp: TOK { $%; @%; $$ = $1; };
1448 ]])
1449
1450 AT_BISON_CHECK([[input.y]], 0, [],
1451 [[input.y:10.19: warning: stray '$'
1452 input.y:10.23: warning: stray '@'
1453 input.y:11.19: warning: stray '$'
1454 input.y:11.23: warning: stray '@'
1455 input.y:12.19: warning: stray '$'
1456 input.y:12.23: warning: stray '@'
1457 input.y:14.19: warning: stray '$'
1458 input.y:14.23: warning: stray '@'
1459 ]])
1460
1461 AT_CLEANUP
1462
1463
1464
1465 ## ---------------- ##
1466 ## Code injection. ##
1467 ## ---------------- ##
1468
1469
1470 AT_SETUP([[Code injection]])
1471
1472 m4_pattern_allow([^m4_errprintn$])
1473
1474 # AT_TEST([MACRO])
1475 # ----------------
1476 # Try to have MACRO be run by bison.
1477 m4_pushdef([AT_TEST],
1478 [AT_DATA([[input.y]],
1479 [[%type <$1(DEAD %type)> exp
1480 %token <$1(DEAD %token)> a
1481 %initial-action
1482 {
1483 $$;
1484 $<$1(DEAD %initial-action)>$
1485 };
1486 %printer
1487 {
1488 $$
1489 $<$1(DEAD %printer)>$
1490 } <> <*>;
1491 %lex-param
1492 {
1493 $1(DEAD %lex-param)
1494 };
1495 %parse-param
1496 {
1497 $1(DEAD %parse-param)
1498 };
1499 %%
1500 exp:
1501 a a[last]
1502 {
1503 $$;
1504 $][1;
1505 $<$1(DEAD action 1)>$
1506 $<$1(DEAD action 2)>1
1507 $<$1(DEAD action 3)>last
1508 $<$1(DEAD action 4)>0
1509 ;
1510 };
1511 ]])
1512
1513 # FIXME: Provide a means to iterate over all the skeletons.
1514 AT_BISON_CHECK([[-d input.y]])
1515 AT_BISON_CHECK([[-d -S glr.c input.y]])
1516 AT_BISON_CHECK([[-d -S lalr1.cc input.y]])
1517 AT_BISON_CHECK([[-d -S glr.cc input.y]])
1518 AT_BISON_CHECK([[ -S lalr1.java input.y]])
1519 ])
1520
1521 AT_TEST([m4_errprintn])
1522 AT_TEST([@:>@m4_errprintn])
1523
1524 m4_popdef([AT_TEST])
1525
1526 AT_CLEANUP