]>
Commit | Line | Data |
---|---|---|
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 | |
20 | AT_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 | 29 | AT_SETUP([Invalid $n and @n]) |
9b2d0677 AD |
30 | |
31 | AT_DATA([input.y], | |
32 | [[%% | |
bfcf1f3a | 33 | exp: { $$ = $1 ; }; |
bfcf1f3a | 34 | exp: { @$ = @1 ; }; |
9b2d0677 AD |
35 | ]]) |
36 | ||
37 | AT_CHECK([bison input.y], [1], [], | |
e9071366 AD |
38 | [[input.y:2.13-14: integer out of range: `$1' |
39 | input.y:3.13-14: integer out of range: `@1' | |
9b2d0677 AD |
40 | ]]) |
41 | ||
42 | AT_CLEANUP | |
9af3fbce AD |
43 | |
44 | ||
45 | ## -------------- ## | |
e776192e | 46 | ## Type Clashes. ## |
9af3fbce AD |
47 | ## -------------- ## |
48 | ||
e776192e | 49 | AT_SETUP([Type Clashes]) |
9af3fbce AD |
50 | |
51 | AT_DATA([input.y], | |
ffa4ba3a JD |
52 | [[%union { int bar; } |
53 | %token foo | |
9af3fbce AD |
54 | %type <bar> exp |
55 | %% | |
ffa4ba3a | 56 | exp: foo { $$; } foo { $2; } foo |
9af3fbce AD |
57 | | foo |
58 | | /* Empty. */ | |
59 | ; | |
60 | ]]) | |
61 | ||
ffa4ba3a JD |
62 | AT_CHECK([bison input.y], [1], [], |
63 | [[input.y:5.12-13: $$ for the midrule at $2 of `exp' has no declared type | |
64 | input.y:5.24-25: $2 of `exp' has no declared type | |
65 | input.y:5.6-32: warning: type clash on default action: <bar> != <> | |
66 | input.y:6.6-8: warning: type clash on default action: <bar> != <> | |
67 | input.y:7.5: warning: empty rule for typed nonterminal, and no action | |
9af3fbce AD |
68 | ]]) |
69 | ||
70 | AT_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 |
78 | m4_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 | |
94 | m4_define([AT_CHECK_UNUSED_VALUES], | |
95 | [AT_DATA([input.y], | |
96 | m4_ifval($1, [ | |
97 | ||
98 | ||
99 | ], [_AT_UNUSED_VALUES_DECLARATIONS | |
100 | ])[[%% | |
27622431 | 101 | start: |
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 | |
107 | a: INT | INT { } INT { } INT { }; | |
108 | b: INT | /* empty */; | |
519d0004 JD |
109 | c: INT | INT { $]1[ } INT { $<integer>2 } INT { $<integer>4 }; |
110 | d: INT | INT { } INT { $]1[ } INT { $<integer>2 }; | |
ffa4ba3a JD |
111 | e: INT | INT { } INT { } INT { $]1[ }; |
112 | f: INT | INT { } INT { } INT { $]$[ = $]1[ + $]3[ + $]5[; }; | |
ddc8ede1 PE |
113 | g: INT | INT { $<integer>$; } INT { $<integer>$; } INT { }; |
114 | h: INT | INT { $<integer>$; } INT { $<integer>$ = $<integer>2; } INT { }; | |
ffa4ba3a JD |
115 | i: INT | INT INT { } { $]$[ = $]1[ + $]2[; }; |
116 | j: INT | INT INT { $<integer>$ = 1; } { $]$[ = $]1[ + $]2[; }; | |
ddc8ede1 PE |
117 | k: INT | INT INT { $<integer>$; } { $<integer>$ = $<integer>3; } { }; |
118 | l: 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 | 122 | AT_CHECK([bison]m4_ifval($2, [ --warnings=midrule-values ])[ input.y], [0], [], |
ffa4ba3a JD |
123 | [[input.y:11.10-32: warning: unset value: $]$[ |
124 | input.y:11.10-32: warning: unused value: $]1[ | |
125 | input.y:11.10-32: warning: unused value: $]3[ | |
126 | input.y:11.10-32: warning: unused value: $]5[ | |
127 | input.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 | 129 | input.y:13.25-39: warning: unset value: $$ |
17bd8a73 | 130 | ]]])[[input.y:13.10-59: warning: unset value: $]$[ |
519d0004 JD |
131 | input.y:13.10-59: warning: unused value: $]3[ |
132 | input.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 |
135 | input.y:14.10-47: warning: unused value: $]3[ |
136 | input.y:14.10-47: warning: unused value: $]5[ | |
ffa4ba3a JD |
137 | input.y:15.10-36: warning: unset value: $]$[ |
138 | input.y:15.10-36: warning: unused value: $]3[ | |
139 | input.y:15.10-36: warning: unused value: $]5[ | |
ddc8ede1 PE |
140 | input.y:17.10-58: warning: unset value: $]$[ |
141 | input.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 |
146 | input.y:18.10-72: warning: unset value: $]$[ |
147 | input.y:18.10-72: warning: unused value: $]1[ | |
148 | input.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 |
153 | input.y:21.10-68: warning: unused value: $]1[ |
154 | input.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 | ||
163 | AT_SETUP([Unused values]) | |
164 | AT_CHECK_UNUSED_VALUES | |
17bd8a73 | 165 | AT_CHECK_UNUSED_VALUES(, [1]) |
ffa4ba3a JD |
166 | AT_CLEANUP |
167 | ||
168 | ||
169 | ## ------------------------------------------ ## | |
170 | ## Unused values before symbol declarations. ## | |
171 | ## ------------------------------------------ ## | |
84866159 | 172 | |
ffa4ba3a JD |
173 | AT_SETUP([Unused values before symbol declarations]) |
174 | AT_CHECK_UNUSED_VALUES([1]) | |
17bd8a73 | 175 | AT_CHECK_UNUSED_VALUES([1], [1]) |
84866159 | 176 | AT_CLEANUP |
378f4bd8 AD |
177 | |
178 | ||
ec5479ce JD |
179 | ## --------------------------------------------- ## |
180 | ## Default %printer and %destructor redeclared. ## | |
181 | ## --------------------------------------------- ## | |
182 | ||
183 | AT_SETUP([Default %printer and %destructor redeclared]) | |
184 | ||
185 | AT_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 | ||
200 | start: ; | |
201 | ||
12e35840 JD |
202 | %destructor { destroy ($$); } <*>; |
203 | %printer { destroy ($$); } <*>; | |
204 | ||
3ebecc24 JD |
205 | %destructor { destroy ($$); } <>; |
206 | %printer { destroy ($$); } <>; | |
ec5479ce JD |
207 | ]]) |
208 | ||
209 | AT_CHECK([bison input.y], [1], [], | |
12e35840 | 210 | [[input.y:1.13-29: redeclaration for default tagged %destructor |
b2a0b7ca | 211 | input.y:1.13-29: previous declaration |
12e35840 | 212 | input.y:2.10-26: redeclaration for default tagged %printer |
b2a0b7ca | 213 | input.y:2.10-26: previous declaration |
12e35840 | 214 | input.y:4.13-29: redeclaration for default tagged %destructor |
ec5479ce | 215 | input.y:1.13-29: previous declaration |
12e35840 | 216 | input.y:5.10-26: redeclaration for default tagged %printer |
ec5479ce | 217 | input.y:2.10-26: previous declaration |
12e35840 JD |
218 | input.y:7.13-29: redeclaration for default tagless %destructor |
219 | input.y:7.13-29: previous declaration | |
220 | input.y:8.10-26: redeclaration for default tagless %printer | |
221 | input.y:8.10-26: previous declaration | |
222 | input.y:10.13-29: redeclaration for default tagless %destructor | |
223 | input.y:7.13-29: previous declaration | |
224 | input.y:11.10-26: redeclaration for default tagless %printer | |
225 | input.y:8.10-26: previous declaration | |
226 | input.y:17.13-29: redeclaration for default tagged %destructor | |
ec5479ce | 227 | input.y:4.13-29: previous declaration |
12e35840 | 228 | input.y:18.10-26: redeclaration for default tagged %printer |
ec5479ce | 229 | input.y:5.10-26: previous declaration |
12e35840 JD |
230 | input.y:20.13-29: redeclaration for default tagless %destructor |
231 | input.y:10.13-29: previous declaration | |
232 | input.y:21.10-26: redeclaration for default tagless %printer | |
233 | input.y:11.10-26: previous declaration | |
ec5479ce JD |
234 | ]]) |
235 | ||
236 | AT_CLEANUP | |
237 | ||
238 | ||
b2a0b7ca JD |
239 | ## ---------------------------------------------- ## |
240 | ## Per-type %printer and %destructor redeclared. ## | |
241 | ## ---------------------------------------------- ## | |
242 | ||
243 | AT_SETUP([Per-type %printer and %destructor redeclared]) | |
244 | ||
245 | AT_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 | ||
254 | start: ; | |
255 | ||
256 | %destructor { destroy ($$); } <field2> <field1>; | |
257 | %printer { destroy ($$); } <field2> <field1>; | |
258 | ]]) | |
259 | ||
260 | AT_CHECK([bison input.y], [1], [], | |
261 | [[input.y:4.13-29: %destructor redeclaration for <field1> | |
262 | input.y:1.13-29: previous declaration | |
263 | input.y:4.13-29: %destructor redeclaration for <field1> | |
264 | input.y:4.13-29: previous declaration | |
265 | input.y:5.10-26: %printer redeclaration for <field2> | |
266 | input.y:2.10-26: previous declaration | |
267 | input.y:5.10-26: %printer redeclaration for <field2> | |
268 | input.y:5.10-26: previous declaration | |
269 | input.y:11.13-29: %destructor redeclaration for <field1> | |
270 | input.y:4.13-29: previous declaration | |
271 | input.y:11.13-29: %destructor redeclaration for <field2> | |
272 | input.y:1.13-29: previous declaration | |
273 | input.y:12.10-26: %printer redeclaration for <field1> | |
274 | input.y:2.10-26: previous declaration | |
275 | input.y:12.10-26: %printer redeclaration for <field2> | |
276 | input.y:5.10-26: previous declaration | |
277 | ]]) | |
278 | ||
279 | AT_CLEANUP | |
280 | ||
281 | ||
ec5479ce JD |
282 | ## ---------------------------------------- ## |
283 | ## Unused values with default %destructor. ## | |
284 | ## ---------------------------------------- ## | |
285 | ||
286 | AT_SETUP([Unused values with default %destructor]) | |
287 | ||
288 | AT_DATA([[input.y]], | |
3ebecc24 | 289 | [[%destructor { destroy ($$); } <> |
12e35840 JD |
290 | %type <tag> tagged |
291 | ||
292 | %% | |
293 | ||
294 | start: end end tagged tagged { $<tag>1; $3; } ; | |
295 | end: { } ; | |
296 | tagged: { } ; | |
297 | ]]) | |
298 | ||
299 | AT_CHECK([bison input.y], [0], [], | |
300 | [[input.y:6.8-45: warning: unset value: $$ | |
301 | input.y:6.8-45: warning: unused value: $2 | |
302 | input.y:7.6-8: warning: unset value: $$ | |
303 | ]]) | |
304 | ||
305 | AT_DATA([[input.y]], | |
306 | [[%destructor { destroy ($$); } <*> | |
307 | %type <tag> tagged | |
ec5479ce JD |
308 | |
309 | %% | |
310 | ||
12e35840 JD |
311 | start: end end tagged tagged { $<tag>1; $3; } ; |
312 | end: { } ; | |
313 | tagged: { } ; | |
ec5479ce JD |
314 | ]]) |
315 | ||
316 | AT_CHECK([bison input.y], [0], [], | |
12e35840 JD |
317 | [[input.y:6.8-45: warning: unused value: $4 |
318 | input.y:8.9-11: warning: unset value: $$ | |
ec5479ce JD |
319 | ]]) |
320 | ||
321 | AT_CLEANUP | |
322 | ||
323 | ||
b2a0b7ca JD |
324 | ## ----------------------------------------- ## |
325 | ## Unused values with per-type %destructor. ## | |
326 | ## ----------------------------------------- ## | |
327 | ||
328 | AT_SETUP([Unused values with per-type %destructor]) | |
329 | ||
330 | AT_DATA([[input.y]], | |
331 | [[%destructor { destroy ($$); } <field1> | |
332 | %type <field1> start end | |
333 | ||
334 | %% | |
335 | ||
336 | start: end end { $1; } ; | |
337 | end: { } ; | |
338 | ]]) | |
339 | ||
340 | AT_CHECK([bison input.y], [0], [], | |
341 | [[input.y:6.8-22: warning: unset value: $$ | |
342 | input.y:6.8-22: warning: unused value: $2 | |
343 | input.y:7.6-8: warning: unset value: $$ | |
344 | ]]) | |
345 | ||
346 | AT_CLEANUP | |
347 | ||
348 | ||
df09ef2e AD |
349 | ## ---------------------- ## |
350 | ## Incompatible Aliases. ## | |
351 | ## ---------------------- ## | |
352 | ||
353 | AT_SETUP([Incompatible Aliases]) | |
354 | ||
355 | AT_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 | %% | |
369 | exp: foo; | |
370 | ]]) | |
371 | ||
372 | AT_CHECK([bison input.y], [1], [], | |
373 | [[input.y:8.7-11: %type redeclaration for foo | |
dd60572a | 374 | input.y:3.7-11: previous declaration |
df09ef2e | 375 | input.y:10.13-17: %destructor redeclaration for foo |
dd60572a | 376 | input.y:5.13-17: previous declaration |
e2a8c0f5 | 377 | input.y:9.10-14: %printer redeclaration for foo |
dd60572a | 378 | input.y:4.10-14: previous declaration |
df09ef2e | 379 | input.y:11.1-5: %left redeclaration for foo |
dd60572a | 380 | input.y:6.1-5: previous declaration |
df09ef2e AD |
381 | ]]) |
382 | ||
383 | AT_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 | ||
394 | AT_SETUP([Torturing the Scanner]) | |
395 | ||
0baf7c50 PE |
396 | |
397 | AT_DATA([input.y], []) | |
398 | AT_CHECK([bison input.y], [1], [], | |
4a678af8 | 399 | [[input.y:1.1: syntax error, unexpected end of file |
0baf7c50 PE |
400 | ]]) |
401 | ||
402 | ||
e9071366 | 403 | AT_DATA([input.y], |
b2ddc3f3 AD |
404 | [{} |
405 | ]) | |
406 | AT_CHECK([bison input.y], [1], [], | |
4a678af8 | 407 | [[input.y:1.1-2: syntax error, unexpected {...} |
b2ddc3f3 AD |
408 | ]]) |
409 | ||
410 | ||
9501dc6e | 411 | AT_DATA_GRAMMAR([input.y], |
5a08f1ce AD |
412 | [[%{ |
413 | /* This is seen in GCC: a %{ and %} in middle of a comment. */ | |
414 | const 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 | |
437 | char str[] = "\\ | |
438 | " A string with backslash-newlines in it %{ %} \\ | |
dda7a53e | 439 | \ |
206fe6a5 PE |
440 | ""; |
441 | ||
dda7a53e | 442 | char 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 | 452 | typedef 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 | 466 | static YYSTYPE value_as_yystype (value val); |
5a08f1ce AD |
467 | |
468 | /* Exercise quotes in declarations. */ | |
469 | char quote[] = "@:>@@:>@,"; | |
470 | %} | |
471 | ||
472 | %{ | |
473 | static void yyerror (const char *s); | |
7172e23e | 474 | static 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 | 484 | exp: '@<:@' '\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 | |
492 | two: '\x000000000000000000000000000000000000000000000000000000000000000000002'; | |
493 | oline: '@' 'o' 'l' 'i' 'n' 'e' '@' '_' '_' 'o' 'l' 'i' 'n' 'e' '_' '_'; | |
087b9fdf | 494 | output.or.oline.opt: ;|oline;;|output;;; |
5b7f88c7 | 495 | output: '#' 'o' 'u' 't' 'p' 'u' 't' ' '; |
5a08f1ce | 496 | %% |
206fe6a5 | 497 | /* Exercise M4 quoting: '@:>@@:>@', @<:@, 2. */ |
5a08f1ce AD |
498 | |
499 | static YYSTYPE | |
051ade83 | 500 | value_as_yystype (value val) |
5a08f1ce AD |
501 | { |
502 | YYSTYPE res; | |
503 | res.ival = val; | |
504 | return res; | |
505 | } | |
506 | ||
7172e23e | 507 | static int |
5a08f1ce AD |
508 | yylex (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 | ||
520 | static void | |
521 | yyerror (const char *msg) | |
522 | { | |
523 | fprintf (stderr, "%s\n", msg); | |
524 | } | |
525 | ]]) | |
526 | ||
9501dc6e AD |
527 | # Pacify Emacs'font-lock-mode: " |
528 | ||
5a08f1ce | 529 | AT_DATA([main.c], |
051ade83 | 530 | [[typedef int value; |
5a08f1ce AD |
531 | #include "input.h" |
532 | ||
533 | int yyparse (void); | |
534 | ||
535 | int | |
536 | main (void) | |
537 | { | |
538 | return yyparse (); | |
539 | } | |
540 | ]]) | |
541 | ||
b56471a6 | 542 | AT_CHECK([bison -d -v -o input.c input.y]) |
efc6bf1b PE |
543 | AT_COMPILE([input.o], [-c input.c]) |
544 | AT_COMPILE([main.o], [-c main.c]) | |
545 | AT_COMPILE([input], [input.o main.o]) | |
1154cced | 546 | AT_PARSER_CHECK([./input], 0, |
206fe6a5 | 547 | [[[@<:@], |
5a08f1ce AD |
548 | ]]) |
549 | ||
550 | AT_CLEANUP | |
e59adf8f PE |
551 | |
552 | ||
553 | ## ---------------------- ## | |
554 | ## Typed symbol aliases. ## | |
555 | ## ---------------------- ## | |
556 | ||
557 | AT_SETUP([Typed symbol aliases]) | |
558 | ||
559 | # Bison 2.0 broke typed symbol aliases - ensure they work. | |
560 | ||
561 | AT_DATA_GRAMMAR([input.y], | |
562 | [[%union | |
563 | { | |
564 | int val; | |
565 | }; | |
566 | %token <val> MY_TOKEN "MY TOKEN" | |
567 | %type <val> exp | |
568 | %% | |
569 | exp: "MY TOKEN"; | |
570 | %% | |
571 | ]]) | |
572 | ||
573 | AT_CHECK([bison -o input.c input.y]) | |
574 | ||
575 | AT_CLEANUP | |
b50d2359 AD |
576 | |
577 | ||
578 | ## --------- ## | |
579 | ## Require. ## | |
580 | ## --------- ## | |
581 | ||
582 | m4_define([AT_CHECK_REQUIRE], | |
583 | [AT_SETUP([Require $1]) | |
584 | AT_DATA_GRAMMAR([input.y], | |
585 | [[%require "$1"; | |
586 | %% | |
587 | empty_file:; | |
588 | ]]) | |
589 | AT_CHECK([bison -o input.c input.y], $2, [], ignore) | |
590 | AT_CLEANUP | |
591 | ]) | |
592 | ||
593 | AT_CHECK_REQUIRE(1.0, 0) | |
594 | AT_CHECK_REQUIRE(AT_PACKAGE_VERSION, 0) | |
595 | ## FIXME: Some day augment this version number. | |
9b8a5ce0 | 596 | AT_CHECK_REQUIRE(100.0, 63) |
1f6b3679 JD |
597 | |
598 | ||
599 | ## ------------------------------------- ## | |
600 | ## String aliases for character tokens. ## | |
601 | ## ------------------------------------- ## | |
602 | ||
603 | AT_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 | ||
608 | AT_DATA_GRAMMAR([input.y], | |
609 | [[%token 'a' "a" | |
610 | %% | |
611 | start: 'a'; | |
612 | %% | |
613 | ]]) | |
614 | ||
615 | AT_CHECK([bison -o input.c input.y]) | |
616 | ||
617 | AT_CLEANUP | |
47aee066 JD |
618 | |
619 | ||
620 | ## --------------------- ## | |
621 | ## Unclosed constructs. ## | |
622 | ## --------------------- ## | |
623 | ||
624 | AT_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 | ||
631 | AT_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 | ||
641 | start: ; | |
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 | ||
653 | AT_CHECK([bison -o input.c input.y], 1, [], | |
654 | [[input.y:1.10-2.0: missing `"' at end of line | |
655 | input.y:4.10-5.0: missing `'' at end of line | |
656 | input.y:14.11-15.0: missing `'' at end of line | |
657 | input.y:16.11-17.0: missing `"' at end of line | |
658 | input.y:19.13-20.0: missing `}' at end of file | |
3be03b13 | 659 | input.y:20.1: syntax error, unexpected end of file |
47aee066 JD |
660 | ]]) |
661 | ||
662 | AT_CLEANUP | |
4d7370cb JD |
663 | |
664 | ||
665 | ## ------------------------- ## | |
666 | ## %start after first rule. ## | |
667 | ## ------------------------- ## | |
668 | ||
669 | AT_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 | ||
674 | AT_DATA([input.y], | |
675 | [[%% | |
676 | false_start: ; | |
677 | start: false_start ; | |
678 | %start start; | |
679 | ]]) | |
680 | ||
681 | AT_CHECK([bison -o input.c input.y]) | |
682 | ||
683 | AT_CLEANUP | |
26b8a438 JD |
684 | |
685 | ||
686 | ## --------------------- ## | |
687 | ## %prec takes a token. ## | |
688 | ## --------------------- ## | |
689 | ||
690 | AT_SETUP([%prec takes a token]) | |
691 | ||
692 | # Bison once allowed %prec sym where sym was a nonterminal. | |
693 | ||
694 | AT_DATA([input.y], | |
695 | [[%% | |
696 | start: PREC %prec PREC ; | |
697 | PREC: ; | |
698 | ]]) | |
699 | ||
700 | AT_CHECK([bison input.y], [1], [], | |
701 | [[input.y:3.1-4: rule given for PREC, which is a token | |
702 | ]]) | |
703 | ||
704 | AT_CLEANUP | |
8e0a5e9e JD |
705 | |
706 | ||
6afc30cc JD |
707 | ## -------------------------------- ## |
708 | ## Reject unused %code qualifiers. ## | |
709 | ## -------------------------------- ## | |
8e0a5e9e | 710 | |
6afc30cc | 711 | AT_SETUP([Reject unused %code qualifiers]) |
8e0a5e9e JD |
712 | |
713 | AT_DATA([input-c.y], | |
16dc6a9e JD |
714 | [[%code q {} |
715 | %code bad {} | |
716 | %code bad {} | |
8405b70c | 717 | %code format {} |
8e0a5e9e JD |
718 | %% |
719 | start: ; | |
720 | ]]) | |
6afc30cc | 721 | AT_CHECK([[bison input-c.y]], [0], [], |
16dc6a9e JD |
722 | [[input-c.y:1.7: warning: %code qualifier `q' is not used |
723 | input-c.y:2.7-9: warning: %code qualifier `bad' is not used | |
724 | input-c.y:3.7-9: warning: %code qualifier `bad' is not used | |
8405b70c | 725 | input-c.y:4.7-12: warning: %code qualifier `format' is not used |
08af01c2 | 726 | ]]) |
8e0a5e9e JD |
727 | |
728 | AT_DATA([input-c-glr.y], | |
16dc6a9e JD |
729 | [[%code q {} |
730 | %code bad {} | |
731 | %code bad {} | |
8e0a5e9e JD |
732 | %% |
733 | start: ; | |
734 | ]]) | |
6afc30cc | 735 | AT_CHECK([[bison input-c-glr.y]], [0], [], |
16dc6a9e JD |
736 | [[input-c-glr.y:1.7: warning: %code qualifier `q' is not used |
737 | input-c-glr.y:2.7-9: warning: %code qualifier `bad' is not used | |
738 | input-c-glr.y:3.8-10: warning: %code qualifier `bad' is not used | |
08af01c2 | 739 | ]]) |
8e0a5e9e JD |
740 | |
741 | AT_DATA([input-c++.y], | |
16dc6a9e JD |
742 | [[%code q {} |
743 | %code bad {} | |
744 | %code q {} | |
8e0a5e9e JD |
745 | %% |
746 | start: ; | |
747 | ]]) | |
6afc30cc | 748 | AT_CHECK([[bison input-c++.y]], [0], [], |
16dc6a9e JD |
749 | [[input-c++.y:1.7: warning: %code qualifier `q' is not used |
750 | input-c++.y:2.7-9: warning: %code qualifier `bad' is not used | |
751 | input-c++.y:3.8: warning: %code qualifier `q' is not used | |
08af01c2 | 752 | ]]) |
8e0a5e9e JD |
753 | |
754 | AT_DATA([input-c++-glr.y], | |
16dc6a9e JD |
755 | [[%code bad {} |
756 | %code q {} | |
757 | %code q {} | |
8e0a5e9e JD |
758 | %% |
759 | start: ; | |
760 | ]]) | |
6afc30cc | 761 | AT_CHECK([[bison input-c++-glr.y]], [0], [], |
16dc6a9e JD |
762 | [[input-c++-glr.y:1.7-9: warning: %code qualifier `bad' is not used |
763 | input-c++-glr.y:2.7: warning: %code qualifier `q' is not used | |
764 | input-c++-glr.y:3.7: warning: %code qualifier `q' is not used | |
3fc65ead JD |
765 | ]]) |
766 | ||
767 | AT_DATA([special-char-@@.y], | |
16dc6a9e JD |
768 | [[%code bad {} |
769 | %code q {} | |
770 | %code q {} | |
3fc65ead JD |
771 | %% |
772 | start: ; | |
773 | ]]) | |
6afc30cc | 774 | AT_CHECK([[bison special-char-@@.y]], [0], [], |
16dc6a9e JD |
775 | [[special-char-@@.y:1.7-9: warning: %code qualifier `bad' is not used |
776 | special-char-@@.y:2.7: warning: %code qualifier `q' is not used | |
777 | special-char-@@.y:3.7: warning: %code qualifier `q' is not used | |
3fc65ead JD |
778 | ]]) |
779 | ||
780 | AT_DATA([special-char-@:>@.y], | |
16dc6a9e JD |
781 | [[%code bad {} |
782 | %code q {} | |
783 | %code q {} | |
3fc65ead JD |
784 | %% |
785 | start: ; | |
786 | ]]) | |
6afc30cc | 787 | AT_CHECK([[bison special-char-@:>@.y]], [0], [], |
16dc6a9e JD |
788 | [[special-char-@:>@.y:1.7-9: warning: %code qualifier `bad' is not used |
789 | special-char-@:>@.y:2.7: warning: %code qualifier `q' is not used | |
790 | special-char-@:>@.y:3.7: warning: %code qualifier `q' is not used | |
08af01c2 | 791 | ]]) |
8e0a5e9e JD |
792 | |
793 | AT_CLEANUP | |
7eb8a0bc JD |
794 | |
795 | ||
796 | ## ---------------- ## | |
797 | ## %define errors. ## | |
798 | ## ---------------- ## | |
799 | ||
800 | AT_SETUP([%define errors]) | |
801 | ||
802 | AT_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 | %% |
809 | start: ; | |
810 | ]]) | |
811 | ||
6afc30cc | 812 | AT_CHECK([[bison input.y]], [0], [], |
16dc6a9e | 813 | [[input.y:2.9-11: warning: %define variable `var' redefined |
9611cfa2 | 814 | input.y:1.9-11: warning: previous definition |
16dc6a9e | 815 | input.y:3.10-12: warning: %define variable `var' redefined |
9611cfa2 | 816 | input.y:2.9-11: warning: previous definition |
16dc6a9e JD |
817 | input.y:1.9-11: warning: %define variable `var' is not used |
818 | input.y:2.9-11: warning: %define variable `var' is not used | |
819 | input.y:3.10-12: warning: %define variable `var' is not used | |
820 | input.y:4.9-16: warning: %define variable `special1' is not used | |
821 | input.y:5.9-16: warning: %define variable `special2' is not used | |
7eb8a0bc JD |
822 | ]]) |
823 | ||
824 | AT_CLEANUP | |
c1d19e10 PB |
825 | |
826 | ## --------------------------- ## | |
827 | ## Boolean %define variables. ## | |
828 | ## --------------------------- ## | |
829 | ||
830 | AT_SETUP([Boolean %define variables]) | |
831 | ||
832 | AT_DATA([Input.y], | |
833 | [[%language "Java" | |
834 | %define public "maybe" | |
835 | %define parser_class_name "Input" | |
836 | %% | |
837 | start: ; | |
838 | ]]) | |
839 | ||
840 | AT_CHECK([[bison Input.y]], [1], [], | |
9611cfa2 | 841 | [[Input.y:2.9-14: invalid value for %define boolean variable `public' |
c1d19e10 PB |
842 | ]]) |
843 | ||
844 | AT_CLEANUP |