]>
Commit | Line | Data |
---|---|---|
342b8b6e | 1 | # Bison Regressions. -*- Autotest -*- |
4f136612 | 2 | # Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. |
c95f2d78 | 3 | |
342b8b6e AD |
4 | # This program is free software; you can redistribute it and/or modify |
5 | # it under the terms of the GNU General Public License as published by | |
6 | # the Free Software Foundation; either version 2, or (at your option) | |
7 | # any later version. | |
c95f2d78 | 8 | |
342b8b6e AD |
9 | # This program is distributed in the hope that it will be useful, |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. | |
c95f2d78 | 13 | |
342b8b6e AD |
14 | # You should have received a copy of the GNU General Public License |
15 | # along with this program; if not, write to the Free Software | |
0fb669f9 PE |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | # 02110-1301, USA. | |
c95f2d78 | 18 | |
342b8b6e | 19 | AT_BANNER([[Regression tests.]]) |
c95f2d78 | 20 | |
2b25d624 | 21 | |
69078d4b AD |
22 | ## ------------------------- ## |
23 | ## Early token definitions. ## | |
24 | ## ------------------------- ## | |
25 | ||
26 | ||
27 | AT_SETUP([Early token definitions]) | |
28 | ||
29 | # Found in GCJ: they expect the tokens to be defined before the user | |
30 | # prologue, so that they can use the token definitions in it. | |
31 | ||
9501dc6e | 32 | AT_DATA_GRAMMAR([input.y], |
69078d4b AD |
33 | [[%{ |
34 | void yyerror (const char *s); | |
35 | int yylex (void); | |
36 | %} | |
37 | ||
38 | %union | |
39 | { | |
40 | int val; | |
41 | }; | |
42 | %{ | |
43 | #ifndef MY_TOKEN | |
44 | # error "MY_TOKEN not defined." | |
45 | #endif | |
46 | %} | |
47 | %token MY_TOKEN | |
48 | %% | |
49 | exp: MY_TOKEN; | |
50 | %% | |
51 | ]]) | |
52 | ||
b56471a6 | 53 | AT_CHECK([bison -o input.c input.y]) |
002b9b7d | 54 | AT_COMPILE([input.o], [-c input.c]) |
69078d4b AD |
55 | |
56 | AT_CLEANUP | |
57 | ||
58 | ||
59 | ||
2b25d624 AD |
60 | ## ---------------- ## |
61 | ## Braces parsing. ## | |
62 | ## ---------------- ## | |
63 | ||
64 | ||
69078d4b | 65 | AT_SETUP([Braces parsing]) |
2b25d624 AD |
66 | |
67 | AT_DATA([input.y], | |
68 | [[/* Bison used to swallow the character after `}'. */ | |
69 | ||
70 | %% | |
bfcf1f3a | 71 | exp: { tests = {{{{{{{{{{}}}}}}}}}}; }; |
2b25d624 AD |
72 | %% |
73 | ]]) | |
74 | ||
b56471a6 | 75 | AT_CHECK([bison -v -o input.c input.y]) |
2b25d624 | 76 | |
a4bf0390 | 77 | AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore]) |
2b25d624 AD |
78 | |
79 | AT_CLEANUP | |
80 | ||
81 | ||
c95f2d78 AD |
82 | ## ------------------ ## |
83 | ## Duplicate string. ## | |
84 | ## ------------------ ## | |
85 | ||
86 | ||
87 | AT_SETUP([Duplicate string]) | |
88 | ||
f499b062 | 89 | AT_DATA([input.y], |
c95f2d78 AD |
90 | [[/* `Bison -v' used to dump core when two tokens are defined with the same |
91 | string, as LE and GE below. */ | |
92 | ||
93 | %token NUM | |
94 | %token LE "<=" | |
95 | %token GE "<=" | |
96 | ||
97 | %% | |
98 | exp: '(' exp ')' | NUM ; | |
99 | %% | |
100 | ]]) | |
101 | ||
b56471a6 | 102 | AT_CHECK([bison -v -o input.c input.y], 0, [], |
a5d50994 | 103 | [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string |
69078d4b | 104 | ]]) |
c95f2d78 | 105 | |
d803322e | 106 | AT_CLEANUP |
c95f2d78 AD |
107 | |
108 | ||
2ca209c1 AD |
109 | ## ------------------- ## |
110 | ## Rule Line Numbers. ## | |
111 | ## ------------------- ## | |
112 | ||
113 | AT_SETUP([Rule Line Numbers]) | |
114 | ||
6b98e4b5 AD |
115 | AT_KEYWORDS([report]) |
116 | ||
2ca209c1 AD |
117 | AT_DATA([input.y], |
118 | [[%% | |
119 | expr: | |
120 | 'a' | |
121 | ||
122 | { | |
123 | ||
124 | } | |
125 | ||
126 | 'b' | |
127 | ||
128 | { | |
129 | ||
130 | } | |
131 | ||
132 | | | |
133 | ||
134 | ||
135 | { | |
136 | ||
137 | ||
138 | } | |
139 | ||
140 | 'c' | |
141 | ||
142 | { | |
143 | ||
bfcf1f3a | 144 | }; |
2ca209c1 AD |
145 | ]]) |
146 | ||
b56471a6 | 147 | AT_CHECK([bison -o input.c -v input.y]) |
2ca209c1 AD |
148 | |
149 | # Check the contents of the report. | |
150 | AT_CHECK([cat input.output], [], | |
d2d1b42b | 151 | [[Grammar |
2ca209c1 | 152 | |
88bce5a2 | 153 | 0 $accept: expr $end |
6b98e4b5 AD |
154 | |
155 | 1 @1: /* empty */ | |
156 | ||
157 | 2 expr: 'a' @1 'b' | |
158 | ||
159 | 3 @2: /* empty */ | |
160 | ||
161 | 4 expr: @2 'c' | |
2ca209c1 | 162 | |
d2d1b42b | 163 | |
2ca209c1 AD |
164 | Terminals, with rules where they appear |
165 | ||
88bce5a2 | 166 | $end (0) 0 |
2ca209c1 AD |
167 | 'a' (97) 2 |
168 | 'b' (98) 2 | |
169 | 'c' (99) 4 | |
170 | error (256) | |
171 | ||
d2d1b42b | 172 | |
2ca209c1 AD |
173 | Nonterminals, with rules where they appear |
174 | ||
88bce5a2 | 175 | $accept (6) |
b365aa05 AD |
176 | on left: 0 |
177 | expr (7) | |
178 | on left: 2 4, on right: 0 | |
179 | @1 (8) | |
2ca209c1 | 180 | on left: 1, on right: 2 |
b365aa05 | 181 | @2 (9) |
2ca209c1 AD |
182 | on left: 3, on right: 4 |
183 | ||
184 | ||
185 | state 0 | |
186 | ||
88bce5a2 | 187 | 0 $accept: . expr $end |
643a5994 | 188 | |
87675353 | 189 | 'a' shift, and go to state 1 |
2ca209c1 | 190 | |
87675353 | 191 | $default reduce using rule 3 (@2) |
2ca209c1 | 192 | |
87675353 AD |
193 | expr go to state 2 |
194 | @2 go to state 3 | |
2ca209c1 AD |
195 | |
196 | ||
197 | state 1 | |
198 | ||
ce4ccb4b | 199 | 2 expr: 'a' . @1 'b' |
2ca209c1 | 200 | |
87675353 | 201 | $default reduce using rule 1 (@1) |
2ca209c1 | 202 | |
87675353 | 203 | @1 go to state 4 |
2ca209c1 AD |
204 | |
205 | ||
206 | state 2 | |
207 | ||
88bce5a2 | 208 | 0 $accept: expr . $end |
2ca209c1 | 209 | |
88bce5a2 | 210 | $end shift, and go to state 5 |
2ca209c1 AD |
211 | |
212 | ||
213 | state 3 | |
214 | ||
ce4ccb4b | 215 | 4 expr: @2 . 'c' |
2ca209c1 | 216 | |
87675353 | 217 | 'c' shift, and go to state 6 |
2ca209c1 AD |
218 | |
219 | ||
220 | state 4 | |
221 | ||
ce4ccb4b | 222 | 2 expr: 'a' @1 . 'b' |
2ca209c1 | 223 | |
87675353 | 224 | 'b' shift, and go to state 7 |
2ca209c1 AD |
225 | |
226 | ||
227 | state 5 | |
228 | ||
88bce5a2 | 229 | 0 $accept: expr $end . |
2ca209c1 | 230 | |
e8832397 | 231 | $default accept |
2ca209c1 AD |
232 | |
233 | ||
234 | state 6 | |
235 | ||
ce4ccb4b | 236 | 4 expr: @2 'c' . |
b365aa05 | 237 | |
87675353 | 238 | $default reduce using rule 4 (expr) |
2ca209c1 AD |
239 | |
240 | ||
241 | state 7 | |
242 | ||
ce4ccb4b | 243 | 2 expr: 'a' @1 'b' . |
b365aa05 | 244 | |
87675353 | 245 | $default reduce using rule 2 (expr) |
2ca209c1 AD |
246 | ]]) |
247 | ||
248 | AT_CLEANUP | |
249 | ||
250 | ||
251 | ||
cd5aafcf AD |
252 | ## ---------------------- ## |
253 | ## Mixing %token styles. ## | |
254 | ## ---------------------- ## | |
255 | ||
256 | ||
257 | AT_SETUP([Mixing %token styles]) | |
258 | ||
259 | # Taken from the documentation. | |
260 | AT_DATA([input.y], | |
261 | [[%token <operator> OR "||" | |
262 | %token <operator> LE 134 "<=" | |
263 | %left OR "<=" | |
264 | %% | |
265 | exp: ; | |
266 | %% | |
267 | ]]) | |
268 | ||
b56471a6 | 269 | AT_CHECK([bison -v -o input.c input.y]) |
cd5aafcf | 270 | |
d803322e | 271 | AT_CLEANUP |
cd5aafcf AD |
272 | |
273 | ||
274 | ||
29ae55f1 AD |
275 | ## ---------------- ## |
276 | ## Invalid inputs. ## | |
277 | ## ---------------- ## | |
561f9a30 AD |
278 | |
279 | ||
29ae55f1 | 280 | AT_SETUP([Invalid inputs]) |
561f9a30 AD |
281 | |
282 | AT_DATA([input.y], | |
283 | [[%% | |
284 | ? | |
561f9a30 | 285 | default: 'a' } |
29ae55f1 | 286 | %& |
2dfbfc12 | 287 | %a-does-not-exist |
29ae55f1 | 288 | %- |
e9955c83 | 289 | %{ |
561f9a30 AD |
290 | ]]) |
291 | ||
292 | AT_CHECK([bison input.y], [1], [], | |
e9955c83 AD |
293 | [[input.y:2.1: invalid character: `?' |
294 | input.y:3.14: invalid character: `}' | |
295 | input.y:4.1: invalid character: `%' | |
296 | input.y:4.2: invalid character: `&' | |
2dfbfc12 | 297 | input.y:5.1-17: invalid directive: `%a-does-not-exist' |
e9955c83 AD |
298 | input.y:6.1: invalid character: `%' |
299 | input.y:6.2: invalid character: `-' | |
2115939b | 300 | input.y:7.1-8.0: missing `%}' at end of file |
e0c40012 | 301 | ]]) |
561f9a30 AD |
302 | |
303 | AT_CLEANUP | |
304 | ||
305 | ||
fc01665e PE |
306 | AT_SETUP([Invalid inputs with {}]) |
307 | ||
308 | AT_DATA([input.y], | |
309 | [[ | |
310 | %destructor | |
311 | %initial-action | |
312 | %lex-param | |
313 | %parse-param | |
314 | %printer | |
315 | %union | |
316 | ]]) | |
317 | ||
318 | AT_CHECK([bison input.y], [1], [], | |
319 | [[input.y:3.1: missing `{' in "%destructor {...}" | |
320 | input.y:4.1: missing `{' in "%initial-action {...}" | |
321 | input.y:4.1: syntax error, unexpected %initial-action {...}, expecting string or identifier | |
322 | ]]) | |
323 | ||
324 | AT_CLEANUP | |
325 | ||
326 | ||
270a173c | 327 | |
b87f8b21 AD |
328 | ## ------------------- ## |
329 | ## Token definitions. ## | |
330 | ## ------------------- ## | |
331 | ||
332 | ||
333 | AT_SETUP([Token definitions]) | |
334 | ||
335 | # Bison managed, when fed with `%token 'f' "f"' to #define 'f'! | |
9501dc6e | 336 | AT_DATA_GRAMMAR([input.y], |
db7c8e9a | 337 | [%{ |
ca407bdf | 338 | #include <stdio.h> |
db7c8e9a AD |
339 | void yyerror (const char *s); |
340 | int yylex (void); | |
341 | %} | |
ca407bdf PE |
342 | [%error-verbose |
343 | %token MYEOF 0 "end of file" | |
b87f8b21 | 344 | %token 'a' "a" |
4f136612 PE |
345 | %token B_TOKEN "b" |
346 | %token C_TOKEN 'c' | |
347 | %token 'd' D_TOKEN | |
9e0876fb | 348 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\377\x001\x0000ff??!" |
b87f8b21 | 349 | %% |
9e0876fb | 350 | exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\377\x001\x0000ff??!"; |
ca407bdf PE |
351 | %% |
352 | void | |
353 | yyerror (char const *s) | |
354 | { | |
355 | fprintf (stderr, "%s\n", s); | |
356 | } | |
357 | ||
358 | int | |
359 | yylex (void) | |
360 | { | |
361 | return SPECIAL; | |
362 | } | |
363 | ||
364 | int | |
365 | main (void) | |
366 | { | |
367 | return yyparse (); | |
368 | } | |
b87f8b21 AD |
369 | ]]) |
370 | ||
b56471a6 | 371 | AT_CHECK([bison -o input.c input.y]) |
ca407bdf PE |
372 | AT_COMPILE([input]) |
373 | AT_PARSER_CHECK([./input], 1, [], | |
9e0876fb | 374 | [syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\377\001\377?\?!", expecting a |
ca407bdf | 375 | ]) |
b87f8b21 AD |
376 | AT_CLEANUP |
377 | ||
378 | ||
379 | ||
eb714592 AD |
380 | ## -------------------- ## |
381 | ## Characters Escapes. ## | |
382 | ## -------------------- ## | |
383 | ||
384 | ||
385 | AT_SETUP([Characters Escapes]) | |
386 | ||
9501dc6e | 387 | AT_DATA_GRAMMAR([input.y], |
eb714592 AD |
388 | [%{ |
389 | void yyerror (const char *s); | |
390 | int yylex (void); | |
391 | %} | |
392 | [%% | |
393 | exp: | |
394 | '\'' "\'" | |
395 | | '\"' "\"" | |
396 | | '"' "'" | |
397 | ; | |
398 | ]]) | |
9501dc6e | 399 | # Pacify font-lock-mode: " |
eb714592 | 400 | |
b56471a6 | 401 | AT_CHECK([bison -o input.c input.y]) |
eb714592 AD |
402 | AT_COMPILE([input.o], [-c input.c]) |
403 | AT_CLEANUP | |
404 | ||
405 | ||
406 | ||
b9752825 AD |
407 | ## -------------- ## |
408 | ## Web2c Report. ## | |
409 | ## -------------- ## | |
776209d6 AD |
410 | |
411 | # The generation of the reduction was once wrong in Bison, and made it | |
412 | # miss some reductions. In the following test case, the reduction on | |
413 | # `undef_id_tok' in state 1 was missing. This is stripped down from | |
414 | # the actual web2c.y. | |
415 | ||
b9752825 | 416 | AT_SETUP([Web2c Report]) |
776209d6 | 417 | |
6b98e4b5 AD |
418 | AT_KEYWORDS([report]) |
419 | ||
776209d6 AD |
420 | AT_DATA([input.y], |
421 | [[%token undef_id_tok const_id_tok | |
422 | ||
423 | %start CONST_DEC_PART | |
424 | \f | |
425 | %% | |
426 | CONST_DEC_PART: | |
427 | CONST_DEC_LIST | |
428 | ; | |
429 | ||
430 | CONST_DEC_LIST: | |
431 | CONST_DEC | |
432 | | CONST_DEC_LIST CONST_DEC | |
433 | ; | |
434 | ||
435 | CONST_DEC: | |
436 | { } undef_id_tok '=' const_id_tok ';' | |
437 | ; | |
438 | %% | |
776209d6 AD |
439 | ]]) |
440 | ||
441 | AT_CHECK([bison -v input.y]) | |
87675353 | 442 | AT_CHECK([cat input.output], 0, |
776209d6 | 443 | [[Grammar |
87675353 | 444 | |
88bce5a2 | 445 | 0 $accept: CONST_DEC_PART $end |
87675353 | 446 | |
6b98e4b5 | 447 | 1 CONST_DEC_PART: CONST_DEC_LIST |
87675353 | 448 | |
6b98e4b5 AD |
449 | 2 CONST_DEC_LIST: CONST_DEC |
450 | 3 | CONST_DEC_LIST CONST_DEC | |
87675353 | 451 | |
6b98e4b5 | 452 | 4 @1: /* empty */ |
87675353 | 453 | |
6b98e4b5 | 454 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' |
87675353 AD |
455 | |
456 | ||
776209d6 | 457 | Terminals, with rules where they appear |
87675353 | 458 | |
88bce5a2 | 459 | $end (0) 0 |
776209d6 AD |
460 | ';' (59) 5 |
461 | '=' (61) 5 | |
462 | error (256) | |
007a50a4 AD |
463 | undef_id_tok (258) 5 |
464 | const_id_tok (259) 5 | |
87675353 AD |
465 | |
466 | ||
776209d6 | 467 | Nonterminals, with rules where they appear |
87675353 | 468 | |
88bce5a2 | 469 | $accept (7) |
78d5bae9 AD |
470 | on left: 0 |
471 | CONST_DEC_PART (8) | |
472 | on left: 1, on right: 0 | |
473 | CONST_DEC_LIST (9) | |
776209d6 | 474 | on left: 2 3, on right: 1 3 |
78d5bae9 | 475 | CONST_DEC (10) |
776209d6 | 476 | on left: 5, on right: 2 3 |
78d5bae9 | 477 | @1 (11) |
776209d6 | 478 | on left: 4, on right: 5 |
87675353 AD |
479 | |
480 | ||
776209d6 | 481 | state 0 |
87675353 | 482 | |
88bce5a2 | 483 | 0 $accept: . CONST_DEC_PART $end |
87675353 AD |
484 | |
485 | $default reduce using rule 4 (@1) | |
486 | ||
487 | CONST_DEC_PART go to state 1 | |
488 | CONST_DEC_LIST go to state 2 | |
489 | CONST_DEC go to state 3 | |
490 | @1 go to state 4 | |
491 | ||
492 | ||
776209d6 | 493 | state 1 |
87675353 | 494 | |
88bce5a2 | 495 | 0 $accept: CONST_DEC_PART . $end |
87675353 | 496 | |
88bce5a2 | 497 | $end shift, and go to state 5 |
87675353 AD |
498 | |
499 | ||
78d5bae9 | 500 | state 2 |
87675353 | 501 | |
ce4ccb4b AD |
502 | 1 CONST_DEC_PART: CONST_DEC_LIST . |
503 | 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC | |
87675353 AD |
504 | |
505 | undef_id_tok reduce using rule 4 (@1) | |
506 | $default reduce using rule 1 (CONST_DEC_PART) | |
507 | ||
508 | CONST_DEC go to state 6 | |
509 | @1 go to state 4 | |
510 | ||
511 | ||
78d5bae9 | 512 | state 3 |
87675353 | 513 | |
ce4ccb4b | 514 | 2 CONST_DEC_LIST: CONST_DEC . |
87675353 AD |
515 | |
516 | $default reduce using rule 2 (CONST_DEC_LIST) | |
517 | ||
518 | ||
776209d6 | 519 | state 4 |
87675353 | 520 | |
ce4ccb4b | 521 | 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';' |
87675353 AD |
522 | |
523 | undef_id_tok shift, and go to state 7 | |
524 | ||
525 | ||
78d5bae9 | 526 | state 5 |
87675353 | 527 | |
88bce5a2 | 528 | 0 $accept: CONST_DEC_PART $end . |
87675353 | 529 | |
e8832397 | 530 | $default accept |
87675353 AD |
531 | |
532 | ||
78d5bae9 | 533 | state 6 |
87675353 | 534 | |
ce4ccb4b | 535 | 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC . |
87675353 AD |
536 | |
537 | $default reduce using rule 3 (CONST_DEC_LIST) | |
538 | ||
539 | ||
78d5bae9 | 540 | state 7 |
87675353 | 541 | |
ce4ccb4b | 542 | 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';' |
87675353 AD |
543 | |
544 | '=' shift, and go to state 8 | |
545 | ||
546 | ||
78d5bae9 | 547 | state 8 |
87675353 | 548 | |
ce4ccb4b | 549 | 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';' |
87675353 AD |
550 | |
551 | const_id_tok shift, and go to state 9 | |
552 | ||
553 | ||
78d5bae9 | 554 | state 9 |
87675353 | 555 | |
ce4ccb4b | 556 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';' |
87675353 AD |
557 | |
558 | ';' shift, and go to state 10 | |
559 | ||
560 | ||
78d5bae9 | 561 | state 10 |
87675353 | 562 | |
ce4ccb4b | 563 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' . |
87675353 AD |
564 | |
565 | $default reduce using rule 5 (CONST_DEC) | |
776209d6 AD |
566 | ]]) |
567 | ||
568 | AT_CLEANUP | |
b9752825 AD |
569 | |
570 | ||
571 | ## --------------- ## | |
572 | ## Web2c Actions. ## | |
573 | ## --------------- ## | |
574 | ||
575 | # The generation of the mapping `state -> action' was once wrong in | |
576 | # extremely specific situations. web2c.y exhibits this situation. | |
577 | # Below is a stripped version of the grammar. It looks like one can | |
578 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
579 | # which disapears when applying sane grammar transformations. | |
580 | # | |
581 | # It used to be wrong on yydefact only: | |
582 | # | |
779e7ceb | 583 | # static const short int yydefact[] = |
b9752825 AD |
584 | # { |
585 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
586 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
587 | # 0, 0 | |
588 | # }; | |
589 | # | |
590 | # but let's check all the tables. | |
591 | ||
592 | ||
593 | AT_SETUP([Web2c Actions]) | |
594 | ||
6b98e4b5 AD |
595 | AT_KEYWORDS([report]) |
596 | ||
b9752825 AD |
597 | AT_DATA([input.y], |
598 | [[%% | |
599 | statement: struct_stat; | |
600 | struct_stat: /* empty. */ | if else; | |
601 | if: "if" "const" "then" statement; | |
602 | else: "else" statement; | |
603 | %% | |
604 | ]]) | |
605 | ||
b56471a6 | 606 | AT_CHECK([bison -v -o input.c input.y]) |
b9752825 AD |
607 | |
608 | # Check only the tables. We don't use --no-parser, because it is | |
609 | # still to be implemented in the experimental branch of Bison. | |
ce4ccb4b AD |
610 | [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] |
611 | ||
612 | AT_CHECK([[cat tables.c]], 0, | |
c0c9ea05 | 613 | [[static const unsigned char yytranslate[] = |
b9752825 AD |
614 | { |
615 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
616 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
617 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
618 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
619 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
620 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
621 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
622 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
623 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
624 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
625 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
626 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
627 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
628 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
629 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
630 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
631 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
632 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
633 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
634 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
635 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
636 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
637 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
638 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
639 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
007a50a4 AD |
640 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
641 | 5, 6 | |
b9752825 | 642 | }; |
5df5f6d5 | 643 | static const unsigned char yyprhs[] = |
b9752825 | 644 | { |
e7b8bef1 | 645 | 0, 0, 3, 5, 6, 9, 14 |
b9752825 | 646 | }; |
7c78fa18 | 647 | static const yysigned_char yyrhs[] = |
b9752825 | 648 | { |
e7b8bef1 AD |
649 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, |
650 | 4, 5, 8, -1, 6, 8, -1 | |
b9752825 | 651 | }; |
5df5f6d5 | 652 | static const unsigned char yyrline[] = |
b9752825 | 653 | { |
e7b8bef1 | 654 | 0, 2, 2, 3, 3, 4, 5 |
b9752825 AD |
655 | }; |
656 | static const char *const yytname[] = | |
657 | { | |
9e0876fb PE |
658 | "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"", |
659 | "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0 | |
b9752825 | 660 | }; |
779e7ceb | 661 | static const unsigned short int yytoknum[] = |
b9752825 | 662 | { |
3650b4b8 | 663 | 0, 256, 257, 258, 259, 260, 261 |
b9752825 | 664 | }; |
c0c9ea05 | 665 | static const unsigned char yyr1[] = |
b9752825 | 666 | { |
e7b8bef1 | 667 | 0, 7, 8, 9, 9, 10, 11 |
b9752825 | 668 | }; |
5df5f6d5 | 669 | static const unsigned char yyr2[] = |
b9752825 | 670 | { |
e7b8bef1 | 671 | 0, 2, 1, 0, 2, 4, 2 |
b9752825 | 672 | }; |
a762e609 | 673 | static const unsigned char yydefact[] = |
b9752825 | 674 | { |
e8832397 | 675 | 3, 0, 0, 2, 0, 0, 1, 3, 4, 3, |
e7b8bef1 | 676 | 6, 5 |
b9752825 | 677 | }; |
7c78fa18 | 678 | static const yysigned_char yydefgoto[] = |
b9752825 | 679 | { |
e7b8bef1 | 680 | -1, 2, 3, 4, 8 |
b9752825 | 681 | }; |
7c78fa18 | 682 | static const yysigned_char yypact[] = |
b9752825 | 683 | { |
12b0043a AD |
684 | -2, -1, 4, -8, 0, 2, -8, -2, -8, -2, |
685 | -8, -8 | |
b9752825 | 686 | }; |
7c78fa18 | 687 | static const yysigned_char yypgoto[] = |
b9752825 | 688 | { |
12b0043a | 689 | -8, -7, -8, -8, -8 |
b9752825 | 690 | }; |
a762e609 | 691 | static const unsigned char yytable[] = |
b9752825 | 692 | { |
e7b8bef1 | 693 | 10, 1, 11, 5, 6, 0, 7, 9 |
b9752825 | 694 | }; |
7c78fa18 | 695 | static const yysigned_char yycheck[] = |
b9752825 | 696 | { |
e7b8bef1 | 697 | 7, 3, 9, 4, 0, -1, 6, 5 |
b9752825 | 698 | }; |
5504898e AD |
699 | static const unsigned char yystos[] = |
700 | { | |
701 | 0, 3, 8, 9, 10, 4, 0, 6, 11, 5, | |
702 | 8, 8 | |
703 | }; | |
b9752825 AD |
704 | ]]) |
705 | ||
706 | AT_CLEANUP | |
22e304a6 AD |
707 | |
708 | ||
709 | ## ------------------------- ## | |
710 | ## yycheck Bound Violation. ## | |
711 | ## ------------------------- ## | |
712 | ||
713 | ||
714 | # _AT_DATA_DANCER_Y(BISON-OPTIONS) | |
715 | # -------------------------------- | |
716 | # The following grammar, taken from Andrew Suffield's GPL'd implementation | |
717 | # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate | |
718 | # yycheck's bounds where issuing a verbose error message. Keep this test | |
719 | # so that possible bound checking compilers could check all the skeletons. | |
720 | m4_define([_AT_DATA_DANCER_Y], | |
721 | [AT_DATA_GRAMMAR([dancer.y], | |
722 | [%{ | |
848dc439 PE |
723 | static int yylex (AT_LALR1_CC_IF([int *], [void])); |
724 | AT_LALR1_CC_IF([], | |
22e304a6 | 725 | [#include <stdio.h> |
848dc439 | 726 | static void yyerror (const char *);]) |
22e304a6 AD |
727 | %} |
728 | $1 | |
729 | %token ARROW INVALID NUMBER STRING DATA | |
730 | %defines | |
731 | %verbose | |
732 | %error-verbose | |
733 | /* Grammar follows */ | |
734 | %% | |
735 | line: header body | |
736 | ; | |
737 | ||
738 | header: '<' from ARROW to '>' type ':' | |
739 | | '<' ARROW to '>' type ':' | |
740 | | ARROW to type ':' | |
741 | | type ':' | |
742 | | '<' '>' | |
743 | ; | |
744 | ||
745 | from: DATA | |
746 | | STRING | |
747 | | INVALID | |
748 | ; | |
749 | ||
750 | to: DATA | |
751 | | STRING | |
752 | | INVALID | |
753 | ; | |
754 | ||
755 | type: DATA | |
756 | | STRING | |
757 | | INVALID | |
758 | ; | |
759 | ||
760 | body: /* empty */ | |
761 | | body member | |
762 | ; | |
763 | ||
764 | member: STRING | |
765 | | DATA | |
766 | | '+' NUMBER | |
767 | | '-' NUMBER | |
768 | | NUMBER | |
769 | | INVALID | |
770 | ; | |
771 | %% | |
772 | AT_LALR1_CC_IF( | |
68e11668 | 773 | [/* A C++ error reporting function. */ |
22e304a6 | 774 | void |
99880de5 | 775 | yy::parser::error (const location&, const std::string& m) |
22e304a6 | 776 | { |
efeed023 | 777 | std::cerr << m << std::endl; |
22e304a6 AD |
778 | } |
779 | ||
780 | int | |
99880de5 | 781 | yyparse () |
22e304a6 | 782 | { |
99880de5 | 783 | yy::parser parser; |
a3cb6248 | 784 | parser.set_debug_level (!!YYDEBUG); |
22e304a6 AD |
785 | return parser.parse (); |
786 | } | |
787 | ], | |
788 | [static void | |
789 | yyerror (const char *s) | |
790 | { | |
791 | fprintf (stderr, "%s\n", s); | |
792 | }]) | |
793 | ||
794 | static int | |
848dc439 | 795 | yylex (AT_LALR1_CC_IF([int *lval], [void])) |
22e304a6 AD |
796 | [{ |
797 | static int toknum = 0; | |
798 | int tokens[] = | |
799 | { | |
800 | ':', -1 | |
801 | }; | |
848dc439 | 802 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ |
22e304a6 AD |
803 | return tokens[toknum++]; |
804 | }] | |
805 | ||
806 | int | |
807 | main (void) | |
808 | { | |
809 | return yyparse (); | |
810 | } | |
811 | ]) | |
812 | ])# _AT_DATA_DANCER_Y | |
813 | ||
814 | ||
815 | # AT_CHECK_DANCER(BISON-OPTIONS) | |
816 | # ------------------------------ | |
817 | # Generate the grammar, compile it, run it. | |
818 | m4_define([AT_CHECK_DANCER], | |
819 | [AT_SETUP([Dancer $1]) | |
820 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
821 | _AT_DATA_DANCER_Y([$1]) | |
822 | AT_CHECK([bison -o dancer.c dancer.y]) | |
07971983 PE |
823 | AT_LALR1_CC_IF( |
824 | [AT_CHECK([bison -o dancer.cc dancer.y]) | |
825 | AT_COMPILE_CXX([dancer])], | |
826 | [AT_CHECK([bison -o dancer.c dancer.y]) | |
827 | AT_COMPILE([dancer])]) | |
22e304a6 | 828 | AT_PARSER_CHECK([./dancer], 1, [], |
d5286af1 | 829 | [syntax error, unexpected ':' |
22e304a6 AD |
830 | ]) |
831 | AT_BISON_OPTION_POPDEFS | |
832 | AT_CLEANUP | |
833 | ]) | |
834 | ||
835 | AT_CHECK_DANCER() | |
836 | AT_CHECK_DANCER([%glr-parser]) | |
837 | AT_CHECK_DANCER([%skeleton "lalr1.cc"]) |