]>
Commit | Line | Data |
---|---|---|
342b8b6e | 1 | # Bison Regressions. -*- Autotest -*- |
779e7ceb | 2 | # Copyright (C) 2001, 2002, 2003, 2004 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 | |
16 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA | |
17 | # 02111-1307, 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 | ||
270a173c | 306 | |
b87f8b21 AD |
307 | ## ------------------- ## |
308 | ## Token definitions. ## | |
309 | ## ------------------- ## | |
310 | ||
311 | ||
312 | AT_SETUP([Token definitions]) | |
313 | ||
314 | # Bison managed, when fed with `%token 'f' "f"' to #define 'f'! | |
9501dc6e | 315 | AT_DATA_GRAMMAR([input.y], |
db7c8e9a AD |
316 | [%{ |
317 | void yyerror (const char *s); | |
318 | int yylex (void); | |
319 | %} | |
7bd6c77e | 320 | [%token MYEOF 0 "end of file" |
b87f8b21 | 321 | %token 'a' "a" |
e9955c83 AD |
322 | %token b "b" |
323 | %token c 'c' | |
324 | %token 'd' d | |
b87f8b21 AD |
325 | %% |
326 | exp: "a"; | |
327 | ]]) | |
328 | ||
b56471a6 | 329 | AT_CHECK([bison -o input.c input.y]) |
002b9b7d | 330 | AT_COMPILE([input.o], [-c input.c]) |
b87f8b21 AD |
331 | AT_CLEANUP |
332 | ||
333 | ||
334 | ||
eb714592 AD |
335 | ## -------------------- ## |
336 | ## Characters Escapes. ## | |
337 | ## -------------------- ## | |
338 | ||
339 | ||
340 | AT_SETUP([Characters Escapes]) | |
341 | ||
9501dc6e | 342 | AT_DATA_GRAMMAR([input.y], |
eb714592 AD |
343 | [%{ |
344 | void yyerror (const char *s); | |
345 | int yylex (void); | |
346 | %} | |
347 | [%% | |
348 | exp: | |
349 | '\'' "\'" | |
350 | | '\"' "\"" | |
351 | | '"' "'" | |
352 | ; | |
353 | ]]) | |
9501dc6e | 354 | # Pacify font-lock-mode: " |
eb714592 | 355 | |
b56471a6 | 356 | AT_CHECK([bison -o input.c input.y]) |
eb714592 AD |
357 | AT_COMPILE([input.o], [-c input.c]) |
358 | AT_CLEANUP | |
359 | ||
360 | ||
361 | ||
b9752825 AD |
362 | ## -------------- ## |
363 | ## Web2c Report. ## | |
364 | ## -------------- ## | |
776209d6 AD |
365 | |
366 | # The generation of the reduction was once wrong in Bison, and made it | |
367 | # miss some reductions. In the following test case, the reduction on | |
368 | # `undef_id_tok' in state 1 was missing. This is stripped down from | |
369 | # the actual web2c.y. | |
370 | ||
b9752825 | 371 | AT_SETUP([Web2c Report]) |
776209d6 | 372 | |
6b98e4b5 AD |
373 | AT_KEYWORDS([report]) |
374 | ||
776209d6 AD |
375 | AT_DATA([input.y], |
376 | [[%token undef_id_tok const_id_tok | |
377 | ||
378 | %start CONST_DEC_PART | |
379 | \f | |
380 | %% | |
381 | CONST_DEC_PART: | |
382 | CONST_DEC_LIST | |
383 | ; | |
384 | ||
385 | CONST_DEC_LIST: | |
386 | CONST_DEC | |
387 | | CONST_DEC_LIST CONST_DEC | |
388 | ; | |
389 | ||
390 | CONST_DEC: | |
391 | { } undef_id_tok '=' const_id_tok ';' | |
392 | ; | |
393 | %% | |
776209d6 AD |
394 | ]]) |
395 | ||
396 | AT_CHECK([bison -v input.y]) | |
87675353 | 397 | AT_CHECK([cat input.output], 0, |
776209d6 | 398 | [[Grammar |
87675353 | 399 | |
88bce5a2 | 400 | 0 $accept: CONST_DEC_PART $end |
87675353 | 401 | |
6b98e4b5 | 402 | 1 CONST_DEC_PART: CONST_DEC_LIST |
87675353 | 403 | |
6b98e4b5 AD |
404 | 2 CONST_DEC_LIST: CONST_DEC |
405 | 3 | CONST_DEC_LIST CONST_DEC | |
87675353 | 406 | |
6b98e4b5 | 407 | 4 @1: /* empty */ |
87675353 | 408 | |
6b98e4b5 | 409 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' |
87675353 AD |
410 | |
411 | ||
776209d6 | 412 | Terminals, with rules where they appear |
87675353 | 413 | |
88bce5a2 | 414 | $end (0) 0 |
776209d6 AD |
415 | ';' (59) 5 |
416 | '=' (61) 5 | |
417 | error (256) | |
007a50a4 AD |
418 | undef_id_tok (258) 5 |
419 | const_id_tok (259) 5 | |
87675353 AD |
420 | |
421 | ||
776209d6 | 422 | Nonterminals, with rules where they appear |
87675353 | 423 | |
88bce5a2 | 424 | $accept (7) |
78d5bae9 AD |
425 | on left: 0 |
426 | CONST_DEC_PART (8) | |
427 | on left: 1, on right: 0 | |
428 | CONST_DEC_LIST (9) | |
776209d6 | 429 | on left: 2 3, on right: 1 3 |
78d5bae9 | 430 | CONST_DEC (10) |
776209d6 | 431 | on left: 5, on right: 2 3 |
78d5bae9 | 432 | @1 (11) |
776209d6 | 433 | on left: 4, on right: 5 |
87675353 AD |
434 | |
435 | ||
776209d6 | 436 | state 0 |
87675353 | 437 | |
88bce5a2 | 438 | 0 $accept: . CONST_DEC_PART $end |
87675353 AD |
439 | |
440 | $default reduce using rule 4 (@1) | |
441 | ||
442 | CONST_DEC_PART go to state 1 | |
443 | CONST_DEC_LIST go to state 2 | |
444 | CONST_DEC go to state 3 | |
445 | @1 go to state 4 | |
446 | ||
447 | ||
776209d6 | 448 | state 1 |
87675353 | 449 | |
88bce5a2 | 450 | 0 $accept: CONST_DEC_PART . $end |
87675353 | 451 | |
88bce5a2 | 452 | $end shift, and go to state 5 |
87675353 AD |
453 | |
454 | ||
78d5bae9 | 455 | state 2 |
87675353 | 456 | |
ce4ccb4b AD |
457 | 1 CONST_DEC_PART: CONST_DEC_LIST . |
458 | 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC | |
87675353 AD |
459 | |
460 | undef_id_tok reduce using rule 4 (@1) | |
461 | $default reduce using rule 1 (CONST_DEC_PART) | |
462 | ||
463 | CONST_DEC go to state 6 | |
464 | @1 go to state 4 | |
465 | ||
466 | ||
78d5bae9 | 467 | state 3 |
87675353 | 468 | |
ce4ccb4b | 469 | 2 CONST_DEC_LIST: CONST_DEC . |
87675353 AD |
470 | |
471 | $default reduce using rule 2 (CONST_DEC_LIST) | |
472 | ||
473 | ||
776209d6 | 474 | state 4 |
87675353 | 475 | |
ce4ccb4b | 476 | 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';' |
87675353 AD |
477 | |
478 | undef_id_tok shift, and go to state 7 | |
479 | ||
480 | ||
78d5bae9 | 481 | state 5 |
87675353 | 482 | |
88bce5a2 | 483 | 0 $accept: CONST_DEC_PART $end . |
87675353 | 484 | |
e8832397 | 485 | $default accept |
87675353 AD |
486 | |
487 | ||
78d5bae9 | 488 | state 6 |
87675353 | 489 | |
ce4ccb4b | 490 | 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC . |
87675353 AD |
491 | |
492 | $default reduce using rule 3 (CONST_DEC_LIST) | |
493 | ||
494 | ||
78d5bae9 | 495 | state 7 |
87675353 | 496 | |
ce4ccb4b | 497 | 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';' |
87675353 AD |
498 | |
499 | '=' shift, and go to state 8 | |
500 | ||
501 | ||
78d5bae9 | 502 | state 8 |
87675353 | 503 | |
ce4ccb4b | 504 | 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';' |
87675353 AD |
505 | |
506 | const_id_tok shift, and go to state 9 | |
507 | ||
508 | ||
78d5bae9 | 509 | state 9 |
87675353 | 510 | |
ce4ccb4b | 511 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';' |
87675353 AD |
512 | |
513 | ';' shift, and go to state 10 | |
514 | ||
515 | ||
78d5bae9 | 516 | state 10 |
87675353 | 517 | |
ce4ccb4b | 518 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' . |
87675353 AD |
519 | |
520 | $default reduce using rule 5 (CONST_DEC) | |
776209d6 AD |
521 | ]]) |
522 | ||
523 | AT_CLEANUP | |
b9752825 AD |
524 | |
525 | ||
526 | ## --------------- ## | |
527 | ## Web2c Actions. ## | |
528 | ## --------------- ## | |
529 | ||
530 | # The generation of the mapping `state -> action' was once wrong in | |
531 | # extremely specific situations. web2c.y exhibits this situation. | |
532 | # Below is a stripped version of the grammar. It looks like one can | |
533 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
534 | # which disapears when applying sane grammar transformations. | |
535 | # | |
536 | # It used to be wrong on yydefact only: | |
537 | # | |
779e7ceb | 538 | # static const short int yydefact[] = |
b9752825 AD |
539 | # { |
540 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
541 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
542 | # 0, 0 | |
543 | # }; | |
544 | # | |
545 | # but let's check all the tables. | |
546 | ||
547 | ||
548 | AT_SETUP([Web2c Actions]) | |
549 | ||
6b98e4b5 AD |
550 | AT_KEYWORDS([report]) |
551 | ||
b9752825 AD |
552 | AT_DATA([input.y], |
553 | [[%% | |
554 | statement: struct_stat; | |
555 | struct_stat: /* empty. */ | if else; | |
556 | if: "if" "const" "then" statement; | |
557 | else: "else" statement; | |
558 | %% | |
559 | ]]) | |
560 | ||
b56471a6 | 561 | AT_CHECK([bison -v -o input.c input.y]) |
b9752825 AD |
562 | |
563 | # Check only the tables. We don't use --no-parser, because it is | |
564 | # still to be implemented in the experimental branch of Bison. | |
ce4ccb4b AD |
565 | [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] |
566 | ||
567 | AT_CHECK([[cat tables.c]], 0, | |
c0c9ea05 | 568 | [[static const unsigned char yytranslate[] = |
b9752825 AD |
569 | { |
570 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
571 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
572 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
573 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
574 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
575 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
576 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
577 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
578 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
579 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
580 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
581 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
582 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
583 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
584 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
585 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
586 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
587 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
588 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
589 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
590 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
591 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
592 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
593 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
594 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
007a50a4 AD |
595 | 2, 2, 2, 2, 2, 2, 1, 2, 3, 4, |
596 | 5, 6 | |
b9752825 | 597 | }; |
5df5f6d5 | 598 | static const unsigned char yyprhs[] = |
b9752825 | 599 | { |
e7b8bef1 | 600 | 0, 0, 3, 5, 6, 9, 14 |
b9752825 | 601 | }; |
7c78fa18 | 602 | static const yysigned_char yyrhs[] = |
b9752825 | 603 | { |
e7b8bef1 AD |
604 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, |
605 | 4, 5, 8, -1, 6, 8, -1 | |
b9752825 | 606 | }; |
5df5f6d5 | 607 | static const unsigned char yyrline[] = |
b9752825 | 608 | { |
e7b8bef1 | 609 | 0, 2, 2, 3, 3, 4, 5 |
b9752825 AD |
610 | }; |
611 | static const char *const yytname[] = | |
612 | { | |
88bce5a2 AD |
613 | "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"", |
614 | "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0 | |
b9752825 | 615 | }; |
779e7ceb | 616 | static const unsigned short int yytoknum[] = |
b9752825 | 617 | { |
3650b4b8 | 618 | 0, 256, 257, 258, 259, 260, 261 |
b9752825 | 619 | }; |
c0c9ea05 | 620 | static const unsigned char yyr1[] = |
b9752825 | 621 | { |
e7b8bef1 | 622 | 0, 7, 8, 9, 9, 10, 11 |
b9752825 | 623 | }; |
5df5f6d5 | 624 | static const unsigned char yyr2[] = |
b9752825 | 625 | { |
e7b8bef1 | 626 | 0, 2, 1, 0, 2, 4, 2 |
b9752825 | 627 | }; |
a762e609 | 628 | static const unsigned char yydefact[] = |
b9752825 | 629 | { |
e8832397 | 630 | 3, 0, 0, 2, 0, 0, 1, 3, 4, 3, |
e7b8bef1 | 631 | 6, 5 |
b9752825 | 632 | }; |
7c78fa18 | 633 | static const yysigned_char yydefgoto[] = |
b9752825 | 634 | { |
e7b8bef1 | 635 | -1, 2, 3, 4, 8 |
b9752825 | 636 | }; |
7c78fa18 | 637 | static const yysigned_char yypact[] = |
b9752825 | 638 | { |
12b0043a AD |
639 | -2, -1, 4, -8, 0, 2, -8, -2, -8, -2, |
640 | -8, -8 | |
b9752825 | 641 | }; |
7c78fa18 | 642 | static const yysigned_char yypgoto[] = |
b9752825 | 643 | { |
12b0043a | 644 | -8, -7, -8, -8, -8 |
b9752825 | 645 | }; |
a762e609 | 646 | static const unsigned char yytable[] = |
b9752825 | 647 | { |
e7b8bef1 | 648 | 10, 1, 11, 5, 6, 0, 7, 9 |
b9752825 | 649 | }; |
7c78fa18 | 650 | static const yysigned_char yycheck[] = |
b9752825 | 651 | { |
e7b8bef1 | 652 | 7, 3, 9, 4, 0, -1, 6, 5 |
b9752825 | 653 | }; |
5504898e AD |
654 | static const unsigned char yystos[] = |
655 | { | |
656 | 0, 3, 8, 9, 10, 4, 0, 6, 11, 5, | |
657 | 8, 8 | |
658 | }; | |
b9752825 AD |
659 | ]]) |
660 | ||
661 | AT_CLEANUP | |
22e304a6 AD |
662 | |
663 | ||
664 | ## ------------------------- ## | |
665 | ## yycheck Bound Violation. ## | |
666 | ## ------------------------- ## | |
667 | ||
668 | ||
669 | # _AT_DATA_DANCER_Y(BISON-OPTIONS) | |
670 | # -------------------------------- | |
671 | # The following grammar, taken from Andrew Suffield's GPL'd implementation | |
672 | # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate | |
673 | # yycheck's bounds where issuing a verbose error message. Keep this test | |
674 | # so that possible bound checking compilers could check all the skeletons. | |
675 | m4_define([_AT_DATA_DANCER_Y], | |
676 | [AT_DATA_GRAMMAR([dancer.y], | |
677 | [%{ | |
848dc439 PE |
678 | static int yylex (AT_LALR1_CC_IF([int *], [void])); |
679 | AT_LALR1_CC_IF([], | |
22e304a6 | 680 | [#include <stdio.h> |
848dc439 | 681 | static void yyerror (const char *);]) |
22e304a6 AD |
682 | %} |
683 | $1 | |
684 | %token ARROW INVALID NUMBER STRING DATA | |
685 | %defines | |
686 | %verbose | |
687 | %error-verbose | |
688 | /* Grammar follows */ | |
689 | %% | |
690 | line: header body | |
691 | ; | |
692 | ||
693 | header: '<' from ARROW to '>' type ':' | |
694 | | '<' ARROW to '>' type ':' | |
695 | | ARROW to type ':' | |
696 | | type ':' | |
697 | | '<' '>' | |
698 | ; | |
699 | ||
700 | from: DATA | |
701 | | STRING | |
702 | | INVALID | |
703 | ; | |
704 | ||
705 | to: DATA | |
706 | | STRING | |
707 | | INVALID | |
708 | ; | |
709 | ||
710 | type: DATA | |
711 | | STRING | |
712 | | INVALID | |
713 | ; | |
714 | ||
715 | body: /* empty */ | |
716 | | body member | |
717 | ; | |
718 | ||
719 | member: STRING | |
720 | | DATA | |
721 | | '+' NUMBER | |
722 | | '-' NUMBER | |
723 | | NUMBER | |
724 | | INVALID | |
725 | ; | |
726 | %% | |
727 | AT_LALR1_CC_IF( | |
68e11668 | 728 | [/* A C++ error reporting function. */ |
22e304a6 | 729 | void |
99880de5 | 730 | yy::parser::error (const location&, const std::string& m) |
22e304a6 | 731 | { |
efeed023 | 732 | std::cerr << m << std::endl; |
22e304a6 AD |
733 | } |
734 | ||
735 | int | |
99880de5 | 736 | yyparse () |
22e304a6 | 737 | { |
99880de5 | 738 | yy::parser parser; |
a3cb6248 | 739 | parser.set_debug_level (!!YYDEBUG); |
22e304a6 AD |
740 | return parser.parse (); |
741 | } | |
742 | ], | |
743 | [static void | |
744 | yyerror (const char *s) | |
745 | { | |
746 | fprintf (stderr, "%s\n", s); | |
747 | }]) | |
748 | ||
749 | static int | |
848dc439 | 750 | yylex (AT_LALR1_CC_IF([int *lval], [void])) |
22e304a6 AD |
751 | [{ |
752 | static int toknum = 0; | |
753 | int tokens[] = | |
754 | { | |
755 | ':', -1 | |
756 | }; | |
848dc439 | 757 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ |
22e304a6 AD |
758 | return tokens[toknum++]; |
759 | }] | |
760 | ||
761 | int | |
762 | main (void) | |
763 | { | |
764 | return yyparse (); | |
765 | } | |
766 | ]) | |
767 | ])# _AT_DATA_DANCER_Y | |
768 | ||
769 | ||
770 | # AT_CHECK_DANCER(BISON-OPTIONS) | |
771 | # ------------------------------ | |
772 | # Generate the grammar, compile it, run it. | |
773 | m4_define([AT_CHECK_DANCER], | |
774 | [AT_SETUP([Dancer $1]) | |
775 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
776 | _AT_DATA_DANCER_Y([$1]) | |
777 | AT_CHECK([bison -o dancer.c dancer.y]) | |
07971983 PE |
778 | AT_LALR1_CC_IF( |
779 | [AT_CHECK([bison -o dancer.cc dancer.y]) | |
780 | AT_COMPILE_CXX([dancer])], | |
781 | [AT_CHECK([bison -o dancer.c dancer.y]) | |
782 | AT_COMPILE([dancer])]) | |
22e304a6 | 783 | AT_PARSER_CHECK([./dancer], 1, [], |
d5286af1 | 784 | [syntax error, unexpected ':' |
22e304a6 AD |
785 | ]) |
786 | AT_BISON_OPTION_POPDEFS | |
787 | AT_CLEANUP | |
788 | ]) | |
789 | ||
790 | AT_CHECK_DANCER() | |
791 | AT_CHECK_DANCER([%glr-parser]) | |
792 | AT_CHECK_DANCER([%skeleton "lalr1.cc"]) |