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