]> git.saurik.com Git - bison.git/blame - tests/regression.at
* src/output.c (output_unsigned_int_table): New.
[bison.git] / tests / regression.at
CommitLineData
342b8b6e 1# Bison Regressions. -*- Autotest -*-
3c31a486 2# Copyright 2001, 2002 Free Software Foundation, Inc.
c95f2d78 3
342b8b6e
AD
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.
c95f2d78 8
342b8b6e
AD
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.
c95f2d78 13
342b8b6e
AD
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.
c95f2d78 18
342b8b6e 19AT_BANNER([[Regression tests.]])
c95f2d78 20
2b25d624
AD
21
22## ---------------- ##
23## Braces parsing. ##
24## ---------------- ##
25
26
27AT_SETUP([braces parsing])
28
29AT_DATA([input.y],
30[[/* Bison used to swallow the character after `}'. */
31
32%%
bfcf1f3a 33exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
2b25d624
AD
34%%
35]])
36
37AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
38
39AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
40
41AT_CLEANUP
42
43
c95f2d78
AD
44## ------------------ ##
45## Duplicate string. ##
46## ------------------ ##
47
48
49AT_SETUP([Duplicate string])
50
f499b062 51AT_DATA([input.y],
c95f2d78
AD
52[[/* `Bison -v' used to dump core when two tokens are defined with the same
53 string, as LE and GE below. */
54
55%token NUM
56%token LE "<="
57%token GE "<="
58
59%%
60exp: '(' exp ')' | NUM ;
61%%
62]])
63
f499b062 64AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
c95f2d78 65
d803322e 66AT_CLEANUP
c95f2d78
AD
67
68
2ca209c1
AD
69## ------------------- ##
70## Rule Line Numbers. ##
71## ------------------- ##
72
73AT_SETUP([Rule Line Numbers])
74
75AT_DATA([input.y],
76[[%%
77expr:
78'a'
79
80{
81
82}
83
84'b'
85
86{
87
88}
89
90|
91
92
93{
94
95
96}
97
98'c'
99
100{
101
bfcf1f3a 102};
2ca209c1
AD
103]])
104
105AT_CHECK([bison input.y -o input.c -v], 0, [], [])
106
107# Check the contents of the report.
108AT_CHECK([cat input.output], [],
d2d1b42b 109[[Grammar
2ca209c1
AD
110
111 Number, Line, Rule
ff442794 112 0 2 $axiom -> expr $
2ca209c1
AD
113 1 2 @1 -> /* empty */
114 2 2 expr -> 'a' @1 'b'
115 3 15 @2 -> /* empty */
116 4 15 expr -> @2 'c'
117
d2d1b42b 118
2ca209c1
AD
119Terminals, with rules where they appear
120
b365aa05 121$ (0) 0
2ca209c1
AD
122'a' (97) 2
123'b' (98) 2
124'c' (99) 4
125error (256)
126
d2d1b42b 127
2ca209c1
AD
128Nonterminals, with rules where they appear
129
b365aa05
AD
130$axiom (6)
131 on left: 0
132expr (7)
133 on left: 2 4, on right: 0
134@1 (8)
2ca209c1 135 on left: 1, on right: 2
b365aa05 136@2 (9)
2ca209c1
AD
137 on left: 3, on right: 4
138
139
140state 0
141
643a5994
AD
142 $axiom -> . expr $ (rule 0)
143
2ca209c1
AD
144 'a' shift, and go to state 1
145
610ab194
AD
146 $default reduce using rule 3 (@2)
147
b365aa05
AD
148 expr go to state 2
149 @2 go to state 3
2ca209c1
AD
150
151
152
153state 1
154
155 expr -> 'a' . @1 'b' (rule 2)
156
157 $default reduce using rule 1 (@1)
158
b365aa05 159 @1 go to state 4
2ca209c1
AD
160
161
162
163state 2
164
b365aa05 165 $axiom -> expr . $ (rule 0)
2ca209c1 166
b365aa05 167 $ shift, and go to state 5
2ca209c1
AD
168
169
170
171state 3
172
b365aa05 173 expr -> @2 . 'c' (rule 4)
2ca209c1 174
b365aa05 175 'c' shift, and go to state 6
2ca209c1
AD
176
177
178
179state 4
180
b365aa05 181 expr -> 'a' @1 . 'b' (rule 2)
2ca209c1 182
b365aa05 183 'b' shift, and go to state 7
2ca209c1
AD
184
185
186
187state 5
188
b365aa05 189 $axiom -> expr $ . (rule 0)
2ca209c1 190
b365aa05 191 $default accept
2ca209c1
AD
192
193
194state 6
195
b365aa05
AD
196 expr -> @2 'c' . (rule 4)
197
198 $default reduce using rule 4 (expr)
2ca209c1
AD
199
200
201
202state 7
203
b365aa05
AD
204 expr -> 'a' @1 'b' . (rule 2)
205
206 $default reduce using rule 2 (expr)
207
d2d1b42b
AD
208
209
2ca209c1
AD
210]])
211
212AT_CLEANUP
213
214
215
cd5aafcf
AD
216## ---------------------- ##
217## Mixing %token styles. ##
218## ---------------------- ##
219
220
221AT_SETUP([Mixing %token styles])
222
223# Taken from the documentation.
224AT_DATA([input.y],
225[[%token <operator> OR "||"
226%token <operator> LE 134 "<="
227%left OR "<="
228%%
229exp: ;
230%%
231]])
232
233AT_CHECK([bison -v input.y -o input.c], 0, ignore, ignore)
234
d803322e 235AT_CLEANUP
cd5aafcf
AD
236
237
238
29ae55f1
AD
239## ---------------- ##
240## Invalid inputs. ##
241## ---------------- ##
561f9a30
AD
242
243
29ae55f1 244AT_SETUP([Invalid inputs])
561f9a30
AD
245
246AT_DATA([input.y],
247[[%%
248?
561f9a30 249default: 'a' }
29ae55f1
AD
250%{
251%&
252%a
253%-
561f9a30
AD
254]])
255
256AT_CHECK([bison input.y], [1], [],
29ae55f1
AD
257[[input.y:2: invalid input: `?'
258input.y:3: invalid input: `}'
259input.y:4: invalid input: `%{'
260input.y:5: invalid input: `%&'
261input.y:6: invalid input: `%a'
262input.y:7: invalid input: `%-'
e0c40012
AD
263]])
264
265AT_CLEANUP
266
267
268
269## -------------------- ##
270## Invalid %directive. ##
271## -------------------- ##
272
273
274AT_SETUP([Invalid %directive])
275
276AT_DATA([input.y],
277[[%invalid
278]])
279
280AT_CHECK([bison input.y], [1], [],
281[[input.y:1: unrecognized: %invalid
282input.y:1: Skipping to next %
283input.y:2: fatal error: no input grammar
284]])
561f9a30
AD
285
286AT_CLEANUP
287
288
270a173c 289
b87f8b21
AD
290## ------------------- ##
291## Token definitions. ##
292## ------------------- ##
293
294
295AT_SETUP([Token definitions])
296
297# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
298AT_DATA([input.y],
299[[%token "end of file"
300%token 'a' "a"
301%token "b" 'b'
302%token "c" c
303%token d "d"
304%token e 'e'
305%token 'f' e
306%%
307exp: "a";
308]])
309
310AT_CHECK([bison input.y -o input.c])
311AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
312AT_CLEANUP
313
314
315
b9752825
AD
316## -------------- ##
317## Web2c Report. ##
318## -------------- ##
776209d6
AD
319
320# The generation of the reduction was once wrong in Bison, and made it
321# miss some reductions. In the following test case, the reduction on
322# `undef_id_tok' in state 1 was missing. This is stripped down from
323# the actual web2c.y.
324
b9752825 325AT_SETUP([Web2c Report])
776209d6
AD
326
327AT_DATA([input.y],
328[[%token undef_id_tok const_id_tok
329
330%start CONST_DEC_PART
331\f
332%%
333CONST_DEC_PART:
334 CONST_DEC_LIST
335 ;
336
337CONST_DEC_LIST:
338 CONST_DEC
339 | CONST_DEC_LIST CONST_DEC
340 ;
341
342CONST_DEC:
343 { } undef_id_tok '=' const_id_tok ';'
344 ;
345%%
346
347]])
348
349AT_CHECK([bison -v input.y])
350
351AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
352[[Grammar
353 Number, Line, Rule
78d5bae9 354 0 6 $axiom -> CONST_DEC_PART $
776209d6
AD
355 1 6 CONST_DEC_PART -> CONST_DEC_LIST
356 2 10 CONST_DEC_LIST -> CONST_DEC
357 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
358 4 15 @1 -> /* empty */
359 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
360Terminals, with rules where they appear
78d5bae9 361$ (0) 0
776209d6
AD
362';' (59) 5
363'=' (61) 5
364error (256)
007a50a4
AD
365undef_id_tok (258) 5
366const_id_tok (259) 5
776209d6 367Nonterminals, with rules where they appear
78d5bae9
AD
368$axiom (7)
369 on left: 0
370CONST_DEC_PART (8)
371 on left: 1, on right: 0
372CONST_DEC_LIST (9)
776209d6 373 on left: 2 3, on right: 1 3
78d5bae9 374CONST_DEC (10)
776209d6 375 on left: 5, on right: 2 3
78d5bae9 376@1 (11)
776209d6
AD
377 on left: 4, on right: 5
378state 0
643a5994 379 $axiom -> . CONST_DEC_PART $ (rule 0)
776209d6 380 $default reduce using rule 4 (@1)
78d5bae9
AD
381 CONST_DEC_PART go to state 1
382 CONST_DEC_LIST go to state 2
383 CONST_DEC go to state 3
384 @1 go to state 4
776209d6 385state 1
78d5bae9
AD
386 $axiom -> CONST_DEC_PART . $ (rule 0)
387 $ shift, and go to state 5
388state 2
776209d6
AD
389 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
390 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
391 undef_id_tok reduce using rule 4 (@1)
392 $default reduce using rule 1 (CONST_DEC_PART)
78d5bae9
AD
393 CONST_DEC go to state 6
394 @1 go to state 4
395state 3
776209d6
AD
396 CONST_DEC_LIST -> CONST_DEC . (rule 2)
397 $default reduce using rule 2 (CONST_DEC_LIST)
776209d6 398state 4
78d5bae9
AD
399 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
400 undef_id_tok shift, and go to state 7
401state 5
402 $axiom -> CONST_DEC_PART $ . (rule 0)
403 $default accept
404state 6
776209d6
AD
405 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
406 $default reduce using rule 3 (CONST_DEC_LIST)
78d5bae9 407state 7
776209d6 408 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
78d5bae9
AD
409 '=' shift, and go to state 8
410state 8
776209d6 411 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
78d5bae9
AD
412 const_id_tok shift, and go to state 9
413state 9
776209d6 414 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
78d5bae9
AD
415 ';' shift, and go to state 10
416state 10
776209d6
AD
417 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
418 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
419]])
420
421AT_CLEANUP
b9752825
AD
422
423
424## --------------- ##
425## Web2c Actions. ##
426## --------------- ##
427
428# The generation of the mapping `state -> action' was once wrong in
429# extremely specific situations. web2c.y exhibits this situation.
430# Below is a stripped version of the grammar. It looks like one can
431# simplify it further, but just don't: it is tuned to exhibit a bug,
432# which disapears when applying sane grammar transformations.
433#
434# It used to be wrong on yydefact only:
435#
436# static const short yydefact[] =
437# {
438# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
439# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
440# 0, 0
441# };
442#
443# but let's check all the tables.
444
445
446AT_SETUP([Web2c Actions])
447
448AT_DATA([input.y],
449[[%%
450statement: struct_stat;
451struct_stat: /* empty. */ | if else;
452if: "if" "const" "then" statement;
453else: "else" statement;
454%%
455]])
456
457AT_CHECK([bison -v input.y -o input.c])
458
459# Check only the tables. We don't use --no-parser, because it is
460# still to be implemented in the experimental branch of Bison.
461AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
680e8701 462[[static const yy_token_number_type yytranslate[] =
b9752825
AD
463{
464 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
465 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
466 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
467 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
468 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
469 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
470 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
471 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
472 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
473 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
474 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
475 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
476 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
477 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
478 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
479 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
480 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
481 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
482 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
483 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
484 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
485 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
486 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
487 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
488 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
007a50a4
AD
489 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
490 5, 6
b9752825 491};
5df5f6d5 492static const unsigned char yyprhs[] =
b9752825 493{
e7b8bef1 494 0, 0, 3, 5, 6, 9, 14
b9752825 495};
5df5f6d5 496static const signed char yyrhs[] =
b9752825 497{
e7b8bef1
AD
498 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
499 4, 5, 8, -1, 6, 8, -1
b9752825 500};
5df5f6d5 501static const unsigned char yyrline[] =
b9752825 502{
e7b8bef1 503 0, 2, 2, 3, 3, 4, 5
b9752825
AD
504};
505static const char *const yytname[] =
506{
507 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
80cce3da 508 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
b9752825
AD
509};
510static const short yytoknum[] =
511{
007a50a4 512 0, 256, 257, 258, 259, 260, 261, -1
b9752825 513};
9515e8a7 514static const yy_token_number_type yyr1[] =
b9752825 515{
e7b8bef1 516 0, 7, 8, 9, 9, 10, 11
b9752825 517};
5df5f6d5 518static const unsigned char yyr2[] =
b9752825 519{
e7b8bef1 520 0, 2, 1, 0, 2, 4, 2
b9752825
AD
521};
522static const short yydefact[] =
523{
e7b8bef1
AD
524 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
525 6, 5
b9752825
AD
526};
527static const short yydefgoto[] =
528{
e7b8bef1 529 -1, 2, 3, 4, 8
b9752825
AD
530};
531static const short yypact[] =
532{
e7b8bef1
AD
533 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
534 -32768,-32768
b9752825
AD
535};
536static const short yypgoto[] =
537{
e7b8bef1 538 -32768, -7,-32768,-32768,-32768
b9752825
AD
539};
540static const short yytable[] =
541{
e7b8bef1 542 10, 1, 11, 5, 6, 0, 7, 9
b9752825
AD
543};
544static const short yycheck[] =
545{
e7b8bef1 546 7, 3, 9, 4, 0, -1, 6, 5
b9752825
AD
547};
548]])
549
550AT_CLEANUP