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