]> git.saurik.com Git - bison.git/blame - tests/regression.at
GCJ's parser requires the tokens to be defined before the prologue.
[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
115AT_DATA([input.y],
116[[%%
117expr:
118'a'
119
120{
121
122}
123
124'b'
125
126{
127
128}
129
130|
131
132
133{
134
135
136}
137
138'c'
139
140{
141
bfcf1f3a 142};
2ca209c1
AD
143]])
144
69078d4b 145AT_CHECK([bison input.y -o input.c -v])
2ca209c1
AD
146
147# Check the contents of the report.
148AT_CHECK([cat input.output], [],
d2d1b42b 149[[Grammar
2ca209c1
AD
150
151 Number, Line, Rule
ff442794 152 0 2 $axiom -> expr $
2ca209c1
AD
153 1 2 @1 -> /* empty */
154 2 2 expr -> 'a' @1 'b'
155 3 15 @2 -> /* empty */
156 4 15 expr -> @2 'c'
157
d2d1b42b 158
2ca209c1
AD
159Terminals, with rules where they appear
160
b365aa05 161$ (0) 0
2ca209c1
AD
162'a' (97) 2
163'b' (98) 2
164'c' (99) 4
165error (256)
166
d2d1b42b 167
2ca209c1
AD
168Nonterminals, with rules where they appear
169
b365aa05
AD
170$axiom (6)
171 on left: 0
172expr (7)
173 on left: 2 4, on right: 0
174@1 (8)
2ca209c1 175 on left: 1, on right: 2
b365aa05 176@2 (9)
2ca209c1
AD
177 on left: 3, on right: 4
178
179
180state 0
181
643a5994
AD
182 $axiom -> . expr $ (rule 0)
183
2ca209c1
AD
184 'a' shift, and go to state 1
185
610ab194
AD
186 $default reduce using rule 3 (@2)
187
b365aa05
AD
188 expr go to state 2
189 @2 go to state 3
2ca209c1
AD
190
191
192
193state 1
194
195 expr -> 'a' . @1 'b' (rule 2)
196
197 $default reduce using rule 1 (@1)
198
b365aa05 199 @1 go to state 4
2ca209c1
AD
200
201
202
203state 2
204
b365aa05 205 $axiom -> expr . $ (rule 0)
2ca209c1 206
b365aa05 207 $ shift, and go to state 5
2ca209c1
AD
208
209
210
211state 3
212
b365aa05 213 expr -> @2 . 'c' (rule 4)
2ca209c1 214
b365aa05 215 'c' shift, and go to state 6
2ca209c1
AD
216
217
218
219state 4
220
b365aa05 221 expr -> 'a' @1 . 'b' (rule 2)
2ca209c1 222
b365aa05 223 'b' shift, and go to state 7
2ca209c1
AD
224
225
226
227state 5
228
b365aa05 229 $axiom -> expr $ . (rule 0)
2ca209c1 230
b365aa05 231 $default accept
2ca209c1
AD
232
233
234state 6
235
b365aa05
AD
236 expr -> @2 'c' . (rule 4)
237
238 $default reduce using rule 4 (expr)
2ca209c1
AD
239
240
241
242state 7
243
b365aa05
AD
244 expr -> 'a' @1 'b' . (rule 2)
245
246 $default reduce using rule 2 (expr)
247
d2d1b42b
AD
248
249
2ca209c1
AD
250]])
251
252AT_CLEANUP
253
254
255
cd5aafcf
AD
256## ---------------------- ##
257## Mixing %token styles. ##
258## ---------------------- ##
259
260
261AT_SETUP([Mixing %token styles])
262
263# Taken from the documentation.
264AT_DATA([input.y],
265[[%token <operator> OR "||"
266%token <operator> LE 134 "<="
267%left OR "<="
268%%
269exp: ;
270%%
271]])
272
69078d4b 273AT_CHECK([bison -v input.y -o input.c])
cd5aafcf 274
d803322e 275AT_CLEANUP
cd5aafcf
AD
276
277
278
29ae55f1
AD
279## ---------------- ##
280## Invalid inputs. ##
281## ---------------- ##
561f9a30
AD
282
283
29ae55f1 284AT_SETUP([Invalid inputs])
561f9a30
AD
285
286AT_DATA([input.y],
287[[%%
288?
561f9a30 289default: 'a' }
29ae55f1
AD
290%{
291%&
292%a
293%-
561f9a30
AD
294]])
295
296AT_CHECK([bison input.y], [1], [],
29ae55f1
AD
297[[input.y:2: invalid input: `?'
298input.y:3: invalid input: `}'
299input.y:4: invalid input: `%{'
300input.y:5: invalid input: `%&'
301input.y:6: invalid input: `%a'
302input.y:7: invalid input: `%-'
e0c40012
AD
303]])
304
305AT_CLEANUP
306
307
308
309## -------------------- ##
310## Invalid %directive. ##
311## -------------------- ##
312
313
314AT_SETUP([Invalid %directive])
315
316AT_DATA([input.y],
317[[%invalid
318]])
319
320AT_CHECK([bison input.y], [1], [],
321[[input.y:1: unrecognized: %invalid
322input.y:1: Skipping to next %
323input.y:2: fatal error: no input grammar
324]])
561f9a30
AD
325
326AT_CLEANUP
327
328
270a173c 329
b87f8b21
AD
330## ------------------- ##
331## Token definitions. ##
332## ------------------- ##
333
334
335AT_SETUP([Token definitions])
336
337# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
338AT_DATA([input.y],
db7c8e9a
AD
339[%{
340void yyerror (const char *s);
341int yylex (void);
342%}
343[%token "end of file"
b87f8b21
AD
344%token 'a' "a"
345%token "b" 'b'
346%token "c" c
347%token d "d"
348%token e 'e'
349%token 'f' e
350%%
351exp: "a";
352]])
353
354AT_CHECK([bison input.y -o input.c])
355AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
356AT_CLEANUP
357
358
359
b9752825
AD
360## -------------- ##
361## Web2c Report. ##
362## -------------- ##
776209d6
AD
363
364# The generation of the reduction was once wrong in Bison, and made it
365# miss some reductions. In the following test case, the reduction on
366# `undef_id_tok' in state 1 was missing. This is stripped down from
367# the actual web2c.y.
368
b9752825 369AT_SETUP([Web2c Report])
776209d6
AD
370
371AT_DATA([input.y],
372[[%token undef_id_tok const_id_tok
373
374%start CONST_DEC_PART
375\f
376%%
377CONST_DEC_PART:
378 CONST_DEC_LIST
379 ;
380
381CONST_DEC_LIST:
382 CONST_DEC
383 | CONST_DEC_LIST CONST_DEC
384 ;
385
386CONST_DEC:
387 { } undef_id_tok '=' const_id_tok ';'
388 ;
389%%
390
391]])
392
393AT_CHECK([bison -v input.y])
394
395AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
396[[Grammar
397 Number, Line, Rule
78d5bae9 398 0 6 $axiom -> CONST_DEC_PART $
776209d6
AD
399 1 6 CONST_DEC_PART -> CONST_DEC_LIST
400 2 10 CONST_DEC_LIST -> CONST_DEC
401 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
402 4 15 @1 -> /* empty */
403 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
404Terminals, with rules where they appear
78d5bae9 405$ (0) 0
776209d6
AD
406';' (59) 5
407'=' (61) 5
408error (256)
007a50a4
AD
409undef_id_tok (258) 5
410const_id_tok (259) 5
776209d6 411Nonterminals, with rules where they appear
78d5bae9
AD
412$axiom (7)
413 on left: 0
414CONST_DEC_PART (8)
415 on left: 1, on right: 0
416CONST_DEC_LIST (9)
776209d6 417 on left: 2 3, on right: 1 3
78d5bae9 418CONST_DEC (10)
776209d6 419 on left: 5, on right: 2 3
78d5bae9 420@1 (11)
776209d6
AD
421 on left: 4, on right: 5
422state 0
643a5994 423 $axiom -> . CONST_DEC_PART $ (rule 0)
776209d6 424 $default reduce using rule 4 (@1)
78d5bae9
AD
425 CONST_DEC_PART go to state 1
426 CONST_DEC_LIST go to state 2
427 CONST_DEC go to state 3
428 @1 go to state 4
776209d6 429state 1
78d5bae9
AD
430 $axiom -> CONST_DEC_PART . $ (rule 0)
431 $ shift, and go to state 5
432state 2
776209d6
AD
433 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
434 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
435 undef_id_tok reduce using rule 4 (@1)
436 $default reduce using rule 1 (CONST_DEC_PART)
78d5bae9
AD
437 CONST_DEC go to state 6
438 @1 go to state 4
439state 3
776209d6
AD
440 CONST_DEC_LIST -> CONST_DEC . (rule 2)
441 $default reduce using rule 2 (CONST_DEC_LIST)
776209d6 442state 4
78d5bae9
AD
443 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
444 undef_id_tok shift, and go to state 7
445state 5
446 $axiom -> CONST_DEC_PART $ . (rule 0)
447 $default accept
448state 6
776209d6
AD
449 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
450 $default reduce using rule 3 (CONST_DEC_LIST)
78d5bae9 451state 7
776209d6 452 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
78d5bae9
AD
453 '=' shift, and go to state 8
454state 8
776209d6 455 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
78d5bae9
AD
456 const_id_tok shift, and go to state 9
457state 9
776209d6 458 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
78d5bae9
AD
459 ';' shift, and go to state 10
460state 10
776209d6
AD
461 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
462 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
463]])
464
465AT_CLEANUP
b9752825
AD
466
467
468## --------------- ##
469## Web2c Actions. ##
470## --------------- ##
471
472# The generation of the mapping `state -> action' was once wrong in
473# extremely specific situations. web2c.y exhibits this situation.
474# Below is a stripped version of the grammar. It looks like one can
475# simplify it further, but just don't: it is tuned to exhibit a bug,
476# which disapears when applying sane grammar transformations.
477#
478# It used to be wrong on yydefact only:
479#
480# static const short yydefact[] =
481# {
482# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
483# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
484# 0, 0
485# };
486#
487# but let's check all the tables.
488
489
490AT_SETUP([Web2c Actions])
491
492AT_DATA([input.y],
493[[%%
494statement: struct_stat;
495struct_stat: /* empty. */ | if else;
496if: "if" "const" "then" statement;
497else: "else" statement;
498%%
499]])
500
501AT_CHECK([bison -v input.y -o input.c])
502
503# Check only the tables. We don't use --no-parser, because it is
504# still to be implemented in the experimental branch of Bison.
505AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
c0c9ea05 506[[static const unsigned char yytranslate[] =
b9752825
AD
507{
508 0, 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,
522 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
523 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
524 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
525 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
526 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
527 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
528 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
529 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
530 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
531 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
532 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
007a50a4
AD
533 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
534 5, 6
b9752825 535};
5df5f6d5 536static const unsigned char yyprhs[] =
b9752825 537{
e7b8bef1 538 0, 0, 3, 5, 6, 9, 14
b9752825 539};
5df5f6d5 540static const signed char yyrhs[] =
b9752825 541{
e7b8bef1
AD
542 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
543 4, 5, 8, -1, 6, 8, -1
b9752825 544};
5df5f6d5 545static const unsigned char yyrline[] =
b9752825 546{
e7b8bef1 547 0, 2, 2, 3, 3, 4, 5
b9752825
AD
548};
549static const char *const yytname[] =
550{
551 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
80cce3da 552 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
b9752825
AD
553};
554static const short yytoknum[] =
555{
007a50a4 556 0, 256, 257, 258, 259, 260, 261, -1
b9752825 557};
c0c9ea05 558static const unsigned char yyr1[] =
b9752825 559{
e7b8bef1 560 0, 7, 8, 9, 9, 10, 11
b9752825 561};
5df5f6d5 562static const unsigned char yyr2[] =
b9752825 563{
e7b8bef1 564 0, 2, 1, 0, 2, 4, 2
b9752825
AD
565};
566static const short yydefact[] =
567{
e7b8bef1
AD
568 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
569 6, 5
b9752825
AD
570};
571static const short yydefgoto[] =
572{
e7b8bef1 573 -1, 2, 3, 4, 8
b9752825
AD
574};
575static const short yypact[] =
576{
e7b8bef1
AD
577 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
578 -32768,-32768
b9752825
AD
579};
580static const short yypgoto[] =
581{
e7b8bef1 582 -32768, -7,-32768,-32768,-32768
b9752825
AD
583};
584static const short yytable[] =
585{
e7b8bef1 586 10, 1, 11, 5, 6, 0, 7, 9
b9752825
AD
587};
588static const short yycheck[] =
589{
e7b8bef1 590 7, 3, 9, 4, 0, -1, 6, 5
b9752825 591};
5504898e
AD
592static const unsigned char yystos[] =
593{
594 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
595 8, 8
596};
b9752825
AD
597]])
598
599AT_CLEANUP