]> git.saurik.com Git - bison.git/blame_incremental - tests/regression.at
* tests/regression.at (Invalid inputs): Adjust to the recent
[bison.git] / tests / regression.at
... / ...
CommitLineData
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
19AT_BANNER([[Regression tests.]])
20
21
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 -o input.c input.y])
54AT_COMPILE([input.o], [-c input.c])
55
56AT_CLEANUP
57
58
59
60## ---------------- ##
61## Braces parsing. ##
62## ---------------- ##
63
64
65AT_SETUP([Braces parsing])
66
67AT_DATA([input.y],
68[[/* Bison used to swallow the character after `}'. */
69
70%%
71exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
72%%
73]])
74
75AT_CHECK([bison -v -o input.c input.y])
76
77AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
78
79AT_CLEANUP
80
81
82## ------------------ ##
83## Duplicate string. ##
84## ------------------ ##
85
86
87AT_SETUP([Duplicate string])
88
89AT_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%%
98exp: '(' exp ')' | NUM ;
99%%
100]])
101
102AT_CHECK([bison -v -o input.c input.y], 0, [],
103[[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
104]])
105
106AT_CLEANUP
107
108
109## ------------------- ##
110## Rule Line Numbers. ##
111## ------------------- ##
112
113AT_SETUP([Rule Line Numbers])
114
115AT_KEYWORDS([report])
116
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
144};
145]])
146
147AT_CHECK([bison -o input.c -v input.y])
148
149# Check the contents of the report.
150AT_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
164Terminals, with rules where they appear
165
166$end (0) 0
167'a' (97) 2
168'b' (98) 2
169'c' (99) 4
170error (256)
171
172
173Nonterminals, with rules where they appear
174
175$accept (6)
176 on left: 0
177expr (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
185state 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
197state 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
206state 2
207
208 0 $accept: expr . $end
209
210 $end shift, and go to state 5
211
212
213state 3
214
215 4 expr: @2 . 'c'
216
217 'c' shift, and go to state 6
218
219
220state 4
221
222 2 expr: 'a' @1 . 'b'
223
224 'b' shift, and go to state 7
225
226
227state 5
228
229 0 $accept: expr $end .
230
231 $default accept
232
233
234state 6
235
236 4 expr: @2 'c' .
237
238 $default reduce using rule 4 (expr)
239
240
241state 7
242
243 2 expr: 'a' @1 'b' .
244
245 $default reduce using rule 2 (expr)
246]])
247
248AT_CLEANUP
249
250
251
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
269AT_CHECK([bison -v -o input.c input.y])
270
271AT_CLEANUP
272
273
274
275## ---------------- ##
276## Invalid inputs. ##
277## ---------------- ##
278
279
280AT_SETUP([Invalid inputs])
281
282AT_DATA([input.y],
283[[%%
284?
285default: 'a' }
286%&
287%a-does-not-exist
288%-
289%{
290]])
291
292AT_CHECK([bison input.y], [1], [],
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: `&'
297input.y:5.1-17: invalid directive: `%a-does-not-exist'
298input.y:6.1: invalid character: `%'
299input.y:6.2: invalid character: `-'
300input.y:7.1-8.0: unexpected end of file in `%{ ... %}'
301input.y:7.1-8.0: parse error, unexpected "%{...%}", expecting ";" or "|"
302]])
303
304AT_CLEANUP
305
306
307
308## ------------------- ##
309## Token definitions. ##
310## ------------------- ##
311
312
313AT_SETUP([Token definitions])
314
315# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
316AT_DATA([input.y],
317[%{
318void yyerror (const char *s);
319int 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%%
327exp: "a";
328]])
329
330AT_CHECK([bison -o input.c input.y])
331AT_COMPILE([input.o], [-c input.c])
332AT_CLEANUP
333
334
335
336## -------------------- ##
337## Characters Escapes. ##
338## -------------------- ##
339
340
341AT_SETUP([Characters Escapes])
342
343AT_DATA([input.y],
344[%{
345void yyerror (const char *s);
346int yylex (void);
347%}
348[%%
349exp:
350 '\'' "\'"
351| '\"' "\""
352| '"' "'"
353;
354]])
355
356AT_CHECK([bison -o input.c input.y])
357AT_COMPILE([input.o], [-c input.c])
358AT_CLEANUP
359
360
361
362## -------------- ##
363## Web2c Report. ##
364## -------------- ##
365
366# The generation of the reduction was once wrong in Bison, and made it
367# miss some reductions. In the following test case, the reduction on
368# `undef_id_tok' in state 1 was missing. This is stripped down from
369# the actual web2c.y.
370
371AT_SETUP([Web2c Report])
372
373AT_KEYWORDS([report])
374
375AT_DATA([input.y],
376[[%token undef_id_tok const_id_tok
377
378%start CONST_DEC_PART
379\f
380%%
381CONST_DEC_PART:
382 CONST_DEC_LIST
383 ;
384
385CONST_DEC_LIST:
386 CONST_DEC
387 | CONST_DEC_LIST CONST_DEC
388 ;
389
390CONST_DEC:
391 { } undef_id_tok '=' const_id_tok ';'
392 ;
393%%
394]])
395
396AT_CHECK([bison -v input.y])
397AT_CHECK([cat input.output], 0,
398[[Grammar
399
400 0 $accept: CONST_DEC_PART $end
401
402 1 CONST_DEC_PART: CONST_DEC_LIST
403
404 2 CONST_DEC_LIST: CONST_DEC
405 3 | CONST_DEC_LIST CONST_DEC
406
407 4 @1: /* empty */
408
409 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
410
411
412Terminals, with rules where they appear
413
414$end (0) 0
415';' (59) 5
416'=' (61) 5
417error (256)
418undef_id_tok (258) 5
419const_id_tok (259) 5
420
421
422Nonterminals, with rules where they appear
423
424$accept (7)
425 on left: 0
426CONST_DEC_PART (8)
427 on left: 1, on right: 0
428CONST_DEC_LIST (9)
429 on left: 2 3, on right: 1 3
430CONST_DEC (10)
431 on left: 5, on right: 2 3
432@1 (11)
433 on left: 4, on right: 5
434
435
436state 0
437
438 0 $accept: . CONST_DEC_PART $end
439
440 $default reduce using rule 4 (@1)
441
442 CONST_DEC_PART go to state 1
443 CONST_DEC_LIST go to state 2
444 CONST_DEC go to state 3
445 @1 go to state 4
446
447
448state 1
449
450 0 $accept: CONST_DEC_PART . $end
451
452 $end shift, and go to state 5
453
454
455state 2
456
457 1 CONST_DEC_PART: CONST_DEC_LIST .
458 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
459
460 undef_id_tok reduce using rule 4 (@1)
461 $default reduce using rule 1 (CONST_DEC_PART)
462
463 CONST_DEC go to state 6
464 @1 go to state 4
465
466
467state 3
468
469 2 CONST_DEC_LIST: CONST_DEC .
470
471 $default reduce using rule 2 (CONST_DEC_LIST)
472
473
474state 4
475
476 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
477
478 undef_id_tok shift, and go to state 7
479
480
481state 5
482
483 0 $accept: CONST_DEC_PART $end .
484
485 $default accept
486
487
488state 6
489
490 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
491
492 $default reduce using rule 3 (CONST_DEC_LIST)
493
494
495state 7
496
497 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
498
499 '=' shift, and go to state 8
500
501
502state 8
503
504 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
505
506 const_id_tok shift, and go to state 9
507
508
509state 9
510
511 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
512
513 ';' shift, and go to state 10
514
515
516state 10
517
518 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
519
520 $default reduce using rule 5 (CONST_DEC)
521]])
522
523AT_CLEANUP
524
525
526## --------------- ##
527## Web2c Actions. ##
528## --------------- ##
529
530# The generation of the mapping `state -> action' was once wrong in
531# extremely specific situations. web2c.y exhibits this situation.
532# Below is a stripped version of the grammar. It looks like one can
533# simplify it further, but just don't: it is tuned to exhibit a bug,
534# which disapears when applying sane grammar transformations.
535#
536# It used to be wrong on yydefact only:
537#
538# static const short yydefact[] =
539# {
540# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
541# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
542# 0, 0
543# };
544#
545# but let's check all the tables.
546
547
548AT_SETUP([Web2c Actions])
549
550AT_KEYWORDS([report])
551
552AT_DATA([input.y],
553[[%%
554statement: struct_stat;
555struct_stat: /* empty. */ | if else;
556if: "if" "const" "then" statement;
557else: "else" statement;
558%%
559]])
560
561AT_CHECK([bison -v -o input.c input.y])
562
563# Check only the tables. We don't use --no-parser, because it is
564# still to be implemented in the experimental branch of Bison.
565[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
566
567AT_CHECK([[cat tables.c]], 0,
568[[static const unsigned char yytranslate[] =
569{
570 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
571 2, 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, 1, 2, 3, 4,
596 5, 6
597};
598static const unsigned char yyprhs[] =
599{
600 0, 0, 3, 5, 6, 9, 14
601};
602static const yysigned_char yyrhs[] =
603{
604 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
605 4, 5, 8, -1, 6, 8, -1
606};
607static const unsigned char yyrline[] =
608{
609 0, 2, 2, 3, 3, 4, 5
610};
611static const char *const yytname[] =
612{
613 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
614 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
615};
616static const unsigned short yytoknum[] =
617{
618 0, 256, 257, 258, 259, 260, 261
619};
620static const unsigned char yyr1[] =
621{
622 0, 7, 8, 9, 9, 10, 11
623};
624static const unsigned char yyr2[] =
625{
626 0, 2, 1, 0, 2, 4, 2
627};
628static const unsigned char yydefact[] =
629{
630 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
631 6, 5
632};
633static const yysigned_char yydefgoto[] =
634{
635 -1, 2, 3, 4, 8
636};
637static const yysigned_char yypact[] =
638{
639 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
640 -8, -8
641};
642static const yysigned_char yypgoto[] =
643{
644 -8, -7, -8, -8, -8
645};
646static const unsigned char yytable[] =
647{
648 10, 1, 11, 5, 6, 0, 7, 9
649};
650static const yysigned_char yycheck[] =
651{
652 7, 3, 9, 4, 0, -1, 6, 5
653};
654static const unsigned char yystos[] =
655{
656 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
657 8, 8
658};
659]])
660
661AT_CLEANUP