]> git.saurik.com Git - bison.git/blame - tests/regression.at
Really remove it.
[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
9501dc6e 32AT_DATA_GRAMMAR([input.y],
69078d4b
AD
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
b56471a6 53AT_CHECK([bison -o input.c input.y])
002b9b7d 54AT_COMPILE([input.o], [-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
b56471a6 75AT_CHECK([bison -v -o input.c input.y])
2b25d624 76
a4bf0390 77AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
2b25d624
AD
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
b56471a6 102AT_CHECK([bison -v -o input.c input.y], 0, [],
a5d50994 103[[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
69078d4b 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
b56471a6 147AT_CHECK([bison -o input.c -v input.y])
2ca209c1
AD
148
149# Check the contents of the report.
150AT_CHECK([cat input.output], [],
d2d1b42b 151[[Grammar
2ca209c1 152
88bce5a2 153 0 $accept: expr $end
6b98e4b5
AD
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
88bce5a2 166$end (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
88bce5a2 175$accept (6)
b365aa05
AD
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
88bce5a2 187 0 $accept: . expr $end
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
88bce5a2 208 0 $accept: expr . $end
2ca209c1 209
88bce5a2 210 $end 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
88bce5a2 229 0 $accept: expr $end .
2ca209c1 230
e8832397 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
b56471a6 269AT_CHECK([bison -v -o input.c input.y])
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 286%&
2dfbfc12 287%a-does-not-exist
29ae55f1 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: `&'
2dfbfc12 297input.y:5.1-17: invalid directive: `%a-does-not-exist'
e9955c83
AD
298input.y:6.1: invalid character: `%'
299input.y:6.2: invalid character: `-'
2115939b 300input.y:7.1-8.0: missing `%}' at end of file
6e649e65 301input.y:7.1-8.0: syntax error, unexpected "%{...%}", expecting ";" or "|"
e0c40012 302]])
561f9a30
AD
303
304AT_CLEANUP
305
306
270a173c 307
b87f8b21
AD
308## ------------------- ##
309## Token definitions. ##
310## ------------------- ##
311
312
313AT_SETUP([Token definitions])
314
315# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
9501dc6e 316AT_DATA_GRAMMAR([input.y],
db7c8e9a
AD
317[%{
318void yyerror (const char *s);
319int yylex (void);
320%}
7bd6c77e 321[%token MYEOF 0 "end of file"
b87f8b21 322%token 'a' "a"
e9955c83
AD
323%token b "b"
324%token c 'c'
325%token 'd' d
b87f8b21
AD
326%%
327exp: "a";
328]])
329
b56471a6 330AT_CHECK([bison -o input.c input.y])
002b9b7d 331AT_COMPILE([input.o], [-c input.c])
b87f8b21
AD
332AT_CLEANUP
333
334
335
eb714592
AD
336## -------------------- ##
337## Characters Escapes. ##
338## -------------------- ##
339
340
341AT_SETUP([Characters Escapes])
342
9501dc6e 343AT_DATA_GRAMMAR([input.y],
eb714592
AD
344[%{
345void yyerror (const char *s);
346int yylex (void);
347%}
348[%%
349exp:
350 '\'' "\'"
351| '\"' "\""
352| '"' "'"
353;
354]])
9501dc6e 355# Pacify font-lock-mode: "
eb714592 356
b56471a6 357AT_CHECK([bison -o input.c input.y])
eb714592
AD
358AT_COMPILE([input.o], [-c input.c])
359AT_CLEANUP
360
361
362
b9752825
AD
363## -------------- ##
364## Web2c Report. ##
365## -------------- ##
776209d6
AD
366
367# The generation of the reduction was once wrong in Bison, and made it
368# miss some reductions. In the following test case, the reduction on
369# `undef_id_tok' in state 1 was missing. This is stripped down from
370# the actual web2c.y.
371
b9752825 372AT_SETUP([Web2c Report])
776209d6 373
6b98e4b5
AD
374AT_KEYWORDS([report])
375
776209d6
AD
376AT_DATA([input.y],
377[[%token undef_id_tok const_id_tok
378
379%start CONST_DEC_PART
380\f
381%%
382CONST_DEC_PART:
383 CONST_DEC_LIST
384 ;
385
386CONST_DEC_LIST:
387 CONST_DEC
388 | CONST_DEC_LIST CONST_DEC
389 ;
390
391CONST_DEC:
392 { } undef_id_tok '=' const_id_tok ';'
393 ;
394%%
776209d6
AD
395]])
396
397AT_CHECK([bison -v input.y])
87675353 398AT_CHECK([cat input.output], 0,
776209d6 399[[Grammar
87675353 400
88bce5a2 401 0 $accept: CONST_DEC_PART $end
87675353 402
6b98e4b5 403 1 CONST_DEC_PART: CONST_DEC_LIST
87675353 404
6b98e4b5
AD
405 2 CONST_DEC_LIST: CONST_DEC
406 3 | CONST_DEC_LIST CONST_DEC
87675353 407
6b98e4b5 408 4 @1: /* empty */
87675353 409
6b98e4b5 410 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
87675353
AD
411
412
776209d6 413Terminals, with rules where they appear
87675353 414
88bce5a2 415$end (0) 0
776209d6
AD
416';' (59) 5
417'=' (61) 5
418error (256)
007a50a4
AD
419undef_id_tok (258) 5
420const_id_tok (259) 5
87675353
AD
421
422
776209d6 423Nonterminals, with rules where they appear
87675353 424
88bce5a2 425$accept (7)
78d5bae9
AD
426 on left: 0
427CONST_DEC_PART (8)
428 on left: 1, on right: 0
429CONST_DEC_LIST (9)
776209d6 430 on left: 2 3, on right: 1 3
78d5bae9 431CONST_DEC (10)
776209d6 432 on left: 5, on right: 2 3
78d5bae9 433@1 (11)
776209d6 434 on left: 4, on right: 5
87675353
AD
435
436
776209d6 437state 0
87675353 438
88bce5a2 439 0 $accept: . CONST_DEC_PART $end
87675353
AD
440
441 $default reduce using rule 4 (@1)
442
443 CONST_DEC_PART go to state 1
444 CONST_DEC_LIST go to state 2
445 CONST_DEC go to state 3
446 @1 go to state 4
447
448
776209d6 449state 1
87675353 450
88bce5a2 451 0 $accept: CONST_DEC_PART . $end
87675353 452
88bce5a2 453 $end shift, and go to state 5
87675353
AD
454
455
78d5bae9 456state 2
87675353 457
ce4ccb4b
AD
458 1 CONST_DEC_PART: CONST_DEC_LIST .
459 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
87675353
AD
460
461 undef_id_tok reduce using rule 4 (@1)
462 $default reduce using rule 1 (CONST_DEC_PART)
463
464 CONST_DEC go to state 6
465 @1 go to state 4
466
467
78d5bae9 468state 3
87675353 469
ce4ccb4b 470 2 CONST_DEC_LIST: CONST_DEC .
87675353
AD
471
472 $default reduce using rule 2 (CONST_DEC_LIST)
473
474
776209d6 475state 4
87675353 476
ce4ccb4b 477 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
87675353
AD
478
479 undef_id_tok shift, and go to state 7
480
481
78d5bae9 482state 5
87675353 483
88bce5a2 484 0 $accept: CONST_DEC_PART $end .
87675353 485
e8832397 486 $default accept
87675353
AD
487
488
78d5bae9 489state 6
87675353 490
ce4ccb4b 491 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
87675353
AD
492
493 $default reduce using rule 3 (CONST_DEC_LIST)
494
495
78d5bae9 496state 7
87675353 497
ce4ccb4b 498 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
87675353
AD
499
500 '=' shift, and go to state 8
501
502
78d5bae9 503state 8
87675353 504
ce4ccb4b 505 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
87675353
AD
506
507 const_id_tok shift, and go to state 9
508
509
78d5bae9 510state 9
87675353 511
ce4ccb4b 512 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
87675353
AD
513
514 ';' shift, and go to state 10
515
516
78d5bae9 517state 10
87675353 518
ce4ccb4b 519 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
87675353
AD
520
521 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
522]])
523
524AT_CLEANUP
b9752825
AD
525
526
527## --------------- ##
528## Web2c Actions. ##
529## --------------- ##
530
531# The generation of the mapping `state -> action' was once wrong in
532# extremely specific situations. web2c.y exhibits this situation.
533# Below is a stripped version of the grammar. It looks like one can
534# simplify it further, but just don't: it is tuned to exhibit a bug,
535# which disapears when applying sane grammar transformations.
536#
537# It used to be wrong on yydefact only:
538#
539# static const short yydefact[] =
540# {
541# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
542# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
543# 0, 0
544# };
545#
546# but let's check all the tables.
547
548
549AT_SETUP([Web2c Actions])
550
6b98e4b5
AD
551AT_KEYWORDS([report])
552
b9752825
AD
553AT_DATA([input.y],
554[[%%
555statement: struct_stat;
556struct_stat: /* empty. */ | if else;
557if: "if" "const" "then" statement;
558else: "else" statement;
559%%
560]])
561
b56471a6 562AT_CHECK([bison -v -o input.c input.y])
b9752825
AD
563
564# Check only the tables. We don't use --no-parser, because it is
565# still to be implemented in the experimental branch of Bison.
ce4ccb4b
AD
566[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
567
568AT_CHECK([[cat tables.c]], 0,
c0c9ea05 569[[static const unsigned char yytranslate[] =
b9752825
AD
570{
571 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
572 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
573 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
574 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
575 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
576 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
577 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
578 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
579 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
580 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
581 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
582 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
583 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
584 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
585 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
586 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
587 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
588 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
589 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
590 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
591 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
592 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
593 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
594 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
595 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
007a50a4
AD
596 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
597 5, 6
b9752825 598};
5df5f6d5 599static const unsigned char yyprhs[] =
b9752825 600{
e7b8bef1 601 0, 0, 3, 5, 6, 9, 14
b9752825 602};
7c78fa18 603static const yysigned_char yyrhs[] =
b9752825 604{
e7b8bef1
AD
605 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
606 4, 5, 8, -1, 6, 8, -1
b9752825 607};
5df5f6d5 608static const unsigned char yyrline[] =
b9752825 609{
e7b8bef1 610 0, 2, 2, 3, 3, 4, 5
b9752825
AD
611};
612static const char *const yytname[] =
613{
88bce5a2
AD
614 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
615 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
b9752825 616};
3650b4b8 617static const unsigned short yytoknum[] =
b9752825 618{
3650b4b8 619 0, 256, 257, 258, 259, 260, 261
b9752825 620};
c0c9ea05 621static const unsigned char yyr1[] =
b9752825 622{
e7b8bef1 623 0, 7, 8, 9, 9, 10, 11
b9752825 624};
5df5f6d5 625static const unsigned char yyr2[] =
b9752825 626{
e7b8bef1 627 0, 2, 1, 0, 2, 4, 2
b9752825 628};
a762e609 629static const unsigned char yydefact[] =
b9752825 630{
e8832397 631 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
e7b8bef1 632 6, 5
b9752825 633};
7c78fa18 634static const yysigned_char yydefgoto[] =
b9752825 635{
e7b8bef1 636 -1, 2, 3, 4, 8
b9752825 637};
7c78fa18 638static const yysigned_char yypact[] =
b9752825 639{
12b0043a
AD
640 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
641 -8, -8
b9752825 642};
7c78fa18 643static const yysigned_char yypgoto[] =
b9752825 644{
12b0043a 645 -8, -7, -8, -8, -8
b9752825 646};
a762e609 647static const unsigned char yytable[] =
b9752825 648{
e7b8bef1 649 10, 1, 11, 5, 6, 0, 7, 9
b9752825 650};
7c78fa18 651static const yysigned_char yycheck[] =
b9752825 652{
e7b8bef1 653 7, 3, 9, 4, 0, -1, 6, 5
b9752825 654};
5504898e
AD
655static const unsigned char yystos[] =
656{
657 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
658 8, 8
659};
b9752825
AD
660]])
661
662AT_CLEANUP