]> git.saurik.com Git - bison.git/blob - tests/regression.at
Some actions of web2c.y are improperly triggered.
[bison.git] / tests / regression.at
1 # Bison Regressions. -*- Autotest -*-
2 # Copyright 2001 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., 59 Temple Place - Suite 330, Boston, MA
17 # 02111-1307, USA.
18
19 AT_BANNER([[Regression tests.]])
20
21 ## ------------------ ##
22 ## Duplicate string. ##
23 ## ------------------ ##
24
25
26 AT_SETUP([Duplicate string])
27
28 AT_DATA([duplicate.y],
29 [[/* `Bison -v' used to dump core when two tokens are defined with the same
30 string, as LE and GE below. */
31
32 %token NUM
33 %token LE "<="
34 %token GE "<="
35
36 %%
37 exp: '(' exp ')' | NUM ;
38 %%
39 ]])
40
41 AT_CHECK([bison -v duplicate.y -o duplicate.c], 0, ignore, ignore)
42
43 AT_CLEANUP
44
45
46 ## ------------------------- ##
47 ## Unresolved SR Conflicts. ##
48 ## ------------------------- ##
49
50 AT_SETUP([Unresolved SR Conflicts])
51
52 AT_DATA([input.y],
53 [[%token NUM OP
54 %%
55 exp: exp OP exp | NUM;
56 ]])
57
58 AT_CHECK([bison input.y -o input.c -v], 0, [],
59 [input.y contains 1 shift/reduce conflict.
60 ])
61
62 # Check the contents of the report.
63 AT_CHECK([cat input.output], [],
64 [[State 4 contains 1 shift/reduce conflict.
65
66
67 Grammar
68
69 Number, Line, Rule
70 1 3 exp -> exp OP exp
71 2 3 exp -> NUM
72
73
74 Terminals, with rules where they appear
75
76 $ (-1)
77 error (256)
78 NUM (257) 2
79 OP (258) 1
80
81
82 Nonterminals, with rules where they appear
83
84 exp (5)
85 on left: 1 2, on right: 1
86
87
88 state 0
89
90 NUM shift, and go to state 1
91
92 exp go to state 2
93
94
95
96 state 1
97
98 exp -> NUM . (rule 2)
99
100 $default reduce using rule 2 (exp)
101
102
103
104 state 2
105
106 exp -> exp . OP exp (rule 1)
107
108 $ go to state 5
109 OP shift, and go to state 3
110
111
112
113 state 3
114
115 exp -> exp OP . exp (rule 1)
116
117 NUM shift, and go to state 1
118
119 exp go to state 4
120
121
122
123 state 4
124
125 exp -> exp . OP exp (rule 1)
126 exp -> exp OP exp . (rule 1)
127
128 OP shift, and go to state 3
129
130 OP [reduce using rule 1 (exp)]
131 $default reduce using rule 1 (exp)
132
133
134
135 state 5
136
137 $ go to state 6
138
139
140
141 state 6
142
143 $default accept
144
145
146 ]])
147
148 AT_CLEANUP
149
150
151 ## --------------------- ##
152 ## Solved SR Conflicts. ##
153 ## --------------------- ##
154
155 AT_SETUP([Solved SR Conflicts])
156
157 AT_DATA([input.y],
158 [[%token NUM OP
159 %right OP
160 %%
161 exp: exp OP exp | NUM;
162 ]])
163
164 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
165
166 # Check the contents of the report.
167 AT_CHECK([cat input.output], [],
168 [[Conflict in state 4 between rule 1 and token OP resolved as shift.
169
170
171 Grammar
172
173 Number, Line, Rule
174 1 4 exp -> exp OP exp
175 2 4 exp -> NUM
176
177
178 Terminals, with rules where they appear
179
180 $ (-1)
181 error (256)
182 NUM (257) 2
183 OP (258) 1
184
185
186 Nonterminals, with rules where they appear
187
188 exp (5)
189 on left: 1 2, on right: 1
190
191
192 state 0
193
194 NUM shift, and go to state 1
195
196 exp go to state 2
197
198
199
200 state 1
201
202 exp -> NUM . (rule 2)
203
204 $default reduce using rule 2 (exp)
205
206
207
208 state 2
209
210 exp -> exp . OP exp (rule 1)
211
212 $ go to state 5
213 OP shift, and go to state 3
214
215
216
217 state 3
218
219 exp -> exp OP . exp (rule 1)
220
221 NUM shift, and go to state 1
222
223 exp go to state 4
224
225
226
227 state 4
228
229 exp -> exp . OP exp (rule 1)
230 exp -> exp OP exp . (rule 1)
231
232 OP shift, and go to state 3
233
234 $default reduce using rule 1 (exp)
235
236
237
238 state 5
239
240 $ go to state 6
241
242
243
244 state 6
245
246 $default accept
247
248
249 ]])
250
251 AT_CLEANUP
252
253
254
255
256 ## ------------------- ##
257 ## Rule Line Numbers. ##
258 ## ------------------- ##
259
260 AT_SETUP([Rule Line Numbers])
261
262 AT_DATA([input.y],
263 [[%%
264 expr:
265 'a'
266
267 {
268
269 }
270
271 'b'
272
273 {
274
275 }
276
277 |
278
279
280 {
281
282
283 }
284
285 'c'
286
287 {
288
289 }
290 ]])
291
292 AT_CHECK([bison input.y -o input.c -v], 0, [], [])
293
294 # Check the contents of the report.
295 AT_CHECK([cat input.output], [],
296 [[Grammar
297
298 Number, Line, Rule
299 1 2 @1 -> /* empty */
300 2 2 expr -> 'a' @1 'b'
301 3 15 @2 -> /* empty */
302 4 15 expr -> @2 'c'
303
304
305 Terminals, with rules where they appear
306
307 $ (-1)
308 'a' (97) 2
309 'b' (98) 2
310 'c' (99) 4
311 error (256)
312
313
314 Nonterminals, with rules where they appear
315
316 expr (6)
317 on left: 2 4
318 @1 (7)
319 on left: 1, on right: 2
320 @2 (8)
321 on left: 3, on right: 4
322
323
324 state 0
325
326 'a' shift, and go to state 1
327
328 $default reduce using rule 3 (@2)
329
330 expr go to state 6
331 @2 go to state 2
332
333
334
335 state 1
336
337 expr -> 'a' . @1 'b' (rule 2)
338
339 $default reduce using rule 1 (@1)
340
341 @1 go to state 3
342
343
344
345 state 2
346
347 expr -> @2 . 'c' (rule 4)
348
349 'c' shift, and go to state 4
350
351
352
353 state 3
354
355 expr -> 'a' @1 . 'b' (rule 2)
356
357 'b' shift, and go to state 5
358
359
360
361 state 4
362
363 expr -> @2 'c' . (rule 4)
364
365 $default reduce using rule 4 (expr)
366
367
368
369 state 5
370
371 expr -> 'a' @1 'b' . (rule 2)
372
373 $default reduce using rule 2 (expr)
374
375
376
377 state 6
378
379 $ go to state 7
380
381
382
383 state 7
384
385 $ go to state 8
386
387
388
389 state 8
390
391 $default accept
392
393
394 ]])
395
396 AT_CLEANUP
397
398
399
400 ## -------------------- ##
401 ## %expect not enough. ##
402 ## -------------------- ##
403
404 AT_SETUP([%expect not enough])
405
406 AT_DATA([input.y],
407 [[%token NUM OP
408 %expect 0
409 %%
410 exp: exp OP exp | NUM;
411 ]])
412
413 AT_CHECK([bison input.y -o input.c], 1, [],
414 [input.y contains 1 shift/reduce conflict.
415 expected 0 shift/reduce conflicts
416 ])
417 AT_CLEANUP
418
419
420 ## --------------- ##
421 ## %expect right. ##
422 ## --------------- ##
423
424 AT_SETUP([%expect right])
425
426 AT_DATA([input.y],
427 [[%token NUM OP
428 %expect 1
429 %%
430 exp: exp OP exp | NUM;
431 ]])
432
433 AT_CHECK([bison input.y -o input.c], 0)
434 AT_CLEANUP
435
436
437 ## ------------------ ##
438 ## %expect too much. ##
439 ## ------------------ ##
440
441 AT_SETUP([%expect too much])
442
443 AT_DATA([input.y],
444 [[%token NUM OP
445 %expect 2
446 %%
447 exp: exp OP exp | NUM;
448 ]])
449
450 AT_CHECK([bison input.y -o input.c], 1, [],
451 [input.y contains 1 shift/reduce conflict.
452 expected 2 shift/reduce conflicts
453 ])
454 AT_CLEANUP
455
456
457 ## ---------------------- ##
458 ## Mixing %token styles. ##
459 ## ---------------------- ##
460
461
462 AT_SETUP([Mixing %token styles])
463
464 # Taken from the documentation.
465 AT_DATA([input.y],
466 [[%token <operator> OR "||"
467 %token <operator> LE 134 "<="
468 %left OR "<="
469 %%
470 exp: ;
471 %%
472 ]])
473
474 AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
475
476 AT_CLEANUP
477
478
479
480 ## ---------------------- ##
481 ## %union and --defines. ##
482 ## ---------------------- ##
483
484
485 AT_SETUP([%union and --defines])
486
487 AT_DATA([union.y],
488 [%union
489 {
490 int integer;
491 char *string ;
492 }
493 %%
494 exp: {};
495 ])
496
497 AT_CHECK([bison --defines union.y])
498
499 AT_CLEANUP
500
501
502 ## --------------------------------------- ##
503 ## Duplicate '/' in C comments in %union ##
504 ## --------------------------------------- ##
505
506
507 AT_SETUP([%union and C comments])
508
509 AT_DATA([union-comment.y],
510 [%union
511 {
512 /* The int. */ int integer;
513 /* The string. */ char *string ;
514 }
515 %%
516 exp: {};
517 ])
518
519 AT_CHECK([bison union-comment.y])
520 AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
521
522 AT_CLEANUP
523
524
525 ## ----------------- ##
526 ## Invalid input 1. ##
527 ## ----------------- ##
528
529
530 AT_SETUP([Invalid input: 1])
531
532 AT_DATA([input.y],
533 [[%%
534 ?
535 ]])
536
537 AT_CHECK([bison input.y], [1], [],
538 [[input.y:2: invalid input: `?'
539 input.y:3: fatal error: no rules in the input grammar
540 ]])
541
542 AT_CLEANUP
543
544
545 ## ----------------- ##
546 ## Invalid input 2. ##
547 ## ----------------- ##
548
549
550 AT_SETUP([Invalid input: 2])
551
552 AT_DATA([input.y],
553 [[%%
554 default: 'a' }
555 ]])
556
557 AT_CHECK([bison input.y], [1], [],
558 [[input.y:2: invalid input: `}'
559 ]])
560
561 AT_CLEANUP
562
563
564
565 ## -------------------- ##
566 ## Invalid %directive. ##
567 ## -------------------- ##
568
569
570 AT_SETUP([Invalid %directive])
571
572 AT_DATA([input.y],
573 [[%invalid
574 ]])
575
576 AT_CHECK([bison input.y], [1], [],
577 [[input.y:1: unrecognized: %invalid
578 input.y:1: Skipping to next %
579 input.y:2: fatal error: no input grammar
580 ]])
581
582 AT_CLEANUP
583
584
585
586 ## --------------------- ##
587 ## Invalid CPP headers. ##
588 ## --------------------- ##
589
590 # AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
591 # -------------------------------------
592 m4_define([AT_TEST_CPP_GUARD_H],
593 [AT_SETUP([Invalid CPP guards: $1])
594
595 # Possibly create inner directories.
596 dirname=`AS_DIRNAME([$1])`
597 AS_MKDIR_P([$dirname])
598
599 AT_DATA([$1.y],
600 [%%
601 dummy:
602 ])
603
604 AT_CHECK([bison --defines=$1.h $1.y])
605
606 # CPP should be happy with it.
607 AT_CHECK([$CC -E $1.h], 0, [ignore])
608
609 AT_CLEANUP
610 ])
611
612 AT_TEST_CPP_GUARD_H([input/input])
613 AT_TEST_CPP_GUARD_H([9foo])
614
615
616
617 ## -------------- ##
618 ## Web2c Report. ##
619 ## -------------- ##
620
621 # The generation of the reduction was once wrong in Bison, and made it
622 # miss some reductions. In the following test case, the reduction on
623 # `undef_id_tok' in state 1 was missing. This is stripped down from
624 # the actual web2c.y.
625
626 AT_SETUP([Web2c Report])
627
628 AT_DATA([input.y],
629 [[%token undef_id_tok const_id_tok
630
631 %start CONST_DEC_PART
632 \f
633 %%
634 CONST_DEC_PART:
635 CONST_DEC_LIST
636 ;
637
638 CONST_DEC_LIST:
639 CONST_DEC
640 | CONST_DEC_LIST CONST_DEC
641 ;
642
643 CONST_DEC:
644 { } undef_id_tok '=' const_id_tok ';'
645 ;
646 %%
647
648 ]])
649
650 AT_CHECK([bison -v input.y])
651
652 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
653 [[Grammar
654 Number, Line, Rule
655 1 6 CONST_DEC_PART -> CONST_DEC_LIST
656 2 10 CONST_DEC_LIST -> CONST_DEC
657 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
658 4 15 @1 -> /* empty */
659 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
660 Terminals, with rules where they appear
661 $ (-1)
662 ';' (59) 5
663 '=' (61) 5
664 error (256)
665 undef_id_tok (257) 5
666 const_id_tok (258) 5
667 Nonterminals, with rules where they appear
668 CONST_DEC_PART (7)
669 on left: 1
670 CONST_DEC_LIST (8)
671 on left: 2 3, on right: 1 3
672 CONST_DEC (9)
673 on left: 5, on right: 2 3
674 @1 (10)
675 on left: 4, on right: 5
676 state 0
677 $default reduce using rule 4 (@1)
678 CONST_DEC_PART go to state 9
679 CONST_DEC_LIST go to state 1
680 CONST_DEC go to state 2
681 @1 go to state 3
682 state 1
683 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
684 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
685 undef_id_tok reduce using rule 4 (@1)
686 $default reduce using rule 1 (CONST_DEC_PART)
687 CONST_DEC go to state 4
688 @1 go to state 3
689 state 2
690 CONST_DEC_LIST -> CONST_DEC . (rule 2)
691 $default reduce using rule 2 (CONST_DEC_LIST)
692 state 3
693 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
694 undef_id_tok shift, and go to state 5
695 state 4
696 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
697 $default reduce using rule 3 (CONST_DEC_LIST)
698 state 5
699 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
700 '=' shift, and go to state 6
701 state 6
702 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
703 const_id_tok shift, and go to state 7
704 state 7
705 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
706 ';' shift, and go to state 8
707 state 8
708 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
709 $default reduce using rule 5 (CONST_DEC)
710 state 9
711 $ go to state 10
712 state 10
713 $ go to state 11
714 state 11
715 $default accept
716 ]])
717
718 AT_CLEANUP
719
720
721 ## --------------- ##
722 ## Web2c Actions. ##
723 ## --------------- ##
724
725 # The generation of the mapping `state -> action' was once wrong in
726 # extremely specific situations. web2c.y exhibits this situation.
727 # Below is a stripped version of the grammar. It looks like one can
728 # simplify it further, but just don't: it is tuned to exhibit a bug,
729 # which disapears when applying sane grammar transformations.
730 #
731 # It used to be wrong on yydefact only:
732 #
733 # static const short yydefact[] =
734 # {
735 # - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
736 # + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
737 # 0, 0
738 # };
739 #
740 # but let's check all the tables.
741
742
743 AT_SETUP([Web2c Actions])
744
745 AT_DATA([input.y],
746 [[%%
747 statement: struct_stat;
748 struct_stat: /* empty. */ | if else;
749 if: "if" "const" "then" statement;
750 else: "else" statement;
751 %%
752 ]])
753
754 AT_CHECK([bison -v input.y -o input.c])
755
756 # Check only the tables. We don't use --no-parser, because it is
757 # still to be implemented in the experimental branch of Bison.
758 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
759 [[static const char yytranslate[] =
760 {
761 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
763 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
764 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
765 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
766 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
767 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
768 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
769 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
770 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
771 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
772 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
773 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
774 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
775 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
776 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
777 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
778 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
779 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
780 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
781 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
782 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
783 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
784 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
785 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
786 2, 2, 2, 2, 2, 2, 1, 3, 4, 5,
787 6
788 };
789 static const short yyprhs[] =
790 {
791 0, 0, 2, 3, 6, 11
792 };
793 static const short yyrhs[] =
794 {
795 8, 0, 0, 9, 10, 0, 3, 4, 5, 7,
796 0, 6, 7, 0
797 };
798 static const short yyrline[] =
799 {
800 0, 2, 3, 3, 4, 5
801 };
802 static const char *const yytname[] =
803 {
804 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
805 "\"else\"", "statement", "struct_stat", "if", "else", NULL
806 };
807 static const short yyr1[] =
808 {
809 0, 7, 8, 8, 9, 10
810 };
811 static const short yyr2[] =
812 {
813 0, 1, 0, 2, 4, 2
814 };
815 static const short yydefact[] =
816 {
817 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
818 0, 0, 0
819 };
820 static const short yydefgoto[] =
821 {
822 8, 2, 3, 6
823 };
824 static const short yypact[] =
825 {
826 -2, -1,-32768, -4, 1, -2,-32768, -2,-32768,-32768,
827 4, 5,-32768
828 };
829 static const short yypgoto[] =
830 {
831 0,-32768,-32768,-32768
832 };
833 static const short yytable[] =
834 {
835 10, 1, 5, 4, 11, 12, 7, 9
836 };
837 static const short yycheck[] =
838 {
839 0, 3, 6, 4, 0, 0, 5, 7
840 };
841 ]])
842
843 AT_CLEANUP