]> git.saurik.com Git - bison.git/blob - tests/regression.at
* src/symlist.h, src/symlist.c (symbol_list_length): New.
[bison.git] / tests / regression.at
1 # Bison Regressions. -*- Autotest -*-
2 # Copyright (C) 2001, 2002 Free Software Foundation, Inc.
3
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.
8
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.
13
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.
18
19 AT_BANNER([[Regression tests.]])
20
21
22 ## ------------------------- ##
23 ## Early token definitions. ##
24 ## ------------------------- ##
25
26
27 AT_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
32 AT_DATA([input.y],
33 [[%{
34 void yyerror (const char *s);
35 int 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 %%
49 exp: MY_TOKEN;
50 %%
51 ]])
52
53 AT_CHECK([bison input.y -o input.c])
54 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
55
56 AT_CLEANUP
57
58
59
60 ## ---------------- ##
61 ## Braces parsing. ##
62 ## ---------------- ##
63
64
65 AT_SETUP([Braces parsing])
66
67 AT_DATA([input.y],
68 [[/* Bison used to swallow the character after `}'. */
69
70 %%
71 exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
72 %%
73 ]])
74
75 AT_CHECK([bison -v input.y -o input.c])
76
77 AT_CHECK([fgrep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
78
79 AT_CLEANUP
80
81
82 ## ------------------ ##
83 ## Duplicate string. ##
84 ## ------------------ ##
85
86
87 AT_SETUP([Duplicate string])
88
89 AT_DATA([input.y],
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 %%
98 exp: '(' exp ')' | NUM ;
99 %%
100 ]])
101
102 AT_CHECK([bison -v input.y -o input.c], 0, [],
103 [[input.y:6: warning: symbol `"<="' used more than once as a literal string
104 ]])
105
106 AT_CLEANUP
107
108
109 ## ------------------- ##
110 ## Rule Line Numbers. ##
111 ## ------------------- ##
112
113 AT_SETUP([Rule Line Numbers])
114
115 AT_KEYWORDS([report])
116
117 AT_DATA([input.y],
118 [[%%
119 expr:
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
144 };
145 ]])
146
147 AT_CHECK([bison input.y -o input.c -v])
148
149 # Check the contents of the report.
150 AT_CHECK([cat input.output], [],
151 [[Grammar
152
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'
162
163
164 Terminals, with rules where they appear
165
166 $ (0) 0
167 'a' (97) 2
168 'b' (98) 2
169 'c' (99) 4
170 error (256)
171
172
173 Nonterminals, with rules where they appear
174
175 $axiom (6)
176 on left: 0
177 expr (7)
178 on left: 2 4, on right: 0
179 @1 (8)
180 on left: 1, on right: 2
181 @2 (9)
182 on left: 3, on right: 4
183
184
185 state 0
186
187 $axiom -> . expr $ (rule 0)
188
189 'a' shift, and go to state 1
190
191 $default reduce using rule 3 (@2)
192
193 expr go to state 2
194 @2 go to state 3
195
196
197
198 state 1
199
200 expr -> 'a' . @1 'b' (rule 2)
201
202 $default reduce using rule 1 (@1)
203
204 @1 go to state 4
205
206
207
208 state 2
209
210 $axiom -> expr . $ (rule 0)
211
212 $ shift, and go to state 5
213
214
215
216 state 3
217
218 expr -> @2 . 'c' (rule 4)
219
220 'c' shift, and go to state 6
221
222
223
224 state 4
225
226 expr -> 'a' @1 . 'b' (rule 2)
227
228 'b' shift, and go to state 7
229
230
231
232 state 5
233
234 $axiom -> expr $ . (rule 0)
235
236 $default accept
237
238
239 state 6
240
241 expr -> @2 'c' . (rule 4)
242
243 $default reduce using rule 4 (expr)
244
245
246
247 state 7
248
249 expr -> 'a' @1 'b' . (rule 2)
250
251 $default reduce using rule 2 (expr)
252
253
254
255 ]])
256
257 AT_CLEANUP
258
259
260
261 ## ---------------------- ##
262 ## Mixing %token styles. ##
263 ## ---------------------- ##
264
265
266 AT_SETUP([Mixing %token styles])
267
268 # Taken from the documentation.
269 AT_DATA([input.y],
270 [[%token <operator> OR "||"
271 %token <operator> LE 134 "<="
272 %left OR "<="
273 %%
274 exp: ;
275 %%
276 ]])
277
278 AT_CHECK([bison -v input.y -o input.c])
279
280 AT_CLEANUP
281
282
283
284 ## ---------------- ##
285 ## Invalid inputs. ##
286 ## ---------------- ##
287
288
289 AT_SETUP([Invalid inputs])
290
291 AT_DATA([input.y],
292 [[%%
293 ?
294 default: 'a' }
295 %&
296 %a
297 %-
298 %{
299 ]])
300
301 AT_CHECK([bison input.y], [1], [],
302 [[input.y:2.1: invalid character: `?'
303 input.y:3.14: invalid character: `}'
304 input.y:4.1: invalid character: `%'
305 input.y:4.2: invalid character: `&'
306 input.y:5.1: invalid character: `%'
307 input.y:6.1: invalid character: `%'
308 input.y:6.2: invalid character: `-'
309 input.y:7.1-8.0: unexpected end of file in a prologue
310 input.y:7.1-8.0: parse error, unexpected PROLOGUE, expecting ";" or "|"
311 input.y:5.2: symbol a is used, but is not defined as a token and has no rules
312 ]])
313
314 AT_CLEANUP
315
316
317
318 ## ------------------- ##
319 ## Token definitions. ##
320 ## ------------------- ##
321
322
323 AT_SETUP([Token definitions])
324
325 # Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
326 AT_DATA([input.y],
327 [%{
328 void yyerror (const char *s);
329 int yylex (void);
330 %}
331 [%token YYEOF 0 "end of file"
332 %token 'a' "a"
333 %token b "b"
334 %token c 'c'
335 %token 'd' d
336 %%
337 exp: "a";
338 ]])
339
340 AT_CHECK([bison input.y -o input.c])
341 AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -c])
342 AT_CLEANUP
343
344
345
346 ## -------------- ##
347 ## Web2c Report. ##
348 ## -------------- ##
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
355 AT_SETUP([Web2c Report])
356
357 AT_KEYWORDS([report])
358
359 AT_DATA([input.y],
360 [[%token undef_id_tok const_id_tok
361
362 %start CONST_DEC_PART
363 \f
364 %%
365 CONST_DEC_PART:
366 CONST_DEC_LIST
367 ;
368
369 CONST_DEC_LIST:
370 CONST_DEC
371 | CONST_DEC_LIST CONST_DEC
372 ;
373
374 CONST_DEC:
375 { } undef_id_tok '=' const_id_tok ';'
376 ;
377 %%
378
379 ]])
380
381 AT_CHECK([bison -v input.y])
382
383 AT_CHECK([sed -n 's/ *$//;/^$/!p' input.output], 0,
384 [[Grammar
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 ';'
391 Terminals, with rules where they appear
392 $ (0) 0
393 ';' (59) 5
394 '=' (61) 5
395 error (256)
396 undef_id_tok (258) 5
397 const_id_tok (259) 5
398 Nonterminals, with rules where they appear
399 $axiom (7)
400 on left: 0
401 CONST_DEC_PART (8)
402 on left: 1, on right: 0
403 CONST_DEC_LIST (9)
404 on left: 2 3, on right: 1 3
405 CONST_DEC (10)
406 on left: 5, on right: 2 3
407 @1 (11)
408 on left: 4, on right: 5
409 state 0
410 $axiom -> . CONST_DEC_PART $ (rule 0)
411 $default reduce using rule 4 (@1)
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
416 state 1
417 $axiom -> CONST_DEC_PART . $ (rule 0)
418 $ shift, and go to state 5
419 state 2
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)
424 CONST_DEC go to state 6
425 @1 go to state 4
426 state 3
427 CONST_DEC_LIST -> CONST_DEC . (rule 2)
428 $default reduce using rule 2 (CONST_DEC_LIST)
429 state 4
430 CONST_DEC -> @1 . undef_id_tok '=' const_id_tok ';' (rule 5)
431 undef_id_tok shift, and go to state 7
432 state 5
433 $axiom -> CONST_DEC_PART $ . (rule 0)
434 $default accept
435 state 6
436 CONST_DEC_LIST -> CONST_DEC_LIST CONST_DEC . (rule 3)
437 $default reduce using rule 3 (CONST_DEC_LIST)
438 state 7
439 CONST_DEC -> @1 undef_id_tok . '=' const_id_tok ';' (rule 5)
440 '=' shift, and go to state 8
441 state 8
442 CONST_DEC -> @1 undef_id_tok '=' . const_id_tok ';' (rule 5)
443 const_id_tok shift, and go to state 9
444 state 9
445 CONST_DEC -> @1 undef_id_tok '=' const_id_tok . ';' (rule 5)
446 ';' shift, and go to state 10
447 state 10
448 CONST_DEC -> @1 undef_id_tok '=' const_id_tok ';' . (rule 5)
449 $default reduce using rule 5 (CONST_DEC)
450 ]])
451
452 AT_CLEANUP
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
477 AT_SETUP([Web2c Actions])
478
479 AT_KEYWORDS([report])
480
481 AT_DATA([input.y],
482 [[%%
483 statement: struct_stat;
484 struct_stat: /* empty. */ | if else;
485 if: "if" "const" "then" statement;
486 else: "else" statement;
487 %%
488 ]])
489
490 AT_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.
494 AT_CHECK([[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c]], 0,
495 [[static const unsigned char yytranslate[] =
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,
522 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
523 5, 6
524 };
525 static const unsigned char yyprhs[] =
526 {
527 0, 0, 3, 5, 6, 9, 14
528 };
529 static const signed char yyrhs[] =
530 {
531 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
532 4, 5, 8, -1, 6, 8, -1
533 };
534 static const unsigned char yyrline[] =
535 {
536 0, 2, 2, 3, 3, 4, 5
537 };
538 static const char *const yytname[] =
539 {
540 "$", "error", "$undefined.", "\"if\"", "\"const\"", "\"then\"",
541 "\"else\"", "$axiom", "statement", "struct_stat", "if", "else", 0
542 };
543 static const short yytoknum[] =
544 {
545 0, 256, 257, 258, 259, 260, 261, -1
546 };
547 static const unsigned char yyr1[] =
548 {
549 0, 7, 8, 9, 9, 10, 11
550 };
551 static const unsigned char yyr2[] =
552 {
553 0, 2, 1, 0, 2, 4, 2
554 };
555 static const short yydefact[] =
556 {
557 3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
558 6, 5
559 };
560 static const short yydefgoto[] =
561 {
562 -1, 2, 3, 4, 8
563 };
564 static const short yypact[] =
565 {
566 -2, -1, 4,-32768, 0, 2,-32768, -2,-32768, -2,
567 -32768,-32768
568 };
569 static const short yypgoto[] =
570 {
571 -32768, -7,-32768,-32768,-32768
572 };
573 static const short yytable[] =
574 {
575 10, 1, 11, 5, 6, 0, 7, 9
576 };
577 static const short yycheck[] =
578 {
579 7, 3, 9, 4, 0, -1, 6, 5
580 };
581 static const unsigned char yystos[] =
582 {
583 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
584 8, 8
585 };
586 ]])
587
588 AT_CLEANUP