]> git.saurik.com Git - bison.git/blame - tests/input.at
Use ASCII for Sebastien Fricker's name.
[bison.git] / tests / input.at
CommitLineData
087b9fdf 1# Checking the Bison scanner. -*- Autotest -*-
279cabb6
JD
2# Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007 Free Software Foundation,
3# Inc.
9b2d0677
AD
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 2, or (at your option)
8# 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, write to the Free Software
0fb669f9
PE
17# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18# 02110-1301, USA.
9b2d0677
AD
19
20AT_BANNER([[Input Processing.]])
21
22# Mostly test that we are robust to mistakes.
23
6c35d22c 24
9b2d0677
AD
25## ------------ ##
26## Invalid $n. ##
27## ------------ ##
28
287b314e 29AT_SETUP([Invalid $n and @n])
9b2d0677
AD
30
31AT_DATA([input.y],
32[[%%
bfcf1f3a 33exp: { $$ = $1 ; };
bfcf1f3a 34exp: { @$ = @1 ; };
9b2d0677
AD
35]])
36
37AT_CHECK([bison input.y], [1], [],
e9071366
AD
38[[input.y:2.13-14: integer out of range: `$1'
39input.y:3.13-14: integer out of range: `@1'
9b2d0677
AD
40]])
41
42AT_CLEANUP
9af3fbce
AD
43
44
45## -------------- ##
e776192e 46## Type Clashes. ##
9af3fbce
AD
47## -------------- ##
48
e776192e 49AT_SETUP([Type Clashes])
9af3fbce
AD
50
51AT_DATA([input.y],
ffa4ba3a
JD
52[[%union { int bar; }
53%token foo
9af3fbce
AD
54%type <bar> exp
55%%
ffa4ba3a 56exp: foo { $$; } foo { $2; } foo
9af3fbce
AD
57 | foo
58 | /* Empty. */
59 ;
60]])
61
ffa4ba3a
JD
62AT_CHECK([bison input.y], [1], [],
63[[input.y:5.12-13: $$ for the midrule at $2 of `exp' has no declared type
64input.y:5.24-25: $2 of `exp' has no declared type
65input.y:5.6-32: warning: type clash on default action: <bar> != <>
66input.y:6.6-8: warning: type clash on default action: <bar> != <>
67input.y:7.5: warning: empty rule for typed nonterminal, and no action
9af3fbce
AD
68]])
69
70AT_CLEANUP
5a08f1ce
AD
71
72
ffa4ba3a
JD
73# _AT_UNUSED_VALUES_DECLARATIONS()
74# --------------------------------------------
75# Generate the token, type, and destructor
76# declarations for the unused values tests.
378f4bd8 77
ffa4ba3a
JD
78m4_define([_AT_UNUSED_VALUES_DECLARATIONS],
79[[[%token <integer> INT;
80%type <integer> a b c d e f g h i j k l;
81%destructor { destroy ($$); } INT a b c d e f g h i j k l;]]])
378f4bd8 82
ffa4ba3a 83
17bd8a73
JD
84# AT_CHECK_UNUSED_VALUES(DECLARATIONS_AFTER, CHECK_MIDRULE_VALUES)
85# ------------------------------------------------------------------
ffa4ba3a
JD
86# Generate a grammar to test unused values,
87# compile it, run it. If DECLARATIONS_AFTER
88# is set, then the token, type, and destructor
89# declarations are generated after the rules
17bd8a73
JD
90# rather than before. If CHECK_MIDRULE_VALUES
91# is set, then --warnings=midrule-values is
92# set.
ffa4ba3a
JD
93
94m4_define([AT_CHECK_UNUSED_VALUES],
95[AT_DATA([input.y],
96m4_ifval($1, [
97
98
99], [_AT_UNUSED_VALUES_DECLARATIONS
100])[[%%
27622431 101start:
ffa4ba3a
JD
102 'a' a { $]2[ } | 'b' b { $]2[ } | 'c' c { $]2[ } | 'd' d { $]2[ } | 'e' e { $]2[ }
103| 'f' f { $]2[ } | 'g' g { $]2[ } | 'h' h { $]2[ } | 'i' i { $]2[ } | 'j' j { $]2[ }
104| 'k' k { $]2[ } | 'l' l { $]2[ }
378f4bd8 105;
27622431
PE
106
107a: INT | INT { } INT { } INT { };
108b: INT | /* empty */;
519d0004
JD
109c: INT | INT { $]1[ } INT { $<integer>2 } INT { $<integer>4 };
110d: INT | INT { } INT { $]1[ } INT { $<integer>2 };
ffa4ba3a
JD
111e: INT | INT { } INT { } INT { $]1[ };
112f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; };
ddc8ede1
PE
113g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { };
114h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { };
ffa4ba3a
JD
115i: INT | INT INT { } { $]$[ = $]1[ + $]2[; };
116j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; };
ddc8ede1
PE
117k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { };
118l: INT | INT { $<integer>$ = $<integer>1; } INT { $<integer>$ = $<integer>2 + $<integer>3; } INT { $<integer>$ = $<integer>4 + $<integer>5; };]]m4_ifval($1, [
ffa4ba3a
JD
119_AT_UNUSED_VALUES_DECLARATIONS])
120)
121
17bd8a73 122AT_CHECK([bison]m4_ifval($2, [ --warnings=midrule-values ])[ input.y], [0], [],
ffa4ba3a
JD
123[[input.y:11.10-32: warning: unset value: $]$[
124input.y:11.10-32: warning: unused value: $]1[
125input.y:11.10-32: warning: unused value: $]3[
126input.y:11.10-32: warning: unused value: $]5[
127input.y:12.9: warning: empty rule for typed nonterminal, and no action
17bd8a73 128]]m4_ifval($2, [[[input.y:13.14-19: warning: unset value: $$
519d0004 129input.y:13.25-39: warning: unset value: $$
17bd8a73 130]]])[[input.y:13.10-59: warning: unset value: $]$[
519d0004
JD
131input.y:13.10-59: warning: unused value: $]3[
132input.y:13.10-59: warning: unused value: $]5[
17bd8a73
JD
133]]m4_ifval($2, [[[input.y:14.14-16: warning: unset value: $$
134]]])[[input.y:14.10-47: warning: unset value: $]$[
519d0004
JD
135input.y:14.10-47: warning: unused value: $]3[
136input.y:14.10-47: warning: unused value: $]5[
ffa4ba3a
JD
137input.y:15.10-36: warning: unset value: $]$[
138input.y:15.10-36: warning: unused value: $]3[
139input.y:15.10-36: warning: unused value: $]5[
ddc8ede1
PE
140input.y:17.10-58: warning: unset value: $]$[
141input.y:17.10-58: warning: unused value: $]1[
17bd8a73
JD
142]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]2[
143]]])[[input.y:17.10-58: warning: unused value: $]3[
144]]m4_ifval($2, [[[input.y:17.10-58: warning: unused value: $]4[
145]]])[[input.y:17.10-58: warning: unused value: $]5[
ddc8ede1
PE
146input.y:18.10-72: warning: unset value: $]$[
147input.y:18.10-72: warning: unused value: $]1[
148input.y:18.10-72: warning: unused value: $]3[
17bd8a73
JD
149]]m4_ifval($2, [[[input.y:18.10-72: warning: unused value: $]4[
150]]])[[input.y:18.10-72: warning: unused value: $]5[
151]]m4_ifval($2, [[[input.y:20.10-55: warning: unused value: $]3[
152]]])[[input.y:21.10-68: warning: unset value: $]$[
ddc8ede1
PE
153input.y:21.10-68: warning: unused value: $]1[
154input.y:21.10-68: warning: unused value: $]2[
17bd8a73
JD
155]]m4_ifval($2, [[[input.y:21.10-68: warning: unused value: $]4[
156]]]))])
27622431 157
378f4bd8 158
ffa4ba3a
JD
159## --------------- ##
160## Unused values. ##
161## --------------- ##
162
163AT_SETUP([Unused values])
164AT_CHECK_UNUSED_VALUES
17bd8a73 165AT_CHECK_UNUSED_VALUES(, [1])
ffa4ba3a
JD
166AT_CLEANUP
167
168
169## ------------------------------------------ ##
170## Unused values before symbol declarations. ##
171## ------------------------------------------ ##
84866159 172
ffa4ba3a
JD
173AT_SETUP([Unused values before symbol declarations])
174AT_CHECK_UNUSED_VALUES([1])
17bd8a73 175AT_CHECK_UNUSED_VALUES([1], [1])
84866159 176AT_CLEANUP
378f4bd8
AD
177
178
ec5479ce
JD
179## --------------------------------------------- ##
180## Default %printer and %destructor redeclared. ##
181## --------------------------------------------- ##
182
183AT_SETUP([Default %printer and %destructor redeclared])
184
185AT_DATA([[input.y]],
12e35840
JD
186[[%destructor { destroy ($$); } <*> <*>
187%printer { destroy ($$); } <*> <*>
ec5479ce 188
12e35840
JD
189%destructor { destroy ($$); } <*>
190%printer { destroy ($$); } <*>
191
3ebecc24
JD
192%destructor { destroy ($$); } <> <>
193%printer { destroy ($$); } <> <>
12e35840 194
3ebecc24
JD
195%destructor { destroy ($$); } <>
196%printer { destroy ($$); } <>
ec5479ce
JD
197
198%%
199
200start: ;
201
12e35840
JD
202%destructor { destroy ($$); } <*>;
203%printer { destroy ($$); } <*>;
204
3ebecc24
JD
205%destructor { destroy ($$); } <>;
206%printer { destroy ($$); } <>;
ec5479ce
JD
207]])
208
209AT_CHECK([bison input.y], [1], [],
12e35840 210[[input.y:1.13-29: redeclaration for default tagged %destructor
b2a0b7ca 211input.y:1.13-29: previous declaration
12e35840 212input.y:2.10-26: redeclaration for default tagged %printer
b2a0b7ca 213input.y:2.10-26: previous declaration
12e35840 214input.y:4.13-29: redeclaration for default tagged %destructor
ec5479ce 215input.y:1.13-29: previous declaration
12e35840 216input.y:5.10-26: redeclaration for default tagged %printer
ec5479ce 217input.y:2.10-26: previous declaration
12e35840
JD
218input.y:7.13-29: redeclaration for default tagless %destructor
219input.y:7.13-29: previous declaration
220input.y:8.10-26: redeclaration for default tagless %printer
221input.y:8.10-26: previous declaration
222input.y:10.13-29: redeclaration for default tagless %destructor
223input.y:7.13-29: previous declaration
224input.y:11.10-26: redeclaration for default tagless %printer
225input.y:8.10-26: previous declaration
226input.y:17.13-29: redeclaration for default tagged %destructor
ec5479ce 227input.y:4.13-29: previous declaration
12e35840 228input.y:18.10-26: redeclaration for default tagged %printer
ec5479ce 229input.y:5.10-26: previous declaration
12e35840
JD
230input.y:20.13-29: redeclaration for default tagless %destructor
231input.y:10.13-29: previous declaration
232input.y:21.10-26: redeclaration for default tagless %printer
233input.y:11.10-26: previous declaration
ec5479ce
JD
234]])
235
236AT_CLEANUP
237
238
b2a0b7ca
JD
239## ---------------------------------------------- ##
240## Per-type %printer and %destructor redeclared. ##
241## ---------------------------------------------- ##
242
243AT_SETUP([Per-type %printer and %destructor redeclared])
244
245AT_DATA([[input.y]],
246[[%destructor { destroy ($$); } <field1> <field2>
247%printer { destroy ($$); } <field1> <field2>
248
249%destructor { destroy ($$); } <field1> <field1>
250%printer { destroy ($$); } <field2> <field2>
251
252%%
253
254start: ;
255
256%destructor { destroy ($$); } <field2> <field1>;
257%printer { destroy ($$); } <field2> <field1>;
258]])
259
260AT_CHECK([bison input.y], [1], [],
261[[input.y:4.13-29: %destructor redeclaration for <field1>
262input.y:1.13-29: previous declaration
263input.y:4.13-29: %destructor redeclaration for <field1>
264input.y:4.13-29: previous declaration
265input.y:5.10-26: %printer redeclaration for <field2>
266input.y:2.10-26: previous declaration
267input.y:5.10-26: %printer redeclaration for <field2>
268input.y:5.10-26: previous declaration
269input.y:11.13-29: %destructor redeclaration for <field1>
270input.y:4.13-29: previous declaration
271input.y:11.13-29: %destructor redeclaration for <field2>
272input.y:1.13-29: previous declaration
273input.y:12.10-26: %printer redeclaration for <field1>
274input.y:2.10-26: previous declaration
275input.y:12.10-26: %printer redeclaration for <field2>
276input.y:5.10-26: previous declaration
277]])
278
279AT_CLEANUP
280
281
ec5479ce
JD
282## ---------------------------------------- ##
283## Unused values with default %destructor. ##
284## ---------------------------------------- ##
285
286AT_SETUP([Unused values with default %destructor])
287
288AT_DATA([[input.y]],
3ebecc24 289[[%destructor { destroy ($$); } <>
12e35840
JD
290%type <tag> tagged
291
292%%
293
294start: end end tagged tagged { $<tag>1; $3; } ;
295end: { } ;
296tagged: { } ;
297]])
298
299AT_CHECK([bison input.y], [0], [],
300[[input.y:6.8-45: warning: unset value: $$
301input.y:6.8-45: warning: unused value: $2
302input.y:7.6-8: warning: unset value: $$
303]])
304
305AT_DATA([[input.y]],
306[[%destructor { destroy ($$); } <*>
307%type <tag> tagged
ec5479ce
JD
308
309%%
310
12e35840
JD
311start: end end tagged tagged { $<tag>1; $3; } ;
312end: { } ;
313tagged: { } ;
ec5479ce
JD
314]])
315
316AT_CHECK([bison input.y], [0], [],
12e35840
JD
317[[input.y:6.8-45: warning: unused value: $4
318input.y:8.9-11: warning: unset value: $$
ec5479ce
JD
319]])
320
321AT_CLEANUP
322
323
b2a0b7ca
JD
324## ----------------------------------------- ##
325## Unused values with per-type %destructor. ##
326## ----------------------------------------- ##
327
328AT_SETUP([Unused values with per-type %destructor])
329
330AT_DATA([[input.y]],
331[[%destructor { destroy ($$); } <field1>
332%type <field1> start end
333
334%%
335
336start: end end { $1; } ;
337end: { } ;
338]])
339
340AT_CHECK([bison input.y], [0], [],
341[[input.y:6.8-22: warning: unset value: $$
342input.y:6.8-22: warning: unused value: $2
343input.y:7.6-8: warning: unset value: $$
344]])
345
346AT_CLEANUP
347
348
df09ef2e
AD
349## ---------------------- ##
350## Incompatible Aliases. ##
351## ---------------------- ##
352
353AT_SETUP([Incompatible Aliases])
354
355AT_DATA([input.y],
356[[%token foo "foo"
357
358%type <bar> foo
359%printer {bar} foo
360%destructor {bar} foo
361%left foo
362
363%type <baz> "foo"
364%printer {baz} "foo"
365%destructor {baz} "foo"
366%left "foo"
367
368%%
369exp: foo;
370]])
371
372AT_CHECK([bison input.y], [1], [],
373[[input.y:8.7-11: %type redeclaration for foo
dd60572a 374input.y:3.7-11: previous declaration
df09ef2e 375input.y:10.13-17: %destructor redeclaration for foo
dd60572a 376input.y:5.13-17: previous declaration
e2a8c0f5 377input.y:9.10-14: %printer redeclaration for foo
dd60572a 378input.y:4.10-14: previous declaration
df09ef2e 379input.y:11.1-5: %left redeclaration for foo
dd60572a 380input.y:6.1-5: previous declaration
df09ef2e
AD
381]])
382
383AT_CLEANUP
384
385
5a08f1ce
AD
386
387## ----------------------- ##
388## Torturing the Scanner. ##
389## ----------------------- ##
390
391# Be sure to compile and run, so that the C compiler checks what
392# we do.
393
394AT_SETUP([Torturing the Scanner])
395
0baf7c50
PE
396
397AT_DATA([input.y], [])
398AT_CHECK([bison input.y], [1], [],
4a678af8 399[[input.y:1.1: syntax error, unexpected end of file
0baf7c50
PE
400]])
401
402
e9071366 403AT_DATA([input.y],
b2ddc3f3
AD
404[{}
405])
406AT_CHECK([bison input.y], [1], [],
4a678af8 407[[input.y:1.1-2: syntax error, unexpected {...}
b2ddc3f3
AD
408]])
409
410
9501dc6e 411AT_DATA_GRAMMAR([input.y],
5a08f1ce
AD
412[[%{
413/* This is seen in GCC: a %{ and %} in middle of a comment. */
414const char *foo = "So %{ and %} can be here too.";
415
dda7a53e
PE
416#if 0
417/* These examples test Bison while not stressing C compilers too much.
418 Many C compilers mishandle backslash-newlines, so this part of the
419 test is inside "#if 0". The comment and string are written so that
420 the "#endif" will be seen regardless of the C compiler bugs that we
421 know about, namely:
422
423 HP C (as of late 2002) mishandles *\[newline]\[newline]/ within a
424 comment.
425
426 The Apple Darwin compiler (as of late 2002) mishandles
427 \\[newline]' within a character constant.
428
429 */
430
206fe6a5 431/\
dda7a53e
PE
432* A comment with backslash-newlines in it. %} *\
433\
206fe6a5 434/
dda7a53e 435/* { Close the above comment, if the C compiler mishandled it. */
206fe6a5
PE
436
437char str[] = "\\
438" A string with backslash-newlines in it %{ %} \\
dda7a53e 439\
206fe6a5
PE
440"";
441
dda7a53e 442char apostrophe = '\'';
206fe6a5
PE
443#endif
444
5a08f1ce 445#include <stdio.h>
c4bd5bf7 446#include <stdlib.h>
5a08f1ce
AD
447%}
448/* %{ and %} can be here too. */
449
450%{
451/* Exercise pre-prologue dependency to %union. */
051ade83 452typedef int value;
5a08f1ce
AD
453%}
454
455/* Exercise M4 quoting: '@:>@@:>@', 0. */
456
457/* Also exercise %union. */
458%union
459{
051ade83 460 value ival; /* A comment to exercise an old bug. */
5a08f1ce
AD
461};
462
463
464/* Exercise post-prologue dependency to %union. */
465%{
051ade83 466static YYSTYPE value_as_yystype (value val);
5a08f1ce
AD
467
468/* Exercise quotes in declarations. */
469char quote[] = "@:>@@:>@,";
470%}
471
472%{
473static void yyerror (const char *s);
7172e23e 474static int yylex (void);
5a08f1ce
AD
475%}
476
206fe6a5 477%type <ival> '@<:@'
5a08f1ce
AD
478
479/* Exercise quotes in strings. */
3dc4c5fa 480%token FAKE "fake @<:@@:>@ \a\b\f\n\r\t\v\"\'\?\\\u005B\U0000005c ??!??'??(??)??-??/??<??=??> \x1\1"
5a08f1ce
AD
481
482%%
206fe6a5 483/* Exercise M4 quoting: '@:>@@:>@', @<:@, 1. */
087b9fdf 484exp: '@<:@' '\1' two '$' '@' '{' oline output.or.oline.opt
5a08f1ce
AD
485 {
486 /* Exercise quotes in braces. */
487 char tmp[] = "@<:@%c@:>@,\n";
488 printf (tmp, $1);
489 }
490;
5b7f88c7
PE
491
492two: '\x000000000000000000000000000000000000000000000000000000000000000000002';
493oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_';
087b9fdf 494output.or.oline.opt: ;|oline;;|output;;;
5b7f88c7 495output: '#' 'o' 'u' 't' 'p' 'u' 't' ' ';
5a08f1ce 496%%
206fe6a5 497/* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */
5a08f1ce
AD
498
499static YYSTYPE
051ade83 500value_as_yystype (value val)
5a08f1ce
AD
501{
502 YYSTYPE res;
503 res.ival = val;
504 return res;
505}
506
7172e23e 507static int
5a08f1ce
AD
508yylex (void)
509{
cf806753 510 static char const input[] = "@<:@\1\2$@{@oline@__@&t@oline__\
5b7f88c7
PE
511#output "; /* "
512 */
cf806753
PE
513 static size_t toknum;
514 if (! (toknum < sizeof input))
515 abort ();
516 yylval = value_as_yystype (input[toknum]);
517 return input[toknum++];
5a08f1ce
AD
518}
519
520static void
521yyerror (const char *msg)
522{
523 fprintf (stderr, "%s\n", msg);
524}
525]])
526
9501dc6e
AD
527# Pacify Emacs'font-lock-mode: "
528
5a08f1ce 529AT_DATA([main.c],
051ade83 530[[typedef int value;
5a08f1ce
AD
531#include "input.h"
532
533int yyparse (void);
534
535int
536main (void)
537{
538 return yyparse ();
539}
540]])
541
b56471a6 542AT_CHECK([bison -d -v -o input.c input.y])
efc6bf1b
PE
543AT_COMPILE([input.o], [-c input.c])
544AT_COMPILE([main.o], [-c main.c])
545AT_COMPILE([input], [input.o main.o])
1154cced 546AT_PARSER_CHECK([./input], 0,
206fe6a5 547[[[@<:@],
5a08f1ce
AD
548]])
549
550AT_CLEANUP
e59adf8f
PE
551
552
553## ---------------------- ##
554## Typed symbol aliases. ##
555## ---------------------- ##
556
557AT_SETUP([Typed symbol aliases])
558
559# Bison 2.0 broke typed symbol aliases - ensure they work.
560
561AT_DATA_GRAMMAR([input.y],
562[[%union
563{
564 int val;
565};
566%token <val> MY_TOKEN "MY TOKEN"
567%type <val> exp
568%%
569exp: "MY TOKEN";
570%%
571]])
572
573AT_CHECK([bison -o input.c input.y])
574
575AT_CLEANUP
b50d2359
AD
576
577
578## --------- ##
579## Require. ##
580## --------- ##
581
582m4_define([AT_CHECK_REQUIRE],
583[AT_SETUP([Require $1])
584AT_DATA_GRAMMAR([input.y],
585[[%require "$1";
586%%
587empty_file:;
588]])
589AT_CHECK([bison -o input.c input.y], $2, [], ignore)
590AT_CLEANUP
591])
592
593AT_CHECK_REQUIRE(1.0, 0)
594AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0)
595## FIXME: Some day augment this version number.
9b8a5ce0 596AT_CHECK_REQUIRE(100.0, 63)
1f6b3679
JD
597
598
599## ------------------------------------- ##
600## String aliases for character tokens. ##
601## ------------------------------------- ##
602
603AT_SETUP([String aliases for character tokens])
604
605# Bison once thought a character token and its alias were different symbols
606# with the same user token number.
607
608AT_DATA_GRAMMAR([input.y],
609[[%token 'a' "a"
610%%
611start: 'a';
612%%
613]])
614
615AT_CHECK([bison -o input.c input.y])
616
617AT_CLEANUP
47aee066
JD
618
619
620## --------------------- ##
621## Unclosed constructs. ##
622## --------------------- ##
623
624AT_SETUP([Unclosed constructs])
625
626# Bison's scan-gram.l once forgot to STRING_FINISH some unclosed constructs, so
627# they were prepended to whatever it STRING_GROW'ed next. It also threw them
628# away rather than returning them to the parser. The effect was confusing
629# subsequent error messages.
630
631AT_DATA([input.y],
632[[%token A "a
633%token B "b"
634%token AB "ab" // Used to complain that "ab" was already used.
635%token C '1
636%token TWO "2"
637%token TICK_TWELVE "'12" // Used to complain that "'12" was already used.
638
639%%
640
641start: ;
642
643// Used to report a syntax error because it didn't see any kind of symbol
644// identifier.
645%type <f> 'a
646;
647%type <f> "a
648;
649// Used to report a syntax error because it didn't see braced code.
650%destructor { free ($$)
651]])
652
653AT_CHECK([bison -o input.c input.y], 1, [],
654[[input.y:1.10-2.0: missing `"' at end of line
655input.y:4.10-5.0: missing `'' at end of line
656input.y:14.11-15.0: missing `'' at end of line
657input.y:16.11-17.0: missing `"' at end of line
658input.y:19.13-20.0: missing `}' at end of file
3be03b13 659input.y:20.1: syntax error, unexpected end of file
47aee066
JD
660]])
661
662AT_CLEANUP
4d7370cb
JD
663
664
665## ------------------------- ##
666## %start after first rule. ##
667## ------------------------- ##
668
669AT_SETUP([%start after first rule])
670
671# Bison once complained that a %start after the first rule was a redeclaration
672# of the start symbol.
673
674AT_DATA([input.y],
675[[%%
676false_start: ;
677start: false_start ;
678%start start;
679]])
680
681AT_CHECK([bison -o input.c input.y])
682
683AT_CLEANUP
26b8a438
JD
684
685
686## --------------------- ##
687## %prec takes a token. ##
688## --------------------- ##
689
690AT_SETUP([%prec takes a token])
691
692# Bison once allowed %prec sym where sym was a nonterminal.
693
694AT_DATA([input.y],
695[[%%
696start: PREC %prec PREC ;
697PREC: ;
698]])
699
700AT_CHECK([bison input.y], [1], [],
701[[input.y:3.1-4: rule given for PREC, which is a token
702]])
703
704AT_CLEANUP
8e0a5e9e
JD
705
706
6afc30cc
JD
707## -------------------------------- ##
708## Reject unused %code qualifiers. ##
709## -------------------------------- ##
8e0a5e9e 710
6afc30cc 711AT_SETUP([Reject unused %code qualifiers])
8e0a5e9e
JD
712
713AT_DATA([input-c.y],
16dc6a9e
JD
714[[%code q {}
715%code bad {}
716%code bad {}
8405b70c 717%code format {}
8e0a5e9e
JD
718%%
719start: ;
720]])
6afc30cc 721AT_CHECK([[bison input-c.y]], [0], [],
16dc6a9e
JD
722[[input-c.y:1.7: warning: %code qualifier `q' is not used
723input-c.y:2.7-9: warning: %code qualifier `bad' is not used
724input-c.y:3.7-9: warning: %code qualifier `bad' is not used
8405b70c 725input-c.y:4.7-12: warning: %code qualifier `format' is not used
08af01c2 726]])
8e0a5e9e
JD
727
728AT_DATA([input-c-glr.y],
16dc6a9e
JD
729[[%code q {}
730%code bad {}
731 %code bad {}
8e0a5e9e
JD
732%%
733start: ;
734]])
6afc30cc 735AT_CHECK([[bison input-c-glr.y]], [0], [],
16dc6a9e
JD
736[[input-c-glr.y:1.7: warning: %code qualifier `q' is not used
737input-c-glr.y:2.7-9: warning: %code qualifier `bad' is not used
738input-c-glr.y:3.8-10: warning: %code qualifier `bad' is not used
08af01c2 739]])
8e0a5e9e
JD
740
741AT_DATA([input-c++.y],
16dc6a9e
JD
742[[%code q {}
743%code bad {}
744 %code q {}
8e0a5e9e
JD
745%%
746start: ;
747]])
6afc30cc 748AT_CHECK([[bison input-c++.y]], [0], [],
16dc6a9e
JD
749[[input-c++.y:1.7: warning: %code qualifier `q' is not used
750input-c++.y:2.7-9: warning: %code qualifier `bad' is not used
751input-c++.y:3.8: warning: %code qualifier `q' is not used
08af01c2 752]])
8e0a5e9e
JD
753
754AT_DATA([input-c++-glr.y],
16dc6a9e
JD
755[[%code bad {}
756%code q {}
757%code q {}
8e0a5e9e
JD
758%%
759start: ;
760]])
6afc30cc 761AT_CHECK([[bison input-c++-glr.y]], [0], [],
16dc6a9e
JD
762[[input-c++-glr.y:1.7-9: warning: %code qualifier `bad' is not used
763input-c++-glr.y:2.7: warning: %code qualifier `q' is not used
764input-c++-glr.y:3.7: warning: %code qualifier `q' is not used
3fc65ead
JD
765]])
766
767AT_DATA([special-char-@@.y],
16dc6a9e
JD
768[[%code bad {}
769%code q {}
770%code q {}
3fc65ead
JD
771%%
772start: ;
773]])
6afc30cc 774AT_CHECK([[bison special-char-@@.y]], [0], [],
16dc6a9e
JD
775[[special-char-@@.y:1.7-9: warning: %code qualifier `bad' is not used
776special-char-@@.y:2.7: warning: %code qualifier `q' is not used
777special-char-@@.y:3.7: warning: %code qualifier `q' is not used
3fc65ead
JD
778]])
779
780AT_DATA([special-char-@:>@.y],
16dc6a9e
JD
781[[%code bad {}
782%code q {}
783%code q {}
3fc65ead
JD
784%%
785start: ;
786]])
6afc30cc 787AT_CHECK([[bison special-char-@:>@.y]], [0], [],
16dc6a9e
JD
788[[special-char-@:>@.y:1.7-9: warning: %code qualifier `bad' is not used
789special-char-@:>@.y:2.7: warning: %code qualifier `q' is not used
790special-char-@:>@.y:3.7: warning: %code qualifier `q' is not used
08af01c2 791]])
8e0a5e9e
JD
792
793AT_CLEANUP
7eb8a0bc
JD
794
795
796## ---------------- ##
797## %define errors. ##
798## ---------------- ##
799
800AT_SETUP([%define errors])
801
802AT_DATA([input.y],
16dc6a9e
JD
803[[%define var "value1"
804%define var "value1"
805 %define var "value2"
806%define special1 "@:>@"
807%define special2 "@<:@"
7eb8a0bc
JD
808%%
809start: ;
810]])
811
6afc30cc 812AT_CHECK([[bison input.y]], [0], [],
16dc6a9e 813[[input.y:2.9-11: warning: %define variable `var' redefined
9611cfa2 814input.y:1.9-11: warning: previous definition
16dc6a9e 815input.y:3.10-12: warning: %define variable `var' redefined
9611cfa2 816input.y:2.9-11: warning: previous definition
16dc6a9e
JD
817input.y:1.9-11: warning: %define variable `var' is not used
818input.y:2.9-11: warning: %define variable `var' is not used
819input.y:3.10-12: warning: %define variable `var' is not used
820input.y:4.9-16: warning: %define variable `special1' is not used
821input.y:5.9-16: warning: %define variable `special2' is not used
7eb8a0bc
JD
822]])
823
824AT_CLEANUP
c1d19e10
PB
825
826## --------------------------- ##
827## Boolean %define variables. ##
828## --------------------------- ##
829
830AT_SETUP([Boolean %define variables])
831
832AT_DATA([Input.y],
833[[%language "Java"
834%define public "maybe"
835%define parser_class_name "Input"
836%%
837start: ;
838]])
839
840AT_CHECK([[bison Input.y]], [1], [],
9611cfa2 841[[Input.y:2.9-14: invalid value for %define boolean variable `public'
c1d19e10
PB
842]])
843
844AT_CLEANUP