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