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