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