]> git.saurik.com Git - bison.git/blame - tests/regression.at
maint: run "make update-copyright"
[bison.git] / tests / regression.at
CommitLineData
342b8b6e 1# Bison Regressions. -*- Autotest -*-
d42cf844 2
219c26ea 3# Copyright (C) 2001-2010 Free Software Foundation, Inc.
c95f2d78 4
f16b0819 5# This program is free software: you can redistribute it and/or modify
342b8b6e 6# it under the terms of the GNU General Public License as published by
f16b0819
PE
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
342b8b6e
AD
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
f16b0819 14#
342b8b6e 15# You should have received a copy of the GNU General Public License
f16b0819 16# along with this program. If not, see <http://www.gnu.org/licenses/>.
c95f2d78 17
342b8b6e 18AT_BANNER([[Regression tests.]])
c95f2d78 19
2b25d624 20
276f48df
PE
21## ------------------ ##
22## Trivial grammars. ##
23## ------------------ ##
24
25AT_SETUP([Trivial grammars])
26
27AT_DATA_GRAMMAR([input.y],
28[[%{
29void yyerror (char const *);
30int yylex (void);
50cce58e 31#define YYSTYPE int *
276f48df
PE
32%}
33
34%error-verbose
35
36%%
37
38program: 'x';
39]])
40
da730230 41AT_BISON_CHECK([-o input.c input.y])
276f48df 42AT_COMPILE([input.o], [-c input.c])
50cce58e 43AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
276f48df
PE
44
45AT_CLEANUP
46
47
48
ddc8ede1
PE
49## ----------------- ##
50## YYSTYPE typedef. ##
51## ----------------- ##
52
53AT_SETUP([YYSTYPE typedef])
54
55AT_DATA_GRAMMAR([input.y],
56[[%{
57void yyerror (char const *);
58int yylex (void);
59typedef union { char const *val; } YYSTYPE;
60%}
61
62%type <val> program
63
64%%
65
66program: { $$ = ""; };
67]])
68
da730230 69AT_BISON_CHECK([-o input.c input.y])
ddc8ede1
PE
70AT_COMPILE([input.o], [-c input.c])
71
72AT_CLEANUP
73
74
75
b931235e
JD
76## ------------------------------------- ##
77## Early token definitions with --yacc. ##
78## ------------------------------------- ##
69078d4b
AD
79
80
b931235e 81AT_SETUP([Early token definitions with --yacc])
69078d4b
AD
82
83# Found in GCJ: they expect the tokens to be defined before the user
84# prologue, so that they can use the token definitions in it.
85
9501dc6e 86AT_DATA_GRAMMAR([input.y],
69078d4b
AD
87[[%{
88void yyerror (const char *s);
89int yylex (void);
90%}
91
92%union
93{
94 int val;
95};
9bc0dd67
JD
96%{
97#ifndef MY_TOKEN
98# error "MY_TOKEN not defined."
99#endif
100%}
b931235e
JD
101%token MY_TOKEN
102%%
103exp: MY_TOKEN;
104%%
105]])
106
da730230 107AT_BISON_CHECK([-y -o input.c input.y])
b931235e
JD
108AT_COMPILE([input.o], [-c input.c])
109
110AT_CLEANUP
111
112
113
114## ---------------------------------------- ##
115## Early token definitions without --yacc. ##
116## ---------------------------------------- ##
117
118
119AT_SETUP([Early token definitions without --yacc])
120
121# Found in GCJ: they expect the tokens to be defined before the user
122# prologue, so that they can use the token definitions in it.
123
124AT_DATA_GRAMMAR([input.y],
125[[%{
126#include <stdio.h>
127void yyerror (const char *s);
128int yylex (void);
129void print_my_token (void);
9bc0dd67
JD
130%}
131
132%union
133{
134 int val;
135};
136%{
b931235e
JD
137void
138print_my_token (void)
139{
140 enum yytokentype my_token = MY_TOKEN;
141 printf ("%d\n", my_token);
142}
69078d4b
AD
143%}
144%token MY_TOKEN
145%%
146exp: MY_TOKEN;
147%%
148]])
149
da730230 150AT_BISON_CHECK([-o input.c input.y])
002b9b7d 151AT_COMPILE([input.o], [-c input.c])
69078d4b
AD
152
153AT_CLEANUP
154
155
156
2b25d624
AD
157## ---------------- ##
158## Braces parsing. ##
159## ---------------- ##
160
161
69078d4b 162AT_SETUP([Braces parsing])
2b25d624
AD
163
164AT_DATA([input.y],
165[[/* Bison used to swallow the character after `}'. */
166
167%%
bfcf1f3a 168exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
2b25d624
AD
169%%
170]])
171
da730230 172AT_BISON_CHECK([-v -o input.c input.y])
2b25d624 173
a4bf0390 174AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
2b25d624
AD
175
176AT_CLEANUP
177
178
c95f2d78
AD
179## ------------------ ##
180## Duplicate string. ##
181## ------------------ ##
182
183
184AT_SETUP([Duplicate string])
185
f499b062 186AT_DATA([input.y],
c95f2d78
AD
187[[/* `Bison -v' used to dump core when two tokens are defined with the same
188 string, as LE and GE below. */
189
190%token NUM
191%token LE "<="
192%token GE "<="
193
194%%
195exp: '(' exp ')' | NUM ;
196%%
197]])
198
da730230 199AT_BISON_CHECK([-v -o input.c input.y], 0, [],
a5d50994 200[[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
69078d4b 201]])
c95f2d78 202
d803322e 203AT_CLEANUP
c95f2d78
AD
204
205
2ca209c1
AD
206## ------------------- ##
207## Rule Line Numbers. ##
208## ------------------- ##
209
210AT_SETUP([Rule Line Numbers])
211
6b98e4b5
AD
212AT_KEYWORDS([report])
213
2ca209c1
AD
214AT_DATA([input.y],
215[[%%
216expr:
217'a'
218
219{
220
221}
222
223'b'
224
225{
226
227}
228
229|
230
231
232{
233
234
235}
236
237'c'
238
239{
240
bfcf1f3a 241};
2ca209c1
AD
242]])
243
da730230 244AT_BISON_CHECK([-o input.c -v input.y])
2ca209c1
AD
245
246# Check the contents of the report.
247AT_CHECK([cat input.output], [],
d2d1b42b 248[[Grammar
2ca209c1 249
88bce5a2 250 0 $accept: expr $end
6b98e4b5 251
f91b1629 252 1 $@1: /* empty */
6b98e4b5 253
f91b1629 254 2 expr: 'a' $@1 'b'
6b98e4b5 255
f91b1629 256 3 $@2: /* empty */
6b98e4b5 257
f91b1629 258 4 expr: $@2 'c'
2ca209c1 259
d2d1b42b 260
2ca209c1
AD
261Terminals, with rules where they appear
262
88bce5a2 263$end (0) 0
2ca209c1
AD
264'a' (97) 2
265'b' (98) 2
266'c' (99) 4
267error (256)
268
d2d1b42b 269
2ca209c1
AD
270Nonterminals, with rules where they appear
271
88bce5a2 272$accept (6)
b365aa05
AD
273 on left: 0
274expr (7)
275 on left: 2 4, on right: 0
f91b1629 276$@1 (8)
2ca209c1 277 on left: 1, on right: 2
f91b1629 278$@2 (9)
2ca209c1
AD
279 on left: 3, on right: 4
280
281
282state 0
283
88bce5a2 284 0 $accept: . expr $end
643a5994 285
87675353 286 'a' shift, and go to state 1
2ca209c1 287
f91b1629 288 $default reduce using rule 3 ($@2)
2ca209c1 289
87675353 290 expr go to state 2
f91b1629 291 $@2 go to state 3
2ca209c1
AD
292
293
294state 1
295
f91b1629 296 2 expr: 'a' . $@1 'b'
2ca209c1 297
f91b1629 298 $default reduce using rule 1 ($@1)
2ca209c1 299
f91b1629 300 $@1 go to state 4
2ca209c1
AD
301
302
303state 2
304
88bce5a2 305 0 $accept: expr . $end
2ca209c1 306
88bce5a2 307 $end shift, and go to state 5
2ca209c1
AD
308
309
310state 3
311
f91b1629 312 4 expr: $@2 . 'c'
2ca209c1 313
87675353 314 'c' shift, and go to state 6
2ca209c1
AD
315
316
317state 4
318
f91b1629 319 2 expr: 'a' $@1 . 'b'
2ca209c1 320
87675353 321 'b' shift, and go to state 7
2ca209c1
AD
322
323
324state 5
325
88bce5a2 326 0 $accept: expr $end .
2ca209c1 327
e8832397 328 $default accept
2ca209c1
AD
329
330
331state 6
332
f91b1629 333 4 expr: $@2 'c' .
b365aa05 334
87675353 335 $default reduce using rule 4 (expr)
2ca209c1
AD
336
337
338state 7
339
f91b1629 340 2 expr: 'a' $@1 'b' .
b365aa05 341
87675353 342 $default reduce using rule 2 (expr)
2ca209c1
AD
343]])
344
345AT_CLEANUP
346
347
348
cd5aafcf
AD
349## ---------------------- ##
350## Mixing %token styles. ##
351## ---------------------- ##
352
353
354AT_SETUP([Mixing %token styles])
355
356# Taken from the documentation.
357AT_DATA([input.y],
358[[%token <operator> OR "||"
359%token <operator> LE 134 "<="
360%left OR "<="
361%%
362exp: ;
363%%
364]])
365
da730230 366AT_BISON_CHECK([-v -o input.c input.y])
cd5aafcf 367
d803322e 368AT_CLEANUP
cd5aafcf
AD
369
370
371
29ae55f1
AD
372## ---------------- ##
373## Invalid inputs. ##
374## ---------------- ##
561f9a30
AD
375
376
29ae55f1 377AT_SETUP([Invalid inputs])
561f9a30
AD
378
379AT_DATA([input.y],
380[[%%
381?
561f9a30 382default: 'a' }
29ae55f1 383%&
2dfbfc12 384%a-does-not-exist
29ae55f1 385%-
e9955c83 386%{
561f9a30
AD
387]])
388
da730230 389AT_BISON_CHECK([input.y], [1], [],
e9955c83
AD
390[[input.y:2.1: invalid character: `?'
391input.y:3.14: invalid character: `}'
392input.y:4.1: invalid character: `%'
393input.y:4.2: invalid character: `&'
2dfbfc12 394input.y:5.1-17: invalid directive: `%a-does-not-exist'
e9955c83
AD
395input.y:6.1: invalid character: `%'
396input.y:6.2: invalid character: `-'
2115939b 397input.y:7.1-8.0: missing `%}' at end of file
47aee066 398input.y:7.1-8.0: syntax error, unexpected %{...%}
e0c40012 399]])
561f9a30
AD
400
401AT_CLEANUP
402
403
fc01665e
PE
404AT_SETUP([Invalid inputs with {}])
405
406AT_DATA([input.y],
407[[
408%destructor
409%initial-action
410%lex-param
411%parse-param
412%printer
413%union
414]])
415
da730230 416AT_BISON_CHECK([input.y], [1], [],
e9071366 417[[input.y:3.1-15: syntax error, unexpected %initial-action, expecting {...}
fc01665e
PE
418]])
419
420AT_CLEANUP
421
422
270a173c 423
b87f8b21
AD
424## ------------------- ##
425## Token definitions. ##
426## ------------------- ##
427
428
429AT_SETUP([Token definitions])
430
431# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
9501dc6e 432AT_DATA_GRAMMAR([input.y],
db7c8e9a 433[%{
cf806753 434#include <stdlib.h>
ca407bdf 435#include <stdio.h>
db7c8e9a
AD
436void yyerror (const char *s);
437int yylex (void);
438%}
ca407bdf
PE
439[%error-verbose
440%token MYEOF 0 "end of file"
b87f8b21 441%token 'a' "a"
4f136612
PE
442%token B_TOKEN "b"
443%token C_TOKEN 'c'
444%token 'd' D_TOKEN
3d54b576 445%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
1cfe6375 446%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
b87f8b21 447%%
3d54b576 448exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
ca407bdf
PE
449%%
450void
451yyerror (char const *s)
452{
453 fprintf (stderr, "%s\n", s);
454}
455
456int
457yylex (void)
458{
cf806753
PE
459 static int called;
460 if (called++)
461 abort ();
ca407bdf
PE
462 return SPECIAL;
463}
464
465int
466main (void)
467{
468 return yyparse ();
469}
b87f8b21
AD
470]])
471
1cfe6375
JD
472# Checking the warning message guarantees that the trigraph "??!" isn't
473# unnecessarily escaped here even though it would need to be if encoded in a
474# C-string literal. Also notice that unnecessary escaping, such as "\?", from
475# the user specification is eliminated.
476AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
477[[input.y:22.8-14: warning: symbol SPECIAL redeclared
478input.y:22.8-63: warning: symbol `"\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!"' used more than once as a literal string
479]])
ca407bdf 480AT_COMPILE([input])
1cfe6375
JD
481
482# Checking the error message here guarantees that yytname, which does contain
483# C-string literals, does have the trigraph escaped correctly. Thus, the
484# symbol name reported by the parser is exactly the same as that reported by
485# Bison itself.
3d54b576 486AT_DATA([experr],
1cfe6375 487[[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a
3d54b576
PE
488]])
489AT_PARSER_CHECK([./input], 1, [], [experr])
b87f8b21
AD
490AT_CLEANUP
491
492
493
eb714592
AD
494## -------------------- ##
495## Characters Escapes. ##
496## -------------------- ##
497
498
499AT_SETUP([Characters Escapes])
500
9501dc6e 501AT_DATA_GRAMMAR([input.y],
eb714592
AD
502[%{
503void yyerror (const char *s);
504int yylex (void);
505%}
6d0ef4ec 506[%%
eb714592
AD
507exp:
508 '\'' "\'"
509| '\"' "\""
510| '"' "'"
511;
512]])
9501dc6e 513# Pacify font-lock-mode: "
eb714592 514
da730230 515AT_BISON_CHECK([-o input.c input.y])
eb714592
AD
516AT_COMPILE([input.o], [-c input.c])
517AT_CLEANUP
518
519
520
b9752825
AD
521## -------------- ##
522## Web2c Report. ##
523## -------------- ##
776209d6
AD
524
525# The generation of the reduction was once wrong in Bison, and made it
526# miss some reductions. In the following test case, the reduction on
527# `undef_id_tok' in state 1 was missing. This is stripped down from
528# the actual web2c.y.
529
b9752825 530AT_SETUP([Web2c Report])
776209d6 531
6b98e4b5
AD
532AT_KEYWORDS([report])
533
776209d6
AD
534AT_DATA([input.y],
535[[%token undef_id_tok const_id_tok
536
537%start CONST_DEC_PART
538\f
539%%
540CONST_DEC_PART:
541 CONST_DEC_LIST
542 ;
543
544CONST_DEC_LIST:
545 CONST_DEC
546 | CONST_DEC_LIST CONST_DEC
547 ;
548
549CONST_DEC:
550 { } undef_id_tok '=' const_id_tok ';'
551 ;
552%%
776209d6
AD
553]])
554
da730230 555AT_BISON_CHECK([-v input.y])
87675353 556AT_CHECK([cat input.output], 0,
776209d6 557[[Grammar
87675353 558
88bce5a2 559 0 $accept: CONST_DEC_PART $end
87675353 560
6b98e4b5 561 1 CONST_DEC_PART: CONST_DEC_LIST
87675353 562
6b98e4b5
AD
563 2 CONST_DEC_LIST: CONST_DEC
564 3 | CONST_DEC_LIST CONST_DEC
87675353 565
f91b1629 566 4 $@1: /* empty */
87675353 567
f91b1629 568 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';'
87675353
AD
569
570
776209d6 571Terminals, with rules where they appear
87675353 572
88bce5a2 573$end (0) 0
776209d6
AD
574';' (59) 5
575'=' (61) 5
576error (256)
007a50a4
AD
577undef_id_tok (258) 5
578const_id_tok (259) 5
87675353
AD
579
580
776209d6 581Nonterminals, with rules where they appear
87675353 582
88bce5a2 583$accept (7)
78d5bae9
AD
584 on left: 0
585CONST_DEC_PART (8)
586 on left: 1, on right: 0
587CONST_DEC_LIST (9)
776209d6 588 on left: 2 3, on right: 1 3
78d5bae9 589CONST_DEC (10)
776209d6 590 on left: 5, on right: 2 3
f91b1629 591$@1 (11)
776209d6 592 on left: 4, on right: 5
87675353
AD
593
594
776209d6 595state 0
87675353 596
88bce5a2 597 0 $accept: . CONST_DEC_PART $end
87675353 598
f91b1629 599 $default reduce using rule 4 ($@1)
87675353
AD
600
601 CONST_DEC_PART go to state 1
602 CONST_DEC_LIST go to state 2
603 CONST_DEC go to state 3
f91b1629 604 $@1 go to state 4
87675353
AD
605
606
776209d6 607state 1
87675353 608
88bce5a2 609 0 $accept: CONST_DEC_PART . $end
87675353 610
88bce5a2 611 $end shift, and go to state 5
87675353
AD
612
613
78d5bae9 614state 2
87675353 615
ce4ccb4b
AD
616 1 CONST_DEC_PART: CONST_DEC_LIST .
617 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
87675353 618
f91b1629 619 undef_id_tok reduce using rule 4 ($@1)
87675353
AD
620 $default reduce using rule 1 (CONST_DEC_PART)
621
622 CONST_DEC go to state 6
f91b1629 623 $@1 go to state 4
87675353
AD
624
625
78d5bae9 626state 3
87675353 627
ce4ccb4b 628 2 CONST_DEC_LIST: CONST_DEC .
87675353
AD
629
630 $default reduce using rule 2 (CONST_DEC_LIST)
631
632
776209d6 633state 4
87675353 634
f91b1629 635 5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';'
87675353
AD
636
637 undef_id_tok shift, and go to state 7
638
639
78d5bae9 640state 5
87675353 641
88bce5a2 642 0 $accept: CONST_DEC_PART $end .
87675353 643
e8832397 644 $default accept
87675353
AD
645
646
78d5bae9 647state 6
87675353 648
ce4ccb4b 649 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
87675353
AD
650
651 $default reduce using rule 3 (CONST_DEC_LIST)
652
653
78d5bae9 654state 7
87675353 655
f91b1629 656 5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';'
87675353
AD
657
658 '=' shift, and go to state 8
659
660
78d5bae9 661state 8
87675353 662
f91b1629 663 5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';'
87675353
AD
664
665 const_id_tok shift, and go to state 9
666
667
78d5bae9 668state 9
87675353 669
f91b1629 670 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';'
87675353
AD
671
672 ';' shift, and go to state 10
673
674
78d5bae9 675state 10
87675353 676
f91b1629 677 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' .
87675353
AD
678
679 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
680]])
681
682AT_CLEANUP
b9752825
AD
683
684
685## --------------- ##
686## Web2c Actions. ##
687## --------------- ##
688
689# The generation of the mapping `state -> action' was once wrong in
690# extremely specific situations. web2c.y exhibits this situation.
691# Below is a stripped version of the grammar. It looks like one can
692# simplify it further, but just don't: it is tuned to exhibit a bug,
693# which disapears when applying sane grammar transformations.
694#
695# It used to be wrong on yydefact only:
696#
d42cf844 697# static const yytype_uint8 yydefact[] =
b9752825
AD
698# {
699# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
700# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
701# 0, 0
702# };
703#
704# but let's check all the tables.
705
706
707AT_SETUP([Web2c Actions])
708
6b98e4b5
AD
709AT_KEYWORDS([report])
710
b9752825
AD
711AT_DATA([input.y],
712[[%%
713statement: struct_stat;
714struct_stat: /* empty. */ | if else;
715if: "if" "const" "then" statement;
716else: "else" statement;
717%%
718]])
719
da730230 720AT_BISON_CHECK([-v -o input.c input.y])
b9752825 721
728c4be2 722# Check only the tables.
ce4ccb4b
AD
723[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
724
725AT_CHECK([[cat tables.c]], 0,
d42cf844 726[[static const yytype_uint8 yytranslate[] =
b9752825
AD
727{
728 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
729 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
730 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
731 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
732 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
733 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
734 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
735 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
736 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
737 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
738 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
739 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
740 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
741 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
742 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
743 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
744 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
745 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
746 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
747 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
748 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
749 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
750 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
751 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
752 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
007a50a4
AD
753 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
754 5, 6
b9752825 755};
d42cf844 756static const yytype_uint8 yyprhs[] =
b9752825 757{
e7b8bef1 758 0, 0, 3, 5, 6, 9, 14
b9752825 759};
d42cf844 760static const yytype_int8 yyrhs[] =
b9752825 761{
e7b8bef1
AD
762 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
763 4, 5, 8, -1, 6, 8, -1
b9752825 764};
d42cf844 765static const yytype_uint8 yyrline[] =
b9752825 766{
e7b8bef1 767 0, 2, 2, 3, 3, 4, 5
b9752825
AD
768};
769static const char *const yytname[] =
770{
9e0876fb
PE
771 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
772 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
b9752825 773};
d42cf844 774static const yytype_uint16 yytoknum[] =
b9752825 775{
3650b4b8 776 0, 256, 257, 258, 259, 260, 261
b9752825 777};
d42cf844 778static const yytype_uint8 yyr1[] =
b9752825 779{
e7b8bef1 780 0, 7, 8, 9, 9, 10, 11
b9752825 781};
d42cf844 782static const yytype_uint8 yyr2[] =
b9752825 783{
e7b8bef1 784 0, 2, 1, 0, 2, 4, 2
b9752825 785};
d42cf844 786static const yytype_uint8 yydefact[] =
b9752825 787{
e8832397 788 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
e7b8bef1 789 6, 5
b9752825 790};
d42cf844 791static const yytype_int8 yydefgoto[] =
b9752825 792{
e7b8bef1 793 -1, 2, 3, 4, 8
b9752825 794};
d42cf844 795static const yytype_int8 yypact[] =
b9752825 796{
12b0043a
AD
797 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
798 -8, -8
b9752825 799};
d42cf844 800static const yytype_int8 yypgoto[] =
b9752825 801{
12b0043a 802 -8, -7, -8, -8, -8
b9752825 803};
d42cf844 804static const yytype_uint8 yytable[] =
b9752825 805{
e7b8bef1 806 10, 1, 11, 5, 6, 0, 7, 9
b9752825 807};
d42cf844 808static const yytype_int8 yycheck[] =
b9752825 809{
e7b8bef1 810 7, 3, 9, 4, 0, -1, 6, 5
b9752825 811};
d42cf844 812static const yytype_uint8 yystos[] =
5504898e
AD
813{
814 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
815 8, 8
816};
b9752825
AD
817]])
818
819AT_CLEANUP
22e304a6
AD
820
821
822## ------------------------- ##
823## yycheck Bound Violation. ##
824## ------------------------- ##
825
826
827# _AT_DATA_DANCER_Y(BISON-OPTIONS)
828# --------------------------------
829# The following grammar, taken from Andrew Suffield's GPL'd implementation
830# of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
831# yycheck's bounds where issuing a verbose error message. Keep this test
832# so that possible bound checking compilers could check all the skeletons.
833m4_define([_AT_DATA_DANCER_Y],
834[AT_DATA_GRAMMAR([dancer.y],
835[%{
848dc439
PE
836static int yylex (AT_LALR1_CC_IF([int *], [void]));
837AT_LALR1_CC_IF([],
cf806753
PE
838[#include <stdlib.h>
839#include <stdio.h>
848dc439 840static void yyerror (const char *);])
22e304a6
AD
841%}
842$1
843%token ARROW INVALID NUMBER STRING DATA
844%defines
845%verbose
846%error-verbose
847/* Grammar follows */
848%%
849line: header body
850 ;
851
852header: '<' from ARROW to '>' type ':'
853 | '<' ARROW to '>' type ':'
854 | ARROW to type ':'
855 | type ':'
856 | '<' '>'
857 ;
858
859from: DATA
860 | STRING
861 | INVALID
862 ;
863
864to: DATA
865 | STRING
866 | INVALID
867 ;
868
869type: DATA
870 | STRING
871 | INVALID
872 ;
873
874body: /* empty */
875 | body member
876 ;
877
878member: STRING
879 | DATA
880 | '+' NUMBER
881 | '-' NUMBER
882 | NUMBER
883 | INVALID
884 ;
885%%
886AT_LALR1_CC_IF(
68e11668 887[/* A C++ error reporting function. */
22e304a6 888void
99880de5 889yy::parser::error (const location&, const std::string& m)
22e304a6 890{
efeed023 891 std::cerr << m << std::endl;
22e304a6
AD
892}
893
894int
99880de5 895yyparse ()
22e304a6 896{
99880de5 897 yy::parser parser;
fa7b79c0
PE
898#if YYDEBUG
899 parser.set_debug_level (YYDEBUG);
900#endif
22e304a6
AD
901 return parser.parse ();
902}
903],
904[static void
905yyerror (const char *s)
906{
907 fprintf (stderr, "%s\n", s);
908}])
909
910static int
848dc439 911yylex (AT_LALR1_CC_IF([int *lval], [void]))
22e304a6 912[{
cf806753 913 static int const tokens[] =
22e304a6
AD
914 {
915 ':', -1
916 };
cf806753 917 static size_t toknum;
848dc439 918 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
cf806753
PE
919 if (! (toknum < sizeof tokens / sizeof *tokens))
920 abort ();
22e304a6
AD
921 return tokens[toknum++];
922}]
923
924int
925main (void)
926{
927 return yyparse ();
928}
929])
930])# _AT_DATA_DANCER_Y
931
932
933# AT_CHECK_DANCER(BISON-OPTIONS)
934# ------------------------------
935# Generate the grammar, compile it, run it.
936m4_define([AT_CHECK_DANCER],
937[AT_SETUP([Dancer $1])
938AT_BISON_OPTION_PUSHDEFS([$1])
939_AT_DATA_DANCER_Y([$1])
da730230 940AT_BISON_CHECK([-o dancer.c dancer.y])
07971983 941AT_LALR1_CC_IF(
da730230 942 [AT_BISON_CHECK([-o dancer.cc dancer.y])
07971983 943 AT_COMPILE_CXX([dancer])],
da730230 944 [AT_BISON_CHECK([-o dancer.c dancer.y])
07971983 945 AT_COMPILE([dancer])])
22e304a6 946AT_PARSER_CHECK([./dancer], 1, [],
d5286af1 947[syntax error, unexpected ':'
22e304a6
AD
948])
949AT_BISON_OPTION_POPDEFS
950AT_CLEANUP
951])
952
953AT_CHECK_DANCER()
954AT_CHECK_DANCER([%glr-parser])
955AT_CHECK_DANCER([%skeleton "lalr1.cc"])
d6645148
PE
956
957
958## ------------------------------------------ ##
959## Diagnostic that expects two alternatives. ##
960## ------------------------------------------ ##
961
962
963# _AT_DATA_EXPECT2_Y(BISON-OPTIONS)
964# --------------------------------
965m4_define([_AT_DATA_EXPECT2_Y],
966[AT_DATA_GRAMMAR([expect2.y],
967[%{
968static int yylex (AT_LALR1_CC_IF([int *], [void]));
969AT_LALR1_CC_IF([],
970[#include <stdio.h>
c4bd5bf7 971#include <stdlib.h>
d6645148
PE
972static void yyerror (const char *);])
973%}
974$1
975%defines
976%error-verbose
977%token A 1000
978%token B
979
980%%
981program: /* empty */
982 | program e ';'
983 | program error ';';
984
985e: e '+' t | t;
986t: A | B;
987
988%%
989AT_LALR1_CC_IF(
990[/* A C++ error reporting function. */
991void
992yy::parser::error (const location&, const std::string& m)
993{
994 std::cerr << m << std::endl;
995}
996
997int
998yyparse ()
999{
1000 yy::parser parser;
1001 return parser.parse ();
1002}
1003],
1004[static void
1005yyerror (const char *s)
1006{
1007 fprintf (stderr, "%s\n", s);
1008}])
1009
1010static int
1011yylex (AT_LALR1_CC_IF([int *lval], [void]))
1012[{
cf806753 1013 static int const tokens[] =
d6645148
PE
1014 {
1015 1000, '+', '+', -1
1016 };
cf806753 1017 static size_t toknum;
d6645148 1018 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
cf806753
PE
1019 if (! (toknum < sizeof tokens / sizeof *tokens))
1020 abort ();
d6645148
PE
1021 return tokens[toknum++];
1022}]
1023
1024int
1025main (void)
1026{
1027 return yyparse ();
1028}
1029])
1030])# _AT_DATA_EXPECT2_Y
1031
1032
1033# AT_CHECK_EXPECT2(BISON-OPTIONS)
1034# ------------------------------
1035# Generate the grammar, compile it, run it.
1036m4_define([AT_CHECK_EXPECT2],
1037[AT_SETUP([Expecting two tokens $1])
1038AT_BISON_OPTION_PUSHDEFS([$1])
1039_AT_DATA_EXPECT2_Y([$1])
da730230 1040AT_BISON_CHECK([-o expect2.c expect2.y])
d6645148 1041AT_LALR1_CC_IF(
da730230 1042 [AT_BISON_CHECK([-o expect2.cc expect2.y])
d6645148 1043 AT_COMPILE_CXX([expect2])],
da730230 1044 [AT_BISON_CHECK([-o expect2.c expect2.y])
d6645148
PE
1045 AT_COMPILE([expect2])])
1046AT_PARSER_CHECK([./expect2], 1, [],
1047[syntax error, unexpected '+', expecting A or B
1048])
1049AT_BISON_OPTION_POPDEFS
1050AT_CLEANUP
1051])
1052
1053AT_CHECK_EXPECT2()
1054AT_CHECK_EXPECT2([%glr-parser])
1055AT_CHECK_EXPECT2([%skeleton "lalr1.cc"])
4210cd0b
JD
1056
1057
1058
1059## --------------------------------------------- ##
1060## Braced code in declaration in rules section. ##
1061## --------------------------------------------- ##
1062
1063AT_SETUP([Braced code in declaration in rules section])
1064
1065# Bison once mistook braced code in a declaration in the rules section to be a
1066# rule action.
1067
1068AT_DATA_GRAMMAR([input.y],
1069[[%{
1070#include <stdio.h>
381ecb06
JD
1071static void yyerror (char const *msg);
1072static int yylex (void);
4210cd0b
JD
1073%}
1074
1075%error-verbose
1076
1077%%
1078
1079start:
1080 {
1081 printf ("Bison would once convert this action to a midrule because of the"
1082 " subsequent braced code.\n");
1083 }
1084 ;
1085
1086%destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
1087%printer { fprintf (yyoutput, "PRINTER"); } 'a';
1088
1089%%
1090
381ecb06 1091static void
4210cd0b
JD
1092yyerror (char const *msg)
1093{
1094 fprintf (stderr, "%s\n", msg);
1095}
1096
381ecb06 1097static int
4210cd0b
JD
1098yylex (void)
1099{
1100 return 'a';
1101}
1102
1103int
1104main (void)
1105{
1106 yydebug = 1;
1107 return !yyparse ();
1108}
1109]])
1110
da730230 1111AT_BISON_CHECK([-t -o input.c input.y])
4210cd0b
JD
1112AT_COMPILE([input])
1113AT_PARSER_CHECK([./input], 0,
1114[[Bison would once convert this action to a midrule because of the subsequent braced code.
1115]],
1116[[Starting parse
1117Entering state 0
231ed89a 1118Reducing stack by rule 1 (line 20):
4210cd0b
JD
1119-> $$ = nterm start ()
1120Stack now 0
1121Entering state 1
1122Reading a token: Next token is token 'a' (PRINTER)
1123syntax error, unexpected 'a', expecting $end
1124Error: popping nterm start ()
1125Stack now 0
1126Cleanup: discarding lookahead token 'a' (PRINTER)
1127DESTRUCTOR
1128Stack now 0
1129]])
1130
1131AT_CLEANUP
965537bc
JD
1132
1133
1134
1135## --------------------------------- ##
1136## String alias declared after use. ##
1137## --------------------------------- ##
1138
1139AT_SETUP([String alias declared after use])
1140
1141# Bison once incorrectly asserted that the symbol number for either a token or
1142# its alias was the highest symbol number so far at the point of the alias
1143# declaration. That was true unless the declaration appeared after their first
6d0ef4ec 1144# uses and other tokens appeared in between.
965537bc
JD
1145
1146AT_DATA([input.y],
1147[[%%
1148start: 'a' "A" 'b';
1149%token 'a' "A";
1150]])
1151
da730230 1152AT_BISON_CHECK([-t -o input.c input.y])
965537bc
JD
1153
1154AT_CLEANUP
a0de5091
JD
1155
1156
1157
1158## -------------------------------- ##
1159## Extra lookahead sets in report. ##
1160## -------------------------------- ##
1161
1162AT_SETUP([[Extra lookahead sets in report]])
1163
88c78747
JD
1164# Bison prints each reduction's lookahead set only next to the associated
1165# state's one item that (1) is associated with the same rule as the reduction
1166# and (2) has its dot at the end of its RHS. Previously, Bison also
1167# erroneously printed the lookahead set next to all of the state's other items
1168# associated with the same rule. This bug affected only the `.output' file and
1169# not the generated parser source code.
a0de5091
JD
1170
1171AT_DATA([[input.y]],
1172[[%%
1173start: a | 'a' a 'a' ;
1174a: 'a' ;
1175]])
1176
da730230 1177AT_BISON_CHECK([[--report=all input.y]])
a0de5091
JD
1178AT_CHECK([[sed -n '/^state 1$/,/^state 2$/p' input.output]], [[0]],
1179[[state 1
1180
1181 2 start: 'a' . a 'a'
1182 3 a: . 'a'
1183 3 | 'a' . [$end]
1184
1185 'a' shift, and go to state 4
1186
1187 $default reduce using rule 3 (a)
1188
1189 a go to state 5
1190
1191
1192state 2
1193]])
1194
1195AT_CLEANUP
ab7f29f8
JD
1196
1197
1198
1199## ---------------------------------------- ##
1200## Token number in precedence declaration. ##
1201## ---------------------------------------- ##
1202
14da0cdd 1203AT_SETUP([[Token number in precedence declaration]])
ab7f29f8
JD
1204
1205# POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
1206# we lost this in Bison 1.50.
1207
1208AT_DATA_GRAMMAR([input.y],
1209[[%{
1210 #include <stdio.h>
1211 void yyerror (char const *);
1212 int yylex (void);
1213%}
1214
1215%error-verbose
1216%left TK1 1 TK2 2 "tok alias" 3
1217
1218%%
1219
1220start: TK1 sr_conflict "tok alias" ;
1221
1222sr_conflict:
1223 TK2
1224 | TK2 "tok alias"
1225 ;
1226
1227%%
1228
1229void
1230yyerror (char const *msg)
1231{
1232 fprintf (stderr, "%s\n", msg);
1233}
1234
1235int
1236yylex (void)
1237{
1238 static int const input[] = { 1, 2, 3, 0 };
1239 static int const *inputp = input;
1240 return *inputp++;
1241}
1242
1243int
1244main (void)
1245{
1246 return yyparse ();
1247}
1248]])
1249
1250AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
1251[[input.y:24.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias"
1252]])
1253AT_COMPILE([[input]])
1254AT_PARSER_CHECK([[./input]])
1255
1256AT_CLEANUP
14da0cdd
JD
1257
1258
1259
1260## ----------------------------------------------- ##
1261## Fix user actions without a trailing semicolon. ##
1262## ----------------------------------------------- ##
1263
1264AT_SETUP([[Fix user actions without a trailing semicolon]])
1265
1266# This feature is undocumented, but we accidentally broke it in 2.3a, and there
1267# was a complaint at:
1268# <http://lists.gnu.org/archive/html/bug-bison/2008-11/msg00001.html>.
1269
1270AT_DATA([input.y],
1271[[%%
1272start: {asdffdsa} ;
1273]])
1274
1275AT_BISON_CHECK([[-o input.c input.y]])
1276AT_CHECK([[sed -n '/asdffdsa/s/^ *//p' input.c]], [[0]],
1277[[{asdffdsa;}
1278]])
1279
1280AT_CLEANUP