]> git.saurik.com Git - bison.git/blame - tests/regression.at
* src/closure.c (print_fderives): Use rule_rhs_print.
[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])
1154cced 54AT_COMPILE([input], [-c input.c])
69078d4b
AD
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
ce4ccb4b 187 0 $axiom: . expr $
643a5994 188
87675353 189 'a' shift, and go to state 1
2ca209c1 190
87675353 191 $default reduce using rule 3 (@2)
2ca209c1 192
87675353
AD
193 expr go to state 2
194 @2 go to state 3
2ca209c1
AD
195
196
197state 1
198
ce4ccb4b 199 2 expr: 'a' . @1 'b'
2ca209c1 200
87675353 201 $default reduce using rule 1 (@1)
2ca209c1 202
87675353 203 @1 go to state 4
2ca209c1
AD
204
205
206state 2
207
ce4ccb4b 208 0 $axiom: expr . $
2ca209c1 209
87675353 210 $ shift, and go to state 5
2ca209c1
AD
211
212
213state 3
214
ce4ccb4b 215 4 expr: @2 . 'c'
2ca209c1 216
87675353 217 'c' shift, and go to state 6
2ca209c1
AD
218
219
220state 4
221
ce4ccb4b 222 2 expr: 'a' @1 . 'b'
2ca209c1 223
87675353 224 'b' shift, and go to state 7
2ca209c1
AD
225
226
227state 5
228
ce4ccb4b 229 0 $axiom: expr $ .
2ca209c1 230
b365aa05 231 $default accept
2ca209c1
AD
232
233
234state 6
235
ce4ccb4b 236 4 expr: @2 'c' .
b365aa05 237
87675353 238 $default reduce using rule 4 (expr)
2ca209c1
AD
239
240
241state 7
242
ce4ccb4b 243 2 expr: 'a' @1 'b' .
b365aa05 244
87675353 245 $default reduce using rule 2 (expr)
2ca209c1
AD
246]])
247
248AT_CLEANUP
249
250
251
cd5aafcf
AD
252## ---------------------- ##
253## Mixing %token styles. ##
254## ---------------------- ##
255
256
257AT_SETUP([Mixing %token styles])
258
259# Taken from the documentation.
260AT_DATA([input.y],
261[[%token <operator> OR "||"
262%token <operator> LE 134 "<="
263%left OR "<="
264%%
265exp: ;
266%%
267]])
268
69078d4b 269AT_CHECK([bison -v input.y -o input.c])
cd5aafcf 270
d803322e 271AT_CLEANUP
cd5aafcf
AD
272
273
274
29ae55f1
AD
275## ---------------- ##
276## Invalid inputs. ##
277## ---------------- ##
561f9a30
AD
278
279
29ae55f1 280AT_SETUP([Invalid inputs])
561f9a30
AD
281
282AT_DATA([input.y],
283[[%%
284?
561f9a30 285default: 'a' }
29ae55f1
AD
286%&
287%a
288%-
e9955c83 289%{
561f9a30
AD
290]])
291
292AT_CHECK([bison input.y], [1], [],
e9955c83
AD
293[[input.y:2.1: invalid character: `?'
294input.y:3.14: invalid character: `}'
295input.y:4.1: invalid character: `%'
296input.y:4.2: invalid character: `&'
297input.y:5.1: invalid character: `%'
298input.y:6.1: invalid character: `%'
299input.y:6.2: invalid character: `-'
300input.y:7.1-8.0: unexpected end of file in a prologue
301input.y:7.1-8.0: parse error, unexpected PROLOGUE, expecting ";" or "|"
ee000ba4 302input.y:5.2: symbol a is used, but is not defined as a token and has no rules
e0c40012 303]])
561f9a30
AD
304
305AT_CLEANUP
306
307
270a173c 308
b87f8b21
AD
309## ------------------- ##
310## Token definitions. ##
311## ------------------- ##
312
313
314AT_SETUP([Token definitions])
315
316# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
317AT_DATA([input.y],
db7c8e9a
AD
318[%{
319void yyerror (const char *s);
320int yylex (void);
321%}
e9955c83 322[%token YYEOF 0 "end of file"
b87f8b21 323%token 'a' "a"
e9955c83
AD
324%token b "b"
325%token c 'c'
326%token 'd' d
b87f8b21
AD
327%%
328exp: "a";
329]])
330
331AT_CHECK([bison input.y -o input.c])
1154cced 332AT_COMPILE([input], [input.c -c])
b87f8b21
AD
333AT_CLEANUP
334
335
336
b9752825
AD
337## -------------- ##
338## Web2c Report. ##
339## -------------- ##
776209d6
AD
340
341# The generation of the reduction was once wrong in Bison, and made it
342# miss some reductions. In the following test case, the reduction on
343# `undef_id_tok' in state 1 was missing. This is stripped down from
344# the actual web2c.y.
345
b9752825 346AT_SETUP([Web2c Report])
776209d6 347
6b98e4b5
AD
348AT_KEYWORDS([report])
349
776209d6
AD
350AT_DATA([input.y],
351[[%token undef_id_tok const_id_tok
352
353%start CONST_DEC_PART
354\f
355%%
356CONST_DEC_PART:
357 CONST_DEC_LIST
358 ;
359
360CONST_DEC_LIST:
361 CONST_DEC
362 | CONST_DEC_LIST CONST_DEC
363 ;
364
365CONST_DEC:
366 { } undef_id_tok '=' const_id_tok ';'
367 ;
368%%
776209d6
AD
369]])
370
371AT_CHECK([bison -v input.y])
87675353 372AT_CHECK([cat input.output], 0,
776209d6 373[[Grammar
87675353 374
6b98e4b5 375 0 $axiom: CONST_DEC_PART $
87675353 376
6b98e4b5 377 1 CONST_DEC_PART: CONST_DEC_LIST
87675353 378
6b98e4b5
AD
379 2 CONST_DEC_LIST: CONST_DEC
380 3 | CONST_DEC_LIST CONST_DEC
87675353 381
6b98e4b5 382 4 @1: /* empty */
87675353 383
6b98e4b5 384 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
87675353
AD
385
386
776209d6 387Terminals, with rules where they appear
87675353 388
78d5bae9 389$ (0) 0
776209d6
AD
390';' (59) 5
391'=' (61) 5
392error (256)
007a50a4
AD
393undef_id_tok (258) 5
394const_id_tok (259) 5
87675353
AD
395
396
776209d6 397Nonterminals, with rules where they appear
87675353 398
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 408 on left: 4, on right: 5
87675353
AD
409
410
776209d6 411state 0
87675353 412
ce4ccb4b 413 0 $axiom: . CONST_DEC_PART $
87675353
AD
414
415 $default reduce using rule 4 (@1)
416
417 CONST_DEC_PART go to state 1
418 CONST_DEC_LIST go to state 2
419 CONST_DEC go to state 3
420 @1 go to state 4
421
422
776209d6 423state 1
87675353 424
ce4ccb4b 425 0 $axiom: CONST_DEC_PART . $
87675353
AD
426
427 $ shift, and go to state 5
428
429
78d5bae9 430state 2
87675353 431
ce4ccb4b
AD
432 1 CONST_DEC_PART: CONST_DEC_LIST .
433 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
87675353
AD
434
435 undef_id_tok reduce using rule 4 (@1)
436 $default reduce using rule 1 (CONST_DEC_PART)
437
438 CONST_DEC go to state 6
439 @1 go to state 4
440
441
78d5bae9 442state 3
87675353 443
ce4ccb4b 444 2 CONST_DEC_LIST: CONST_DEC .
87675353
AD
445
446 $default reduce using rule 2 (CONST_DEC_LIST)
447
448
776209d6 449state 4
87675353 450
ce4ccb4b 451 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
87675353
AD
452
453 undef_id_tok shift, and go to state 7
454
455
78d5bae9 456state 5
87675353 457
ce4ccb4b 458 0 $axiom: CONST_DEC_PART $ .
87675353 459
78d5bae9 460 $default accept
87675353
AD
461
462
78d5bae9 463state 6
87675353 464
ce4ccb4b 465 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
87675353
AD
466
467 $default reduce using rule 3 (CONST_DEC_LIST)
468
469
78d5bae9 470state 7
87675353 471
ce4ccb4b 472 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
87675353
AD
473
474 '=' shift, and go to state 8
475
476
78d5bae9 477state 8
87675353 478
ce4ccb4b 479 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
87675353
AD
480
481 const_id_tok shift, and go to state 9
482
483
78d5bae9 484state 9
87675353 485
ce4ccb4b 486 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
87675353
AD
487
488 ';' shift, and go to state 10
489
490
78d5bae9 491state 10
87675353 492
ce4ccb4b 493 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
87675353
AD
494
495 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
496]])
497
498AT_CLEANUP
b9752825
AD
499
500
501## --------------- ##
502## Web2c Actions. ##
503## --------------- ##
504
505# The generation of the mapping `state -> action' was once wrong in
506# extremely specific situations. web2c.y exhibits this situation.
507# Below is a stripped version of the grammar. It looks like one can
508# simplify it further, but just don't: it is tuned to exhibit a bug,
509# which disapears when applying sane grammar transformations.
510#
511# It used to be wrong on yydefact only:
512#
513# static const short yydefact[] =
514# {
515# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
516# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
517# 0, 0
518# };
519#
520# but let's check all the tables.
521
522
523AT_SETUP([Web2c Actions])
524
6b98e4b5
AD
525AT_KEYWORDS([report])
526
b9752825
AD
527AT_DATA([input.y],
528[[%%
529statement: struct_stat;
530struct_stat: /* empty. */ | if else;
531if: "if" "const" "then" statement;
532else: "else" statement;
533%%
534]])
535
536AT_CHECK([bison -v input.y -o input.c])
537
538# Check only the tables. We don't use --no-parser, because it is
539# still to be implemented in the experimental branch of Bison.
ce4ccb4b
AD
540[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
541
542AT_CHECK([[cat tables.c]], 0,
c0c9ea05 543[[static const unsigned char yytranslate[] =
b9752825
AD
544{
545 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
546 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
547 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
548 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
549 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
550 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
551 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
552 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
553 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
554 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
555 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
556 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
557 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
558 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
559 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
560 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
561 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
562 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
563 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
564 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
565 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
566 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
567 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
568 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
569 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
007a50a4
AD
570 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
571 5, 6
b9752825 572};
5df5f6d5 573static const unsigned char yyprhs[] =
b9752825 574{
e7b8bef1 575 0, 0, 3, 5, 6, 9, 14
b9752825 576};
5df5f6d5 577static const signed char yyrhs[] =
b9752825 578{
e7b8bef1
AD
579 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
580 4, 5, 8, -1, 6, 8, -1
b9752825 581};
5df5f6d5 582static const unsigned char yyrline[] =
b9752825 583{
e7b8bef1 584 0, 2, 2, 3, 3, 4, 5
b9752825
AD
585};
586static const char *const yytname[] =
587{
588 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
80cce3da 589 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
b9752825
AD
590};
591static const short yytoknum[] =
592{
007a50a4 593 0, 256, 257, 258, 259, 260, 261, -1
b9752825 594};
c0c9ea05 595static const unsigned char yyr1[] =
b9752825 596{
e7b8bef1 597 0, 7, 8, 9, 9, 10, 11
b9752825 598};
5df5f6d5 599static const unsigned char yyr2[] =
b9752825 600{
e7b8bef1 601 0, 2, 1, 0, 2, 4, 2
b9752825
AD
602};
603static const short yydefact[] =
604{
e7b8bef1
AD
605 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
606 6, 5
b9752825
AD
607};
608static const short yydefgoto[] =
609{
e7b8bef1 610 -1, 2, 3, 4, 8
b9752825
AD
611};
612static const short yypact[] =
613{
e7b8bef1
AD
614 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
615 -32768,-32768
b9752825
AD
616};
617static const short yypgoto[] =
618{
e7b8bef1 619 -32768, -7,-32768,-32768,-32768
b9752825
AD
620};
621static const short yytable[] =
622{
e7b8bef1 623 10, 1, 11, 5, 6, 0, 7, 9
b9752825
AD
624};
625static const short yycheck[] =
626{
e7b8bef1 627 7, 3, 9, 4, 0, -1, 6, 5
b9752825 628};
5504898e
AD
629static const unsigned char yystos[] =
630{
631 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
632 8, 8
633};
b9752825
AD
634]])
635
636AT_CLEANUP