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