]> git.saurik.com Git - bison.git/blame - tests/regression.at
Let symbols have a location.
[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
8efe435c
AD
152 0 5 $axiom -> expr $
153 1 5 @1 -> /* empty */
2ca209c1 154 2 2 expr -> 'a' @1 'b'
8efe435c 155 3 18 @2 -> /* empty */
2ca209c1
AD
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%a
292%-
e9955c83 293%{
561f9a30
AD
294]])
295
296AT_CHECK([bison input.y], [1], [],
e9955c83
AD
297[[input.y:2.1: invalid character: `?'
298input.y:3.14: invalid character: `}'
299input.y:4.1: invalid character: `%'
300input.y:4.2: invalid character: `&'
301input.y:5.1: invalid character: `%'
302input.y:6.1: invalid character: `%'
303input.y:6.2: invalid character: `-'
304input.y:7.1-8.0: unexpected end of file in a prologue
305input.y:7.1-8.0: parse error, unexpected PROLOGUE, expecting ";" or "|"
ee000ba4 306input.y:5.2: symbol a is used, but is not defined as a token and has no rules
e0c40012 307]])
561f9a30
AD
308
309AT_CLEANUP
310
311
270a173c 312
b87f8b21
AD
313## ------------------- ##
314## Token definitions. ##
315## ------------------- ##
316
317
318AT_SETUP([Token definitions])
319
320# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
321AT_DATA([input.y],
db7c8e9a
AD
322[%{
323void yyerror (const char *s);
324int yylex (void);
325%}
e9955c83 326[%token YYEOF 0 "end of file"
b87f8b21 327%token 'a' "a"
e9955c83
AD
328%token b "b"
329%token c 'c'
330%token 'd' d
b87f8b21
AD
331%%
332exp: "a";
333]])
334
335AT_CHECK([bison input.y -o input.c])
336AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
337AT_CLEANUP
338
339
340
b9752825
AD
341## -------------- ##
342## Web2c Report. ##
343## -------------- ##
776209d6
AD
344
345# The generation of the reduction was once wrong in Bison, and made it
346# miss some reductions. In the following test case, the reduction on
347# `undef_id_tok' in state 1 was missing. This is stripped down from
348# the actual web2c.y.
349
b9752825 350AT_SETUP([Web2c Report])
776209d6
AD
351
352AT_DATA([input.y],
353[[%token undef_id_tok const_id_tok
354
355%start CONST_DEC_PART
356\f
357%%
358CONST_DEC_PART:
359 CONST_DEC_LIST
360 ;
361
362CONST_DEC_LIST:
363 CONST_DEC
364 | CONST_DEC_LIST CONST_DEC
365 ;
366
367CONST_DEC:
368 { } undef_id_tok '=' const_id_tok ';'
369 ;
370%%
371
372]])
373
374AT_CHECK([bison -v input.y])
375
376AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
377[[Grammar
378 Number, Line, Rule
78d5bae9 379 0 6 $axiom -> CONST_DEC_PART $
776209d6
AD
380 1 6 CONST_DEC_PART -> CONST_DEC_LIST
381 2 10 CONST_DEC_LIST -> CONST_DEC
382 3 12 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC
8efe435c 383 4 16 @1 -> /* empty */
776209d6
AD
384 5 15 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';'
385Terminals, with rules where they appear
78d5bae9 386$ (0) 0
776209d6
AD
387';' (59) 5
388'=' (61) 5
389error (256)
007a50a4
AD
390undef_id_tok (258) 5
391const_id_tok (259) 5
776209d6 392Nonterminals, with rules where they appear
78d5bae9
AD
393$axiom (7)
394 on left: 0
395CONST_DEC_PART (8)
396 on left: 1, on right: 0
397CONST_DEC_LIST (9)
776209d6 398 on left: 2 3, on right: 1 3
78d5bae9 399CONST_DEC (10)
776209d6 400 on left: 5, on right: 2 3
78d5bae9 401@1 (11)
776209d6
AD
402 on left: 4, on right: 5
403state 0
643a5994 404 $axiom -> . CONST_DEC_PART $ (rule 0)
776209d6 405 $default reduce using rule 4 (@1)
78d5bae9
AD
406 CONST_DEC_PART go to state 1
407 CONST_DEC_LIST go to state 2
408 CONST_DEC go to state 3
409 @1 go to state 4
776209d6 410state 1
78d5bae9
AD
411 $axiom -> CONST_DEC_PART . $ (rule 0)
412 $ shift, and go to state 5
413state 2
776209d6
AD
414 CONST_DEC_PART -> CONST_DEC_LIST . (rule 1)
415 CONST_DEC_LIST -> CONST_DEC_LIST . CONST_DEC (rule 3)
416 undef_id_tok reduce using rule 4 (@1)
417 $default reduce using rule 1 (CONST_DEC_PART)
78d5bae9
AD
418 CONST_DEC go to state 6
419 @1 go to state 4
420state 3
776209d6
AD
421 CONST_DEC_LIST -> CONST_DEC . (rule 2)
422 $default reduce using rule 2 (CONST_DEC_LIST)
776209d6 423state 4
78d5bae9
AD
424 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
425 undef_id_tok shift, and go to state 7
426state 5
427 $axiom -> CONST_DEC_PART $ . (rule 0)
428 $default accept
429state 6
776209d6
AD
430 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
431 $default reduce using rule 3 (CONST_DEC_LIST)
78d5bae9 432state 7
776209d6 433 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
78d5bae9
AD
434 '=' shift, and go to state 8
435state 8
776209d6 436 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
78d5bae9
AD
437 const_id_tok shift, and go to state 9
438state 9
776209d6 439 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
78d5bae9
AD
440 ';' shift, and go to state 10
441state 10
776209d6
AD
442 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
443 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
444]])
445
446AT_CLEANUP
b9752825
AD
447
448
449## --------------- ##
450## Web2c Actions. ##
451## --------------- ##
452
453# The generation of the mapping `state -> action' was once wrong in
454# extremely specific situations. web2c.y exhibits this situation.
455# Below is a stripped version of the grammar. It looks like one can
456# simplify it further, but just don't: it is tuned to exhibit a bug,
457# which disapears when applying sane grammar transformations.
458#
459# It used to be wrong on yydefact only:
460#
461# static const short yydefact[] =
462# {
463# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
464# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
465# 0, 0
466# };
467#
468# but let's check all the tables.
469
470
471AT_SETUP([Web2c Actions])
472
473AT_DATA([input.y],
474[[%%
475statement: struct_stat;
476struct_stat: /* empty. */ | if else;
477if: "if" "const" "then" statement;
478else: "else" statement;
479%%
480]])
481
482AT_CHECK([bison -v input.y -o input.c])
483
484# Check only the tables. We don't use --no-parser, because it is
485# still to be implemented in the experimental branch of Bison.
486AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
c0c9ea05 487[[static const unsigned char yytranslate[] =
b9752825
AD
488{
489 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
490 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
491 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
492 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
493 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
494 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
495 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
496 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
497 2, 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,
007a50a4
AD
514 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
515 5, 6
b9752825 516};
5df5f6d5 517static const unsigned char yyprhs[] =
b9752825 518{
e7b8bef1 519 0, 0, 3, 5, 6, 9, 14
b9752825 520};
5df5f6d5 521static const signed char yyrhs[] =
b9752825 522{
e7b8bef1
AD
523 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
524 4, 5, 8, -1, 6, 8, -1
b9752825 525};
5df5f6d5 526static const unsigned char yyrline[] =
b9752825 527{
e7b8bef1 528 0, 2, 2, 3, 3, 4, 5
b9752825
AD
529};
530static const char *const yytname[] =
531{
532 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
80cce3da 533 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
b9752825
AD
534};
535static const short yytoknum[] =
536{
007a50a4 537 0, 256, 257, 258, 259, 260, 261, -1
b9752825 538};
c0c9ea05 539static const unsigned char yyr1[] =
b9752825 540{
e7b8bef1 541 0, 7, 8, 9, 9, 10, 11
b9752825 542};
5df5f6d5 543static const unsigned char yyr2[] =
b9752825 544{
e7b8bef1 545 0, 2, 1, 0, 2, 4, 2
b9752825
AD
546};
547static const short yydefact[] =
548{
e7b8bef1
AD
549 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
550 6, 5
b9752825
AD
551};
552static const short yydefgoto[] =
553{
e7b8bef1 554 -1, 2, 3, 4, 8
b9752825
AD
555};
556static const short yypact[] =
557{
e7b8bef1
AD
558 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
559 -32768,-32768
b9752825
AD
560};
561static const short yypgoto[] =
562{
e7b8bef1 563 -32768, -7,-32768,-32768,-32768
b9752825
AD
564};
565static const short yytable[] =
566{
e7b8bef1 567 10, 1, 11, 5, 6, 0, 7, 9
b9752825
AD
568};
569static const short yycheck[] =
570{
e7b8bef1 571 7, 3, 9, 4, 0, -1, 6, 5
b9752825 572};
5504898e
AD
573static const unsigned char yystos[] =
574{
575 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
576 8, 8
577};
b9752825
AD
578]])
579
580AT_CLEANUP