]>
Commit | Line | Data |
---|---|---|
1 | # Bison Regressions. -*- Autotest -*- | |
2 | # Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc. | |
3 | ||
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. | |
8 | ||
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. | |
13 | ||
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., 51 Franklin Street, Fifth Floor, Boston, MA | |
17 | # 02110-1301, USA. | |
18 | ||
19 | AT_BANNER([[Regression tests.]]) | |
20 | ||
21 | ||
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 | ||
32 | AT_DATA_GRAMMAR([input.y], | |
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 | ||
53 | AT_CHECK([bison -o input.c input.y]) | |
54 | AT_COMPILE([input.o], [-c input.c]) | |
55 | ||
56 | AT_CLEANUP | |
57 | ||
58 | ||
59 | ||
60 | ## ---------------- ## | |
61 | ## Braces parsing. ## | |
62 | ## ---------------- ## | |
63 | ||
64 | ||
65 | AT_SETUP([Braces parsing]) | |
66 | ||
67 | AT_DATA([input.y], | |
68 | [[/* Bison used to swallow the character after `}'. */ | |
69 | ||
70 | %% | |
71 | exp: { tests = {{{{{{{{{{}}}}}}}}}}; }; | |
72 | %% | |
73 | ]]) | |
74 | ||
75 | AT_CHECK([bison -v -o input.c input.y]) | |
76 | ||
77 | AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore]) | |
78 | ||
79 | AT_CLEANUP | |
80 | ||
81 | ||
82 | ## ------------------ ## | |
83 | ## Duplicate string. ## | |
84 | ## ------------------ ## | |
85 | ||
86 | ||
87 | AT_SETUP([Duplicate string]) | |
88 | ||
89 | AT_DATA([input.y], | |
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 | ||
102 | AT_CHECK([bison -v -o input.c input.y], 0, [], | |
103 | [[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string | |
104 | ]]) | |
105 | ||
106 | AT_CLEANUP | |
107 | ||
108 | ||
109 | ## ------------------- ## | |
110 | ## Rule Line Numbers. ## | |
111 | ## ------------------- ## | |
112 | ||
113 | AT_SETUP([Rule Line Numbers]) | |
114 | ||
115 | AT_KEYWORDS([report]) | |
116 | ||
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 | ||
144 | }; | |
145 | ]]) | |
146 | ||
147 | AT_CHECK([bison -o input.c -v input.y]) | |
148 | ||
149 | # Check the contents of the report. | |
150 | AT_CHECK([cat input.output], [], | |
151 | [[Grammar | |
152 | ||
153 | 0 $accept: expr $end | |
154 | ||
155 | 1 @1: /* empty */ | |
156 | ||
157 | 2 expr: 'a' @1 'b' | |
158 | ||
159 | 3 @2: /* empty */ | |
160 | ||
161 | 4 expr: @2 'c' | |
162 | ||
163 | ||
164 | Terminals, with rules where they appear | |
165 | ||
166 | $end (0) 0 | |
167 | 'a' (97) 2 | |
168 | 'b' (98) 2 | |
169 | 'c' (99) 4 | |
170 | error (256) | |
171 | ||
172 | ||
173 | Nonterminals, with rules where they appear | |
174 | ||
175 | $accept (6) | |
176 | on left: 0 | |
177 | expr (7) | |
178 | on left: 2 4, on right: 0 | |
179 | @1 (8) | |
180 | on left: 1, on right: 2 | |
181 | @2 (9) | |
182 | on left: 3, on right: 4 | |
183 | ||
184 | ||
185 | state 0 | |
186 | ||
187 | 0 $accept: . expr $end | |
188 | ||
189 | 'a' shift, and go to state 1 | |
190 | ||
191 | $default reduce using rule 3 (@2) | |
192 | ||
193 | expr go to state 2 | |
194 | @2 go to state 3 | |
195 | ||
196 | ||
197 | state 1 | |
198 | ||
199 | 2 expr: 'a' . @1 'b' | |
200 | ||
201 | $default reduce using rule 1 (@1) | |
202 | ||
203 | @1 go to state 4 | |
204 | ||
205 | ||
206 | state 2 | |
207 | ||
208 | 0 $accept: expr . $end | |
209 | ||
210 | $end shift, and go to state 5 | |
211 | ||
212 | ||
213 | state 3 | |
214 | ||
215 | 4 expr: @2 . 'c' | |
216 | ||
217 | 'c' shift, and go to state 6 | |
218 | ||
219 | ||
220 | state 4 | |
221 | ||
222 | 2 expr: 'a' @1 . 'b' | |
223 | ||
224 | 'b' shift, and go to state 7 | |
225 | ||
226 | ||
227 | state 5 | |
228 | ||
229 | 0 $accept: expr $end . | |
230 | ||
231 | $default accept | |
232 | ||
233 | ||
234 | state 6 | |
235 | ||
236 | 4 expr: @2 'c' . | |
237 | ||
238 | $default reduce using rule 4 (expr) | |
239 | ||
240 | ||
241 | state 7 | |
242 | ||
243 | 2 expr: 'a' @1 'b' . | |
244 | ||
245 | $default reduce using rule 2 (expr) | |
246 | ]]) | |
247 | ||
248 | AT_CLEANUP | |
249 | ||
250 | ||
251 | ||
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 | ||
269 | AT_CHECK([bison -v -o input.c input.y]) | |
270 | ||
271 | AT_CLEANUP | |
272 | ||
273 | ||
274 | ||
275 | ## ---------------- ## | |
276 | ## Invalid inputs. ## | |
277 | ## ---------------- ## | |
278 | ||
279 | ||
280 | AT_SETUP([Invalid inputs]) | |
281 | ||
282 | AT_DATA([input.y], | |
283 | [[%% | |
284 | ? | |
285 | default: 'a' } | |
286 | %& | |
287 | %a-does-not-exist | |
288 | %- | |
289 | %{ | |
290 | ]]) | |
291 | ||
292 | AT_CHECK([bison input.y], [1], [], | |
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: `&' | |
297 | input.y:5.1-17: invalid directive: `%a-does-not-exist' | |
298 | input.y:6.1: invalid character: `%' | |
299 | input.y:6.2: invalid character: `-' | |
300 | input.y:7.1-8.0: missing `%}' at end of file | |
301 | ]]) | |
302 | ||
303 | AT_CLEANUP | |
304 | ||
305 | ||
306 | ||
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'! | |
315 | AT_DATA_GRAMMAR([input.y], | |
316 | [%{ | |
317 | #include <stdio.h> | |
318 | void yyerror (const char *s); | |
319 | int yylex (void); | |
320 | %} | |
321 | [%error-verbose | |
322 | %token MYEOF 0 "end of file" | |
323 | %token 'a' "a" | |
324 | %token B_TOKEN "b" | |
325 | %token C_TOKEN 'c' | |
326 | %token 'd' D_TOKEN | |
327 | %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\377\x001\x0000ff??!" | |
328 | %% | |
329 | exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\377\x001\x0000ff??!"; | |
330 | %% | |
331 | void | |
332 | yyerror (char const *s) | |
333 | { | |
334 | fprintf (stderr, "%s\n", s); | |
335 | } | |
336 | ||
337 | int | |
338 | yylex (void) | |
339 | { | |
340 | return SPECIAL; | |
341 | } | |
342 | ||
343 | int | |
344 | main (void) | |
345 | { | |
346 | return yyparse (); | |
347 | } | |
348 | ]]) | |
349 | ||
350 | AT_CHECK([bison -o input.c input.y]) | |
351 | AT_COMPILE([input]) | |
352 | AT_PARSER_CHECK([./input], 1, [], | |
353 | [syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\377\001\377?\?!", expecting a | |
354 | ]) | |
355 | AT_CLEANUP | |
356 | ||
357 | ||
358 | ||
359 | ## -------------------- ## | |
360 | ## Characters Escapes. ## | |
361 | ## -------------------- ## | |
362 | ||
363 | ||
364 | AT_SETUP([Characters Escapes]) | |
365 | ||
366 | AT_DATA_GRAMMAR([input.y], | |
367 | [%{ | |
368 | void yyerror (const char *s); | |
369 | int yylex (void); | |
370 | %} | |
371 | [%% | |
372 | exp: | |
373 | '\'' "\'" | |
374 | | '\"' "\"" | |
375 | | '"' "'" | |
376 | ; | |
377 | ]]) | |
378 | # Pacify font-lock-mode: " | |
379 | ||
380 | AT_CHECK([bison -o input.c input.y]) | |
381 | AT_COMPILE([input.o], [-c input.c]) | |
382 | AT_CLEANUP | |
383 | ||
384 | ||
385 | ||
386 | ## -------------- ## | |
387 | ## Web2c Report. ## | |
388 | ## -------------- ## | |
389 | ||
390 | # The generation of the reduction was once wrong in Bison, and made it | |
391 | # miss some reductions. In the following test case, the reduction on | |
392 | # `undef_id_tok' in state 1 was missing. This is stripped down from | |
393 | # the actual web2c.y. | |
394 | ||
395 | AT_SETUP([Web2c Report]) | |
396 | ||
397 | AT_KEYWORDS([report]) | |
398 | ||
399 | AT_DATA([input.y], | |
400 | [[%token undef_id_tok const_id_tok | |
401 | ||
402 | %start CONST_DEC_PART | |
403 | \f | |
404 | %% | |
405 | CONST_DEC_PART: | |
406 | CONST_DEC_LIST | |
407 | ; | |
408 | ||
409 | CONST_DEC_LIST: | |
410 | CONST_DEC | |
411 | | CONST_DEC_LIST CONST_DEC | |
412 | ; | |
413 | ||
414 | CONST_DEC: | |
415 | { } undef_id_tok '=' const_id_tok ';' | |
416 | ; | |
417 | %% | |
418 | ]]) | |
419 | ||
420 | AT_CHECK([bison -v input.y]) | |
421 | AT_CHECK([cat input.output], 0, | |
422 | [[Grammar | |
423 | ||
424 | 0 $accept: CONST_DEC_PART $end | |
425 | ||
426 | 1 CONST_DEC_PART: CONST_DEC_LIST | |
427 | ||
428 | 2 CONST_DEC_LIST: CONST_DEC | |
429 | 3 | CONST_DEC_LIST CONST_DEC | |
430 | ||
431 | 4 @1: /* empty */ | |
432 | ||
433 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' | |
434 | ||
435 | ||
436 | Terminals, with rules where they appear | |
437 | ||
438 | $end (0) 0 | |
439 | ';' (59) 5 | |
440 | '=' (61) 5 | |
441 | error (256) | |
442 | undef_id_tok (258) 5 | |
443 | const_id_tok (259) 5 | |
444 | ||
445 | ||
446 | Nonterminals, with rules where they appear | |
447 | ||
448 | $accept (7) | |
449 | on left: 0 | |
450 | CONST_DEC_PART (8) | |
451 | on left: 1, on right: 0 | |
452 | CONST_DEC_LIST (9) | |
453 | on left: 2 3, on right: 1 3 | |
454 | CONST_DEC (10) | |
455 | on left: 5, on right: 2 3 | |
456 | @1 (11) | |
457 | on left: 4, on right: 5 | |
458 | ||
459 | ||
460 | state 0 | |
461 | ||
462 | 0 $accept: . CONST_DEC_PART $end | |
463 | ||
464 | $default reduce using rule 4 (@1) | |
465 | ||
466 | CONST_DEC_PART go to state 1 | |
467 | CONST_DEC_LIST go to state 2 | |
468 | CONST_DEC go to state 3 | |
469 | @1 go to state 4 | |
470 | ||
471 | ||
472 | state 1 | |
473 | ||
474 | 0 $accept: CONST_DEC_PART . $end | |
475 | ||
476 | $end shift, and go to state 5 | |
477 | ||
478 | ||
479 | state 2 | |
480 | ||
481 | 1 CONST_DEC_PART: CONST_DEC_LIST . | |
482 | 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC | |
483 | ||
484 | undef_id_tok reduce using rule 4 (@1) | |
485 | $default reduce using rule 1 (CONST_DEC_PART) | |
486 | ||
487 | CONST_DEC go to state 6 | |
488 | @1 go to state 4 | |
489 | ||
490 | ||
491 | state 3 | |
492 | ||
493 | 2 CONST_DEC_LIST: CONST_DEC . | |
494 | ||
495 | $default reduce using rule 2 (CONST_DEC_LIST) | |
496 | ||
497 | ||
498 | state 4 | |
499 | ||
500 | 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';' | |
501 | ||
502 | undef_id_tok shift, and go to state 7 | |
503 | ||
504 | ||
505 | state 5 | |
506 | ||
507 | 0 $accept: CONST_DEC_PART $end . | |
508 | ||
509 | $default accept | |
510 | ||
511 | ||
512 | state 6 | |
513 | ||
514 | 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC . | |
515 | ||
516 | $default reduce using rule 3 (CONST_DEC_LIST) | |
517 | ||
518 | ||
519 | state 7 | |
520 | ||
521 | 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';' | |
522 | ||
523 | '=' shift, and go to state 8 | |
524 | ||
525 | ||
526 | state 8 | |
527 | ||
528 | 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';' | |
529 | ||
530 | const_id_tok shift, and go to state 9 | |
531 | ||
532 | ||
533 | state 9 | |
534 | ||
535 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';' | |
536 | ||
537 | ';' shift, and go to state 10 | |
538 | ||
539 | ||
540 | state 10 | |
541 | ||
542 | 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' . | |
543 | ||
544 | $default reduce using rule 5 (CONST_DEC) | |
545 | ]]) | |
546 | ||
547 | AT_CLEANUP | |
548 | ||
549 | ||
550 | ## --------------- ## | |
551 | ## Web2c Actions. ## | |
552 | ## --------------- ## | |
553 | ||
554 | # The generation of the mapping `state -> action' was once wrong in | |
555 | # extremely specific situations. web2c.y exhibits this situation. | |
556 | # Below is a stripped version of the grammar. It looks like one can | |
557 | # simplify it further, but just don't: it is tuned to exhibit a bug, | |
558 | # which disapears when applying sane grammar transformations. | |
559 | # | |
560 | # It used to be wrong on yydefact only: | |
561 | # | |
562 | # static const short int yydefact[] = | |
563 | # { | |
564 | # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4, | |
565 | # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4, | |
566 | # 0, 0 | |
567 | # }; | |
568 | # | |
569 | # but let's check all the tables. | |
570 | ||
571 | ||
572 | AT_SETUP([Web2c Actions]) | |
573 | ||
574 | AT_KEYWORDS([report]) | |
575 | ||
576 | AT_DATA([input.y], | |
577 | [[%% | |
578 | statement: struct_stat; | |
579 | struct_stat: /* empty. */ | if else; | |
580 | if: "if" "const" "then" statement; | |
581 | else: "else" statement; | |
582 | %% | |
583 | ]]) | |
584 | ||
585 | AT_CHECK([bison -v -o input.c input.y]) | |
586 | ||
587 | # Check only the tables. We don't use --no-parser, because it is | |
588 | # still to be implemented in the experimental branch of Bison. | |
589 | [sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c] | |
590 | ||
591 | AT_CHECK([[cat tables.c]], 0, | |
592 | [[static const unsigned char yytranslate[] = | |
593 | { | |
594 | 0, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
595 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
596 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
597 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
598 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
599 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
600 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
601 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
602 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
603 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
604 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
605 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
606 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
607 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
608 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
609 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
610 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
611 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
612 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
613 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
614 | 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, | |
615 | 2, 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, 1, 2, 3, 4, | |
620 | 5, 6 | |
621 | }; | |
622 | static const unsigned char yyprhs[] = | |
623 | { | |
624 | 0, 0, 3, 5, 6, 9, 14 | |
625 | }; | |
626 | static const yysigned_char yyrhs[] = | |
627 | { | |
628 | 8, 0, -1, 9, -1, -1, 10, 11, -1, 3, | |
629 | 4, 5, 8, -1, 6, 8, -1 | |
630 | }; | |
631 | static const unsigned char yyrline[] = | |
632 | { | |
633 | 0, 2, 2, 3, 3, 4, 5 | |
634 | }; | |
635 | static const char *const yytname[] = | |
636 | { | |
637 | "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"", | |
638 | "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0 | |
639 | }; | |
640 | static const unsigned short int yytoknum[] = | |
641 | { | |
642 | 0, 256, 257, 258, 259, 260, 261 | |
643 | }; | |
644 | static const unsigned char yyr1[] = | |
645 | { | |
646 | 0, 7, 8, 9, 9, 10, 11 | |
647 | }; | |
648 | static const unsigned char yyr2[] = | |
649 | { | |
650 | 0, 2, 1, 0, 2, 4, 2 | |
651 | }; | |
652 | static const unsigned char yydefact[] = | |
653 | { | |
654 | 3, 0, 0, 2, 0, 0, 1, 3, 4, 3, | |
655 | 6, 5 | |
656 | }; | |
657 | static const yysigned_char yydefgoto[] = | |
658 | { | |
659 | -1, 2, 3, 4, 8 | |
660 | }; | |
661 | static const yysigned_char yypact[] = | |
662 | { | |
663 | -2, -1, 4, -8, 0, 2, -8, -2, -8, -2, | |
664 | -8, -8 | |
665 | }; | |
666 | static const yysigned_char yypgoto[] = | |
667 | { | |
668 | -8, -7, -8, -8, -8 | |
669 | }; | |
670 | static const unsigned char yytable[] = | |
671 | { | |
672 | 10, 1, 11, 5, 6, 0, 7, 9 | |
673 | }; | |
674 | static const yysigned_char yycheck[] = | |
675 | { | |
676 | 7, 3, 9, 4, 0, -1, 6, 5 | |
677 | }; | |
678 | static const unsigned char yystos[] = | |
679 | { | |
680 | 0, 3, 8, 9, 10, 4, 0, 6, 11, 5, | |
681 | 8, 8 | |
682 | }; | |
683 | ]]) | |
684 | ||
685 | AT_CLEANUP | |
686 | ||
687 | ||
688 | ## ------------------------- ## | |
689 | ## yycheck Bound Violation. ## | |
690 | ## ------------------------- ## | |
691 | ||
692 | ||
693 | # _AT_DATA_DANCER_Y(BISON-OPTIONS) | |
694 | # -------------------------------- | |
695 | # The following grammar, taken from Andrew Suffield's GPL'd implementation | |
696 | # of DGMTP, the Dancer Generic Message Transport Protocol, used to violate | |
697 | # yycheck's bounds where issuing a verbose error message. Keep this test | |
698 | # so that possible bound checking compilers could check all the skeletons. | |
699 | m4_define([_AT_DATA_DANCER_Y], | |
700 | [AT_DATA_GRAMMAR([dancer.y], | |
701 | [%{ | |
702 | static int yylex (AT_LALR1_CC_IF([int *], [void])); | |
703 | AT_LALR1_CC_IF([], | |
704 | [#include <stdio.h> | |
705 | static void yyerror (const char *);]) | |
706 | %} | |
707 | $1 | |
708 | %token ARROW INVALID NUMBER STRING DATA | |
709 | %defines | |
710 | %verbose | |
711 | %error-verbose | |
712 | /* Grammar follows */ | |
713 | %% | |
714 | line: header body | |
715 | ; | |
716 | ||
717 | header: '<' from ARROW to '>' type ':' | |
718 | | '<' ARROW to '>' type ':' | |
719 | | ARROW to type ':' | |
720 | | type ':' | |
721 | | '<' '>' | |
722 | ; | |
723 | ||
724 | from: DATA | |
725 | | STRING | |
726 | | INVALID | |
727 | ; | |
728 | ||
729 | to: DATA | |
730 | | STRING | |
731 | | INVALID | |
732 | ; | |
733 | ||
734 | type: DATA | |
735 | | STRING | |
736 | | INVALID | |
737 | ; | |
738 | ||
739 | body: /* empty */ | |
740 | | body member | |
741 | ; | |
742 | ||
743 | member: STRING | |
744 | | DATA | |
745 | | '+' NUMBER | |
746 | | '-' NUMBER | |
747 | | NUMBER | |
748 | | INVALID | |
749 | ; | |
750 | %% | |
751 | AT_LALR1_CC_IF( | |
752 | [/* A C++ error reporting function. */ | |
753 | void | |
754 | yy::parser::error (const location&, const std::string& m) | |
755 | { | |
756 | std::cerr << m << std::endl; | |
757 | } | |
758 | ||
759 | int | |
760 | yyparse () | |
761 | { | |
762 | yy::parser parser; | |
763 | parser.set_debug_level (!!YYDEBUG); | |
764 | return parser.parse (); | |
765 | } | |
766 | ], | |
767 | [static void | |
768 | yyerror (const char *s) | |
769 | { | |
770 | fprintf (stderr, "%s\n", s); | |
771 | }]) | |
772 | ||
773 | static int | |
774 | yylex (AT_LALR1_CC_IF([int *lval], [void])) | |
775 | [{ | |
776 | static int toknum = 0; | |
777 | int tokens[] = | |
778 | { | |
779 | ':', -1 | |
780 | }; | |
781 | ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[ | |
782 | return tokens[toknum++]; | |
783 | }] | |
784 | ||
785 | int | |
786 | main (void) | |
787 | { | |
788 | return yyparse (); | |
789 | } | |
790 | ]) | |
791 | ])# _AT_DATA_DANCER_Y | |
792 | ||
793 | ||
794 | # AT_CHECK_DANCER(BISON-OPTIONS) | |
795 | # ------------------------------ | |
796 | # Generate the grammar, compile it, run it. | |
797 | m4_define([AT_CHECK_DANCER], | |
798 | [AT_SETUP([Dancer $1]) | |
799 | AT_BISON_OPTION_PUSHDEFS([$1]) | |
800 | _AT_DATA_DANCER_Y([$1]) | |
801 | AT_CHECK([bison -o dancer.c dancer.y]) | |
802 | AT_LALR1_CC_IF( | |
803 | [AT_CHECK([bison -o dancer.cc dancer.y]) | |
804 | AT_COMPILE_CXX([dancer])], | |
805 | [AT_CHECK([bison -o dancer.c dancer.y]) | |
806 | AT_COMPILE([dancer])]) | |
807 | AT_PARSER_CHECK([./dancer], 1, [], | |
808 | [syntax error, unexpected ':' | |
809 | ]) | |
810 | AT_BISON_OPTION_POPDEFS | |
811 | AT_CLEANUP | |
812 | ]) | |
813 | ||
814 | AT_CHECK_DANCER() | |
815 | AT_CHECK_DANCER([%glr-parser]) | |
816 | AT_CHECK_DANCER([%skeleton "lalr1.cc"]) |