]> git.saurik.com Git - bison.git/blame_incremental - tests/regression.at
* src/LR0.c (augment_automaton): Now that all states have shifts,
[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([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%%
37exp: '(' exp ')' | NUM ;
38%%
39]])
40
41AT_CHECK([bison -v duplicate.y -o duplicate.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 4 contains 1 shift/reduce conflict.
65
66
67Grammar
68
69 Number, Line, Rule
70 1 3 exp -> exp OP exp
71 2 3 exp -> NUM
72
73
74Terminals, with rules where they appear
75
76$ (-1)
77error (256)
78NUM (257) 2
79OP (258) 1
80
81
82Nonterminals, with rules where they appear
83
84exp (5)
85 on left: 1 2, on right: 1
86
87
88state 0
89
90 NUM shift, and go to state 1
91
92 exp go to state 2
93
94
95
96state 1
97
98 exp -> NUM . (rule 2)
99
100 $default reduce using rule 2 (exp)
101
102
103
104state 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
113state 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
123state 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
135state 5
136
137 $ go to state 6
138
139
140
141state 6
142
143 $default accept
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 4 between rule 1 and token OP resolved as shift.
169
170
171Grammar
172
173 Number, Line, Rule
174 1 4 exp -> exp OP exp
175 2 4 exp -> NUM
176
177
178Terminals, with rules where they appear
179
180$ (-1)
181error (256)
182NUM (257) 2
183OP (258) 1
184
185
186Nonterminals, with rules where they appear
187
188exp (5)
189 on left: 1 2, on right: 1
190
191
192state 0
193
194 NUM shift, and go to state 1
195
196 exp go to state 2
197
198
199
200state 1
201
202 exp -> NUM . (rule 2)
203
204 $default reduce using rule 2 (exp)
205
206
207
208state 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
217state 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
227state 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
238state 5
239
240 $ go to state 6
241
242
243
244state 6
245
246 $default accept
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 1 2 @1 -> /* empty */
300 2 2 expr -> 'a' @1 'b'
301 3 15 @2 -> /* empty */
302 4 15 expr -> @2 'c'
303
304
305Terminals, with rules where they appear
306
307$ (-1)
308'a' (97) 2
309'b' (98) 2
310'c' (99) 4
311error (256)
312
313
314Nonterminals, with rules where they appear
315
316expr (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
324state 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
335state 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
345state 2
346
347 expr -> @2 . 'c' (rule 4)
348
349 'c' shift, and go to state 4
350
351
352
353state 3
354
355 expr -> 'a' @1 . 'b' (rule 2)
356
357 'b' shift, and go to state 5
358
359
360
361state 4
362
363 expr -> @2 'c' . (rule 4)
364
365 $default reduce using rule 4 (expr)
366
367
368
369state 5
370
371 expr -> 'a' @1 'b' . (rule 2)
372
373 $default reduce using rule 2 (expr)
374
375
376
377state 6
378
379 $ go to state 7
380
381
382
383state 7
384
385 $ go to state 8
386
387
388
389state 8
390
391 $default accept
392
393
394]])
395
396AT_CLEANUP
397
398
399
400## -------------------- ##
401## %expect not enough. ##
402## -------------------- ##
403
404AT_SETUP([%expect not enough])
405
406AT_DATA([input.y],
407[[%token NUM OP
408%expect 0
409%%
410exp: exp OP exp | NUM;
411]])
412
413AT_CHECK([bison input.y -o input.c], 1, [],
414[input.y contains 1 shift/reduce conflict.
415expected 0 shift/reduce conflicts
416])
417AT_CLEANUP
418
419
420## --------------- ##
421## %expect right. ##
422## --------------- ##
423
424AT_SETUP([%expect right])
425
426AT_DATA([input.y],
427[[%token NUM OP
428%expect 1
429%%
430exp: exp OP exp | NUM;
431]])
432
433AT_CHECK([bison input.y -o input.c], 0)
434AT_CLEANUP
435
436
437## ------------------ ##
438## %expect too much. ##
439## ------------------ ##
440
441AT_SETUP([%expect too much])
442
443AT_DATA([input.y],
444[[%token NUM OP
445%expect 2
446%%
447exp: exp OP exp | NUM;
448]])
449
450AT_CHECK([bison input.y -o input.c], 1, [],
451[input.y contains 1 shift/reduce conflict.
452expected 2 shift/reduce conflicts
453])
454AT_CLEANUP
455
456
457## ---------------------- ##
458## Mixing %token styles. ##
459## ---------------------- ##
460
461
462AT_SETUP([Mixing %token styles])
463
464# Taken from the documentation.
465AT_DATA([input.y],
466[[%token <operator> OR "||"
467%token <operator> LE 134 "<="
468%left OR "<="
469%%
470exp: ;
471%%
472]])
473
474AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
475
476AT_CLEANUP
477
478
479
480## ---------------------- ##
481## %union and --defines. ##
482## ---------------------- ##
483
484
485AT_SETUP([%union and --defines])
486
487AT_DATA([union.y],
488[%union
489{
490 int integer;
491 char *string ;
492}
493%%
494exp: {};
495])
496
497AT_CHECK([bison --defines union.y])
498
499AT_CLEANUP
500
501
502## --------------------------------------- ##
503## Duplicate '/' in C comments in %union ##
504## --------------------------------------- ##
505
506
507AT_SETUP([%union and C comments])
508
509AT_DATA([union-comment.y],
510[%union
511{
512 /* The int. */ int integer;
513 /* The string. */ char *string ;
514}
515%%
516exp: {};
517])
518
519AT_CHECK([bison union-comment.y])
520AT_CHECK([fgrep '//*' union-comment.tab.c], [1], [])
521
522AT_CLEANUP
523
524
525## ----------------- ##
526## Invalid input 1. ##
527## ----------------- ##
528
529
530AT_SETUP([Invalid input: 1])
531
532AT_DATA([input.y],
533[[%%
534?
535]])
536
537AT_CHECK([bison input.y], [1], [],
538[[input.y:2: invalid input: `?'
539input.y:3: fatal error: no rules in the input grammar
540]])
541
542AT_CLEANUP
543
544
545## ----------------- ##
546## Invalid input 2. ##
547## ----------------- ##
548
549
550AT_SETUP([Invalid input: 2])
551
552AT_DATA([input.y],
553[[%%
554default: 'a' }
555]])
556
557AT_CHECK([bison input.y], [1], [],
558[[input.y:2: invalid input: `}'
559]])
560
561AT_CLEANUP
562
563
564
565## -------------------- ##
566## Invalid %directive. ##
567## -------------------- ##
568
569
570AT_SETUP([Invalid %directive])
571
572AT_DATA([input.y],
573[[%invalid
574]])
575
576AT_CHECK([bison input.y], [1], [],
577[[input.y:1: unrecognized: %invalid
578input.y:1: Skipping to next %
579input.y:2: fatal error: no input grammar
580]])
581
582AT_CLEANUP
583
584
585
586## --------------------- ##
587## Invalid CPP headers. ##
588## --------------------- ##
589
590# AT_TEST_CPP_GUARD_H([INPUT-FILE-BASE)
591# -------------------------------------
592m4_define([AT_TEST_CPP_GUARD_H],
593[AT_SETUP([Invalid CPP guards: $1])
594
595# Possibly create inner directories.
596dirname=`AS_DIRNAME([$1])`
597AS_MKDIR_P([$dirname])
598
599AT_DATA([$1.y],
600[%%
601dummy:
602])
603
604AT_CHECK([bison --defines=$1.h $1.y])
605
606# CPP should be happy with it.
607AT_CHECK([$CC -E $1.h], 0, [ignore])
608
609AT_CLEANUP
610])
611
612AT_TEST_CPP_GUARD_H([input/input])
613AT_TEST_CPP_GUARD_H([9foo])
614
615
616## ---------------- ##
617## Broken Closure. ##
618## ---------------- ##
619
620# TC was once broken during a massive `simplification' of the code.
621# It resulted in bison dumping core on the following grammar (the
622# computation of FIRSTS uses TC). It managed to produce a pretty
623# exotic closure:
624#
625# TC: Input
626#
627# 01234567
628# +--------+
629# 0| 1 |
630# 1| 1 |
631# 2| 1 |
632# 3| 1 |
633# 4| 1 |
634# 5| 1 |
635# 6| 1|
636# 7| |
637# +--------+
638#
639# TC: Output
640#
641# 01234567
642# +--------+
643# 0| 1 |
644# 1| 111 |
645# 2| 111 |
646# 3| 1111 |
647# 4| 111 1 |
648# 5| 111 1 |
649# 6| 111 1|
650# 7| 111 |
651# +--------+
652#
653# instead of that below.
654
655AT_SETUP([Broken Closure])
656
657AT_DATA([input.y],
658[[%%
659a: b
660b: c
661c: d
662d: e
663e: f
664f: g
665g: h
666h: 'h'
667]])
668
669AT_CHECK([bison --trace input.y 2>&1 |
670 sed -n '/^TC: Output BEGIN/,/^TC: Output END/p'],
671 [0],
672[[TC: Output BEGIN
673 @&t@
674 01234567
675 +--------+
676 0| 1111111|
677 1| 111111|
678 2| 11111|
679 3| 1111|
680 4| 111|
681 5| 11|
682 6| 1|
683 7| |
684 +--------+
685TC: Output END
686]])
687
688AT_CLEANUP