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