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