]> git.saurik.com Git - bison.git/blame - tests/regression.at
tests: please clang and use ".cc", not ".c", for C++ input
[bison.git] / tests / regression.at
CommitLineData
342b8b6e 1# Bison Regressions. -*- Autotest -*-
d42cf844 2
c932d613 3# Copyright (C) 2001-2012 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
71c7e24f 27AT_BISON_OPTION_PUSHDEFS
276f48df
PE
28AT_DATA_GRAMMAR([input.y],
29[[%{
55f48c48
AD
30]AT_YYERROR_DECLARE_EXTERN[
31]AT_YYLEX_DECLARE_EXTERN[
50cce58e 32#define YYSTYPE int *
276f48df
PE
33%}
34
35%error-verbose
36
37%%
38
39program: 'x';
40]])
71c7e24f 41AT_BISON_OPTION_POPDEFS
276f48df 42
da730230 43AT_BISON_CHECK([-o input.c input.y])
91ce0b3a 44AT_COMPILE([input.o])
50cce58e 45AT_COMPILE([input.o], [-DYYDEBUG -c input.c])
276f48df
PE
46
47AT_CLEANUP
48
49
50
ddc8ede1
PE
51## ----------------- ##
52## YYSTYPE typedef. ##
53## ----------------- ##
54
55AT_SETUP([YYSTYPE typedef])
56
71c7e24f 57AT_BISON_OPTION_PUSHDEFS
ddc8ede1
PE
58AT_DATA_GRAMMAR([input.y],
59[[%{
55f48c48
AD
60]AT_YYERROR_DECLARE_EXTERN[
61]AT_YYLEX_DECLARE_EXTERN[
ddc8ede1
PE
62typedef union { char const *val; } YYSTYPE;
63%}
64
65%type <val> program
66
67%%
68
69program: { $$ = ""; };
70]])
71c7e24f 71AT_BISON_OPTION_POPDEFS
ddc8ede1 72
da730230 73AT_BISON_CHECK([-o input.c input.y])
91ce0b3a 74AT_COMPILE([input.o])
ddc8ede1
PE
75
76AT_CLEANUP
77
78
79
b931235e
JD
80## ------------------------------------- ##
81## Early token definitions with --yacc. ##
82## ------------------------------------- ##
69078d4b
AD
83
84
b931235e 85AT_SETUP([Early token definitions with --yacc])
69078d4b
AD
86
87# Found in GCJ: they expect the tokens to be defined before the user
88# prologue, so that they can use the token definitions in it.
89
71c7e24f 90AT_BISON_OPTION_PUSHDEFS
9501dc6e 91AT_DATA_GRAMMAR([input.y],
69078d4b 92[[%{
55f48c48
AD
93]AT_YYERROR_DECLARE_EXTERN[
94]AT_YYLEX_DECLARE_EXTERN[
69078d4b
AD
95%}
96
97%union
98{
99 int val;
100};
9bc0dd67
JD
101%{
102#ifndef MY_TOKEN
103# error "MY_TOKEN not defined."
104#endif
105%}
b931235e
JD
106%token MY_TOKEN
107%%
108exp: MY_TOKEN;
109%%
110]])
71c7e24f 111AT_BISON_OPTION_POPDEFS
b931235e 112
da730230 113AT_BISON_CHECK([-y -o input.c input.y])
91ce0b3a 114AT_COMPILE([input.o])
b931235e
JD
115
116AT_CLEANUP
117
118
119
120## ---------------------------------------- ##
121## Early token definitions without --yacc. ##
122## ---------------------------------------- ##
123
124
125AT_SETUP([Early token definitions without --yacc])
126
127# Found in GCJ: they expect the tokens to be defined before the user
128# prologue, so that they can use the token definitions in it.
129
71c7e24f 130AT_BISON_OPTION_PUSHDEFS
b931235e
JD
131AT_DATA_GRAMMAR([input.y],
132[[%{
133#include <stdio.h>
55f48c48
AD
134]AT_YYERROR_DECLARE_EXTERN[
135]AT_YYLEX_DECLARE_EXTERN[
b931235e 136void print_my_token (void);
9bc0dd67
JD
137%}
138
139%union
140{
141 int val;
142};
143%{
b931235e
JD
144void
145print_my_token (void)
146{
147 enum yytokentype my_token = MY_TOKEN;
148 printf ("%d\n", my_token);
149}
69078d4b
AD
150%}
151%token MY_TOKEN
152%%
153exp: MY_TOKEN;
154%%
155]])
71c7e24f 156AT_BISON_OPTION_POPDEFS
69078d4b 157
da730230 158AT_BISON_CHECK([-o input.c input.y])
91ce0b3a 159AT_COMPILE([input.o])
69078d4b
AD
160
161AT_CLEANUP
162
163
164
2b25d624
AD
165## ---------------- ##
166## Braces parsing. ##
167## ---------------- ##
168
169
69078d4b 170AT_SETUP([Braces parsing])
2b25d624 171
71c7e24f 172AT_BISON_OPTION_PUSHDEFS
2b25d624 173AT_DATA([input.y],
9874f80b 174[[/* Bison used to swallow the character after '}'. */
2b25d624
AD
175
176%%
bfcf1f3a 177exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
2b25d624
AD
178%%
179]])
71c7e24f 180AT_BISON_OPTION_POPDEFS
2b25d624 181
da730230 182AT_BISON_CHECK([-v -o input.c input.y])
2b25d624 183
a4bf0390 184AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
2b25d624
AD
185
186AT_CLEANUP
187
188
c95f2d78
AD
189## ------------------ ##
190## Duplicate string. ##
191## ------------------ ##
192
193
194AT_SETUP([Duplicate string])
195
71c7e24f 196AT_BISON_OPTION_PUSHDEFS
f499b062 197AT_DATA([input.y],
9874f80b 198[[/* 'Bison -v' used to dump core when two tokens are defined with the same
c95f2d78
AD
199 string, as LE and GE below. */
200
201%token NUM
202%token LE "<="
203%token GE "<="
204
205%%
206exp: '(' exp ')' | NUM ;
207%%
208]])
71c7e24f 209AT_BISON_OPTION_POPDEFS
c95f2d78 210
da730230 211AT_BISON_CHECK([-v -o input.c input.y], 0, [],
4c787a31 212[[input.y:6.8-14: warning: symbol "<=" used more than once as a literal string
69078d4b 213]])
c95f2d78 214
d803322e 215AT_CLEANUP
c95f2d78
AD
216
217
2ca209c1
AD
218## ------------------- ##
219## Rule Line Numbers. ##
220## ------------------- ##
221
222AT_SETUP([Rule Line Numbers])
223
6b98e4b5
AD
224AT_KEYWORDS([report])
225
71c7e24f 226AT_BISON_OPTION_PUSHDEFS
2ca209c1
AD
227AT_DATA([input.y],
228[[%%
229expr:
230'a'
231
232{
233
234}
235
236'b'
237
238{
239
240}
241
242|
243
244
245{
246
247
248}
249
250'c'
251
252{
253
bfcf1f3a 254};
2ca209c1 255]])
71c7e24f 256AT_BISON_OPTION_POPDEFS
2ca209c1 257
da730230 258AT_BISON_CHECK([-o input.c -v input.y])
2ca209c1
AD
259
260# Check the contents of the report.
261AT_CHECK([cat input.output], [],
d2d1b42b 262[[Grammar
2ca209c1 263
88bce5a2 264 0 $accept: expr $end
6b98e4b5 265
f91b1629 266 1 $@1: /* empty */
6b98e4b5 267
f91b1629 268 2 expr: 'a' $@1 'b'
6b98e4b5 269
f91b1629 270 3 $@2: /* empty */
6b98e4b5 271
f91b1629 272 4 expr: $@2 'c'
2ca209c1 273
d2d1b42b 274
2ca209c1
AD
275Terminals, with rules where they appear
276
88bce5a2 277$end (0) 0
2ca209c1
AD
278'a' (97) 2
279'b' (98) 2
280'c' (99) 4
281error (256)
282
d2d1b42b 283
2ca209c1
AD
284Nonterminals, with rules where they appear
285
88bce5a2 286$accept (6)
b365aa05
AD
287 on left: 0
288expr (7)
289 on left: 2 4, on right: 0
f91b1629 290$@1 (8)
2ca209c1 291 on left: 1, on right: 2
f91b1629 292$@2 (9)
2ca209c1
AD
293 on left: 3, on right: 4
294
295
d42fe46e 296State 0
2ca209c1 297
88bce5a2 298 0 $accept: . expr $end
643a5994 299
87675353 300 'a' shift, and go to state 1
2ca209c1 301
f91b1629 302 $default reduce using rule 3 ($@2)
2ca209c1 303
87675353 304 expr go to state 2
f91b1629 305 $@2 go to state 3
2ca209c1
AD
306
307
d42fe46e 308State 1
2ca209c1 309
f91b1629 310 2 expr: 'a' . $@1 'b'
2ca209c1 311
f91b1629 312 $default reduce using rule 1 ($@1)
2ca209c1 313
f91b1629 314 $@1 go to state 4
2ca209c1
AD
315
316
d42fe46e 317State 2
2ca209c1 318
88bce5a2 319 0 $accept: expr . $end
2ca209c1 320
88bce5a2 321 $end shift, and go to state 5
2ca209c1
AD
322
323
d42fe46e 324State 3
2ca209c1 325
f91b1629 326 4 expr: $@2 . 'c'
2ca209c1 327
87675353 328 'c' shift, and go to state 6
2ca209c1
AD
329
330
d42fe46e 331State 4
2ca209c1 332
f91b1629 333 2 expr: 'a' $@1 . 'b'
2ca209c1 334
87675353 335 'b' shift, and go to state 7
2ca209c1
AD
336
337
d42fe46e 338State 5
2ca209c1 339
88bce5a2 340 0 $accept: expr $end .
2ca209c1 341
e8832397 342 $default accept
2ca209c1
AD
343
344
d42fe46e 345State 6
2ca209c1 346
f91b1629 347 4 expr: $@2 'c' .
b365aa05 348
87675353 349 $default reduce using rule 4 (expr)
2ca209c1
AD
350
351
d42fe46e 352State 7
2ca209c1 353
f91b1629 354 2 expr: 'a' $@1 'b' .
b365aa05 355
87675353 356 $default reduce using rule 2 (expr)
2ca209c1
AD
357]])
358
359AT_CLEANUP
360
361
362
cd5aafcf
AD
363## ---------------------- ##
364## Mixing %token styles. ##
365## ---------------------- ##
366
367
368AT_SETUP([Mixing %token styles])
369
370# Taken from the documentation.
371AT_DATA([input.y],
372[[%token <operator> OR "||"
373%token <operator> LE 134 "<="
374%left OR "<="
375%%
376exp: ;
377%%
378]])
379
da730230 380AT_BISON_CHECK([-v -o input.c input.y])
cd5aafcf 381
d803322e 382AT_CLEANUP
cd5aafcf
AD
383
384
385
29ae55f1
AD
386## ---------------- ##
387## Invalid inputs. ##
388## ---------------- ##
561f9a30
AD
389
390
29ae55f1 391AT_SETUP([Invalid inputs])
561f9a30
AD
392
393AT_DATA([input.y],
394[[%%
395?
561f9a30 396default: 'a' }
29ae55f1 397%&
2dfbfc12 398%a-does-not-exist
29ae55f1 399%-
e9955c83 400%{
561f9a30
AD
401]])
402
da730230 403AT_BISON_CHECK([input.y], [1], [],
b8e7ad58
TR
404[[input.y:2.1: error: invalid character: '?'
405input.y:3.14: error: invalid character: '}'
406input.y:4.1: error: invalid character: '%'
407input.y:4.2: error: invalid character: '&'
408input.y:5.1-17: error: invalid directive: '%a-does-not-exist'
409input.y:6.1: error: invalid character: '%'
410input.y:6.2: error: invalid character: '-'
411input.y:7.1-8.0: error: missing '%}' at end of file
412input.y:7.1-8.0: error: syntax error, unexpected %{...%}
e0c40012 413]])
561f9a30
AD
414
415AT_CLEANUP
416
417
fc01665e
PE
418AT_SETUP([Invalid inputs with {}])
419
420AT_DATA([input.y],
421[[
422%destructor
423%initial-action
424%lex-param
425%parse-param
426%printer
427%union
428]])
429
da730230 430AT_BISON_CHECK([input.y], [1], [],
b8e7ad58 431[[input.y:3.1-15: error: syntax error, unexpected %initial-action, expecting {...}
fc01665e
PE
432]])
433
434AT_CLEANUP
435
436
270a173c 437
b87f8b21
AD
438## ------------------- ##
439## Token definitions. ##
440## ------------------- ##
441
442
443AT_SETUP([Token definitions])
444
71c7e24f 445AT_BISON_OPTION_PUSHDEFS
9874f80b 446# Bison managed, when fed with '%token 'f' "f"' to #define 'f'!
9501dc6e 447AT_DATA_GRAMMAR([input.y],
db7c8e9a 448[%{
cf806753 449#include <stdlib.h>
ca407bdf 450#include <stdio.h>
55f48c48
AD
451]AT_YYERROR_DECLARE[
452]AT_YYLEX_DECLARE[
db7c8e9a 453%}
ca407bdf
PE
454[%error-verbose
455%token MYEOF 0 "end of file"
b87f8b21 456%token 'a' "a"
4f136612
PE
457%token B_TOKEN "b"
458%token C_TOKEN 'c'
459%token 'd' D_TOKEN
3d54b576 460%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
1cfe6375 461%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
b87f8b21 462%%
3d54b576 463exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
ca407bdf 464%%
290a8ff2 465]AT_YYERROR_DEFINE[
087dcd78 466]AT_YYLEX_DEFINE([{ SPECIAL }])[
ca407bdf
PE
467
468int
469main (void)
470{
471 return yyparse ();
472}
b87f8b21 473]])
71c7e24f 474AT_BISON_OPTION_POPDEFS
b87f8b21 475
1cfe6375
JD
476# Checking the warning message guarantees that the trigraph "??!" isn't
477# unnecessarily escaped here even though it would need to be if encoded in a
478# C-string literal. Also notice that unnecessary escaping, such as "\?", from
479# the user specification is eliminated.
480AT_BISON_CHECK([-o input.c input.y], [[0]], [[]],
481[[input.y:22.8-14: warning: symbol SPECIAL redeclared
4c787a31 482input.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
1cfe6375 483]])
505ece51
TR
484AT_BISON_CHECK([-fcaret -o input.c input.y], [[0]], [[]],
485[[input.y:22.8-14: warning: symbol SPECIAL redeclared
486 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
487 ^^^^^^^
488input.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
489 %token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
490 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
491]])
ca407bdf 492AT_COMPILE([input])
1cfe6375
JD
493
494# Checking the error message here guarantees that yytname, which does contain
495# C-string literals, does have the trigraph escaped correctly. Thus, the
496# symbol name reported by the parser is exactly the same as that reported by
497# Bison itself.
3d54b576 498AT_DATA([experr],
1cfe6375 499[[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a
3d54b576
PE
500]])
501AT_PARSER_CHECK([./input], 1, [], [experr])
b87f8b21
AD
502AT_CLEANUP
503
504
505
eb714592
AD
506## -------------------- ##
507## Characters Escapes. ##
508## -------------------- ##
509
510
511AT_SETUP([Characters Escapes])
512
55f48c48 513AT_BISON_OPTION_PUSHDEFS
9501dc6e 514AT_DATA_GRAMMAR([input.y],
eb714592 515[%{
55f48c48
AD
516]AT_YYERROR_DECLARE_EXTERN[
517]AT_YYLEX_DECLARE_EXTERN[
eb714592 518%}
6d0ef4ec 519[%%
eb714592
AD
520exp:
521 '\'' "\'"
522| '\"' "\""
55f48c48 523| '"' "'" /* Pacify font-lock-mode: ". */
eb714592
AD
524;
525]])
55f48c48
AD
526
527AT_BISON_OPTION_POPDEFS
eb714592 528
da730230 529AT_BISON_CHECK([-o input.c input.y])
91ce0b3a 530AT_COMPILE([input.o])
eb714592
AD
531AT_CLEANUP
532
533
534
b9752825
AD
535## -------------- ##
536## Web2c Report. ##
537## -------------- ##
776209d6
AD
538
539# The generation of the reduction was once wrong in Bison, and made it
540# miss some reductions. In the following test case, the reduction on
9874f80b 541# 'undef_id_tok' in state 1 was missing. This is stripped down from
776209d6
AD
542# the actual web2c.y.
543
b9752825 544AT_SETUP([Web2c Report])
776209d6 545
6b98e4b5
AD
546AT_KEYWORDS([report])
547
776209d6
AD
548AT_DATA([input.y],
549[[%token undef_id_tok const_id_tok
550
551%start CONST_DEC_PART
552\f
553%%
554CONST_DEC_PART:
555 CONST_DEC_LIST
556 ;
557
558CONST_DEC_LIST:
559 CONST_DEC
560 | CONST_DEC_LIST CONST_DEC
561 ;
562
563CONST_DEC:
564 { } undef_id_tok '=' const_id_tok ';'
565 ;
566%%
776209d6
AD
567]])
568
da730230 569AT_BISON_CHECK([-v input.y])
87675353 570AT_CHECK([cat input.output], 0,
776209d6 571[[Grammar
87675353 572
88bce5a2 573 0 $accept: CONST_DEC_PART $end
87675353 574
6b98e4b5 575 1 CONST_DEC_PART: CONST_DEC_LIST
87675353 576
6b98e4b5
AD
577 2 CONST_DEC_LIST: CONST_DEC
578 3 | CONST_DEC_LIST CONST_DEC
87675353 579
f91b1629 580 4 $@1: /* empty */
87675353 581
f91b1629 582 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';'
87675353
AD
583
584
776209d6 585Terminals, with rules where they appear
87675353 586
88bce5a2 587$end (0) 0
776209d6
AD
588';' (59) 5
589'=' (61) 5
590error (256)
007a50a4
AD
591undef_id_tok (258) 5
592const_id_tok (259) 5
87675353
AD
593
594
776209d6 595Nonterminals, with rules where they appear
87675353 596
88bce5a2 597$accept (7)
78d5bae9
AD
598 on left: 0
599CONST_DEC_PART (8)
600 on left: 1, on right: 0
601CONST_DEC_LIST (9)
776209d6 602 on left: 2 3, on right: 1 3
78d5bae9 603CONST_DEC (10)
776209d6 604 on left: 5, on right: 2 3
f91b1629 605$@1 (11)
776209d6 606 on left: 4, on right: 5
87675353
AD
607
608
d42fe46e 609State 0
87675353 610
88bce5a2 611 0 $accept: . CONST_DEC_PART $end
87675353 612
f91b1629 613 $default reduce using rule 4 ($@1)
87675353
AD
614
615 CONST_DEC_PART go to state 1
616 CONST_DEC_LIST go to state 2
617 CONST_DEC go to state 3
f91b1629 618 $@1 go to state 4
87675353
AD
619
620
d42fe46e 621State 1
87675353 622
88bce5a2 623 0 $accept: CONST_DEC_PART . $end
87675353 624
88bce5a2 625 $end shift, and go to state 5
87675353
AD
626
627
d42fe46e 628State 2
87675353 629
ce4ccb4b
AD
630 1 CONST_DEC_PART: CONST_DEC_LIST .
631 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
87675353 632
f91b1629 633 undef_id_tok reduce using rule 4 ($@1)
87675353
AD
634 $default reduce using rule 1 (CONST_DEC_PART)
635
636 CONST_DEC go to state 6
f91b1629 637 $@1 go to state 4
87675353
AD
638
639
d42fe46e 640State 3
87675353 641
ce4ccb4b 642 2 CONST_DEC_LIST: CONST_DEC .
87675353
AD
643
644 $default reduce using rule 2 (CONST_DEC_LIST)
645
646
d42fe46e 647State 4
87675353 648
f91b1629 649 5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';'
87675353
AD
650
651 undef_id_tok shift, and go to state 7
652
653
d42fe46e 654State 5
87675353 655
88bce5a2 656 0 $accept: CONST_DEC_PART $end .
87675353 657
e8832397 658 $default accept
87675353
AD
659
660
d42fe46e 661State 6
87675353 662
ce4ccb4b 663 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
87675353
AD
664
665 $default reduce using rule 3 (CONST_DEC_LIST)
666
667
d42fe46e 668State 7
87675353 669
f91b1629 670 5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';'
87675353
AD
671
672 '=' shift, and go to state 8
673
674
d42fe46e 675State 8
87675353 676
f91b1629 677 5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';'
87675353
AD
678
679 const_id_tok shift, and go to state 9
680
681
d42fe46e 682State 9
87675353 683
f91b1629 684 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';'
87675353
AD
685
686 ';' shift, and go to state 10
687
688
d42fe46e 689State 10
87675353 690
f91b1629 691 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' .
87675353
AD
692
693 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
694]])
695
696AT_CLEANUP
b9752825
AD
697
698
699## --------------- ##
700## Web2c Actions. ##
701## --------------- ##
702
9874f80b 703# The generation of the mapping 'state -> action' was once wrong in
b9752825
AD
704# extremely specific situations. web2c.y exhibits this situation.
705# Below is a stripped version of the grammar. It looks like one can
706# simplify it further, but just don't: it is tuned to exhibit a bug,
707# which disapears when applying sane grammar transformations.
708#
709# It used to be wrong on yydefact only:
710#
d42cf844 711# static const yytype_uint8 yydefact[] =
b9752825
AD
712# {
713# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
714# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
715# 0, 0
716# };
717#
718# but let's check all the tables.
719
720
721AT_SETUP([Web2c Actions])
722
6b98e4b5
AD
723AT_KEYWORDS([report])
724
b9752825
AD
725AT_DATA([input.y],
726[[%%
727statement: struct_stat;
728struct_stat: /* empty. */ | if else;
729if: "if" "const" "then" statement;
730else: "else" statement;
731%%
732]])
733
da730230 734AT_BISON_CHECK([-v -o input.c input.y])
b9752825 735
728c4be2 736# Check only the tables.
ce4ccb4b
AD
737[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
738
739AT_CHECK([[cat tables.c]], 0,
d42cf844 740[[static const yytype_uint8 yytranslate[] =
b9752825
AD
741{
742 0, 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,
753 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
754 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
755 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
756 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
757 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
758 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
759 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
760 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
761 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
762 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
763 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
764 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
765 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
766 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
007a50a4
AD
767 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
768 5, 6
b9752825 769};
d42cf844 770static const yytype_uint8 yyprhs[] =
b9752825 771{
e7b8bef1 772 0, 0, 3, 5, 6, 9, 14
b9752825 773};
d42cf844 774static const yytype_int8 yyrhs[] =
b9752825 775{
e7b8bef1
AD
776 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
777 4, 5, 8, -1, 6, 8, -1
b9752825 778};
d42cf844 779static const yytype_uint8 yyrline[] =
b9752825 780{
e7b8bef1 781 0, 2, 2, 3, 3, 4, 5
b9752825
AD
782};
783static const char *const yytname[] =
784{
9e0876fb 785 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
ef51bfa7 786 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", YY_NULL
b9752825 787};
d42cf844 788static const yytype_uint16 yytoknum[] =
b9752825 789{
3650b4b8 790 0, 256, 257, 258, 259, 260, 261
b9752825 791};
d42cf844 792static const yytype_uint8 yyr1[] =
b9752825 793{
e7b8bef1 794 0, 7, 8, 9, 9, 10, 11
b9752825 795};
d42cf844 796static const yytype_uint8 yyr2[] =
b9752825 797{
e7b8bef1 798 0, 2, 1, 0, 2, 4, 2
b9752825 799};
d42cf844 800static const yytype_uint8 yydefact[] =
b9752825 801{
e8832397 802 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
e7b8bef1 803 6, 5
b9752825 804};
d42cf844 805static const yytype_int8 yydefgoto[] =
b9752825 806{
e7b8bef1 807 -1, 2, 3, 4, 8
b9752825 808};
d42cf844 809static const yytype_int8 yypact[] =
b9752825 810{
12b0043a
AD
811 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
812 -8, -8
b9752825 813};
d42cf844 814static const yytype_int8 yypgoto[] =
b9752825 815{
12b0043a 816 -8, -7, -8, -8, -8
b9752825 817};
d42cf844 818static const yytype_uint8 yytable[] =
b9752825 819{
e7b8bef1 820 10, 1, 11, 5, 6, 0, 7, 9
b9752825 821};
d42cf844 822static const yytype_int8 yycheck[] =
b9752825 823{
e7b8bef1 824 7, 3, 9, 4, 0, -1, 6, 5
b9752825 825};
d42cf844 826static const yytype_uint8 yystos[] =
5504898e
AD
827{
828 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
829 8, 8
830};
b9752825
AD
831]])
832
833AT_CLEANUP
22e304a6
AD
834
835
836## ------------------------- ##
837## yycheck Bound Violation. ##
838## ------------------------- ##
839
840
841# _AT_DATA_DANCER_Y(BISON-OPTIONS)
842# --------------------------------
843# The following grammar, taken from Andrew Suffield's GPL'd implementation
844# of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
845# yycheck's bounds where issuing a verbose error message. Keep this test
846# so that possible bound checking compilers could check all the skeletons.
847m4_define([_AT_DATA_DANCER_Y],
848[AT_DATA_GRAMMAR([dancer.y],
087dcd78
AD
849[[%code provides
850{
851 ]AT_YYERROR_DECLARE[
852 ]AT_YYLEX_DECLARE[
853}
22e304a6
AD
854$1
855%token ARROW INVALID NUMBER STRING DATA
856%defines
857%verbose
858%error-verbose
859/* Grammar follows */
860%%
861line: header body
862 ;
863
864header: '<' from ARROW to '>' type ':'
865 | '<' ARROW to '>' type ':'
866 | ARROW to type ':'
867 | type ':'
868 | '<' '>'
869 ;
870
871from: DATA
872 | STRING
873 | INVALID
874 ;
875
876to: DATA
877 | STRING
878 | INVALID
879 ;
880
881type: DATA
882 | STRING
883 | INVALID
884 ;
885
886body: /* empty */
887 | body member
888 ;
889
890member: STRING
891 | DATA
892 | '+' NUMBER
893 | '-' NUMBER
894 | NUMBER
895 | INVALID
896 ;
897%%
087dcd78
AD
898]AT_YYERROR_DEFINE[
899]AT_YYLEX_DEFINE([":"])[
290a8ff2
AD
900]AT_LALR1_CC_IF(
901[int
99880de5 902yyparse ()
22e304a6 903{
99880de5 904 yy::parser parser;
fa7b79c0
PE
905#if YYDEBUG
906 parser.set_debug_level (YYDEBUG);
907#endif
22e304a6
AD
908 return parser.parse ();
909}
087dcd78 910])[
22e304a6
AD
911
912int
913main (void)
914{
915 return yyparse ();
916}
087dcd78 917]])
22e304a6
AD
918])# _AT_DATA_DANCER_Y
919
920
921# AT_CHECK_DANCER(BISON-OPTIONS)
922# ------------------------------
923# Generate the grammar, compile it, run it.
924m4_define([AT_CHECK_DANCER],
925[AT_SETUP([Dancer $1])
926AT_BISON_OPTION_PUSHDEFS([$1])
927_AT_DATA_DANCER_Y([$1])
11c4e57d 928AT_FULL_COMPILE([dancer])
22e304a6 929AT_PARSER_CHECK([./dancer], 1, [],
d5286af1 930[syntax error, unexpected ':'
22e304a6
AD
931])
932AT_BISON_OPTION_POPDEFS
933AT_CLEANUP
934])
935
936AT_CHECK_DANCER()
937AT_CHECK_DANCER([%glr-parser])
938AT_CHECK_DANCER([%skeleton "lalr1.cc"])
d6645148
PE
939
940
941## ------------------------------------------ ##
942## Diagnostic that expects two alternatives. ##
943## ------------------------------------------ ##
944
945
946# _AT_DATA_EXPECT2_Y(BISON-OPTIONS)
947# --------------------------------
948m4_define([_AT_DATA_EXPECT2_Y],
949[AT_DATA_GRAMMAR([expect2.y],
71c7e24f
AD
950[[%{
951static int yylex (]AT_LALR1_CC_IF([int *], [void]));
d6645148 952AT_LALR1_CC_IF([],
71c7e24f 953[[#include <stdio.h>
c4bd5bf7 954#include <stdlib.h>
71c7e24f 955]AT_YYERROR_DECLARE])[
d6645148
PE
956%}
957$1
958%defines
959%error-verbose
960%token A 1000
961%token B
962
963%%
964program: /* empty */
965 | program e ';'
966 | program error ';';
967
968e: e '+' t | t;
969t: A | B;
970
971%%
71c7e24f
AD
972]AT_YYERROR_DEFINE[
973]AT_LALR1_CC_IF(
974[int
d6645148
PE
975yyparse ()
976{
977 yy::parser parser;
978 return parser.parse ();
979}
71c7e24f 980])[
d6645148 981
77519a7d 982#include <assert.h>
d6645148 983static int
71c7e24f
AD
984yylex (]AT_LALR1_CC_IF([int *lval], [void])[)
985{
cf806753 986 static int const tokens[] =
d6645148
PE
987 {
988 1000, '+', '+', -1
989 };
cf806753 990 static size_t toknum;
d6645148 991 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
77519a7d 992 assert (toknum < sizeof tokens / sizeof *tokens);
d6645148 993 return tokens[toknum++];
71c7e24f 994}
d6645148
PE
995
996int
997main (void)
998{
999 return yyparse ();
1000}
71c7e24f 1001]])
d6645148
PE
1002])# _AT_DATA_EXPECT2_Y
1003
1004
1005# AT_CHECK_EXPECT2(BISON-OPTIONS)
71c7e24f 1006# -------------------------------
d6645148
PE
1007# Generate the grammar, compile it, run it.
1008m4_define([AT_CHECK_EXPECT2],
1009[AT_SETUP([Expecting two tokens $1])
1010AT_BISON_OPTION_PUSHDEFS([$1])
1011_AT_DATA_EXPECT2_Y([$1])
11c4e57d 1012AT_FULL_COMPILE([expect2])
d6645148
PE
1013AT_PARSER_CHECK([./expect2], 1, [],
1014[syntax error, unexpected '+', expecting A or B
1015])
1016AT_BISON_OPTION_POPDEFS
1017AT_CLEANUP
1018])
1019
1020AT_CHECK_EXPECT2()
1021AT_CHECK_EXPECT2([%glr-parser])
1022AT_CHECK_EXPECT2([%skeleton "lalr1.cc"])
4210cd0b
JD
1023
1024
1025
1026## --------------------------------------------- ##
1027## Braced code in declaration in rules section. ##
1028## --------------------------------------------- ##
1029
1030AT_SETUP([Braced code in declaration in rules section])
1031
1032# Bison once mistook braced code in a declaration in the rules section to be a
1033# rule action.
55f48c48 1034AT_BISON_OPTION_PUSHDEFS
4210cd0b
JD
1035AT_DATA_GRAMMAR([input.y],
1036[[%{
1037#include <stdio.h>
55f48c48
AD
1038]AT_YYERROR_DECLARE[
1039]AT_YYLEX_DECLARE[
4210cd0b
JD
1040%}
1041
1042%error-verbose
1043
1044%%
1045
1046start:
1047 {
1048 printf ("Bison would once convert this action to a midrule because of the"
1049 " subsequent braced code.\n");
1050 }
1051 ;
1052
1053%destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
1054%printer { fprintf (yyoutput, "PRINTER"); } 'a';
1055
1056%%
55f48c48 1057]AT_YYERROR_DEFINE[
087dcd78 1058]AT_YYLEX_DEFINE(["a"])[
4210cd0b
JD
1059
1060int
1061main (void)
1062{
1063 yydebug = 1;
1064 return !yyparse ();
1065}
1066]])
55f48c48 1067AT_BISON_OPTION_POPDEFS
4210cd0b 1068
da730230 1069AT_BISON_CHECK([-t -o input.c input.y])
4210cd0b
JD
1070AT_COMPILE([input])
1071AT_PARSER_CHECK([./input], 0,
1072[[Bison would once convert this action to a midrule because of the subsequent braced code.
1073]],
1074[[Starting parse
1075Entering state 0
231ed89a 1076Reducing stack by rule 1 (line 20):
4210cd0b
JD
1077-> $$ = nterm start ()
1078Stack now 0
1079Entering state 1
1080Reading a token: Next token is token 'a' (PRINTER)
1081syntax error, unexpected 'a', expecting $end
1082Error: popping nterm start ()
1083Stack now 0
1084Cleanup: discarding lookahead token 'a' (PRINTER)
1085DESTRUCTOR
1086Stack now 0
1087]])
1088
1089AT_CLEANUP
965537bc
JD
1090
1091
1092
1093## --------------------------------- ##
1094## String alias declared after use. ##
1095## --------------------------------- ##
1096
1097AT_SETUP([String alias declared after use])
1098
1099# Bison once incorrectly asserted that the symbol number for either a token or
1100# its alias was the highest symbol number so far at the point of the alias
1101# declaration. That was true unless the declaration appeared after their first
6d0ef4ec 1102# uses and other tokens appeared in between.
965537bc
JD
1103
1104AT_DATA([input.y],
1105[[%%
1106start: 'a' "A" 'b';
1107%token 'a' "A";
1108]])
1109
da730230 1110AT_BISON_CHECK([-t -o input.c input.y])
965537bc
JD
1111
1112AT_CLEANUP
a0de5091
JD
1113
1114
1115
1116## -------------------------------- ##
1117## Extra lookahead sets in report. ##
1118## -------------------------------- ##
1119
1120AT_SETUP([[Extra lookahead sets in report]])
1121
88c78747
JD
1122# Bison prints each reduction's lookahead set only next to the associated
1123# state's one item that (1) is associated with the same rule as the reduction
1124# and (2) has its dot at the end of its RHS. Previously, Bison also
1125# erroneously printed the lookahead set next to all of the state's other items
9874f80b 1126# associated with the same rule. This bug affected only the '.output' file and
88c78747 1127# not the generated parser source code.
a0de5091
JD
1128
1129AT_DATA([[input.y]],
1130[[%%
1131start: a | 'a' a 'a' ;
1132a: 'a' ;
1133]])
1134
da730230 1135AT_BISON_CHECK([[--report=all input.y]])
d42fe46e
TR
1136AT_CHECK([[sed -n '/^State 1$/,/^State 2$/p' input.output]], [[0]],
1137[[State 1
a0de5091
JD
1138
1139 2 start: 'a' . a 'a'
1140 3 a: . 'a'
1141 3 | 'a' . [$end]
1142
1143 'a' shift, and go to state 4
1144
1145 $default reduce using rule 3 (a)
1146
1147 a go to state 5
1148
1149
d42fe46e 1150State 2
a0de5091
JD
1151]])
1152
1153AT_CLEANUP
ab7f29f8
JD
1154
1155
1156
1157## ---------------------------------------- ##
1158## Token number in precedence declaration. ##
1159## ---------------------------------------- ##
1160
14da0cdd 1161AT_SETUP([[Token number in precedence declaration]])
ab7f29f8
JD
1162
1163# POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
1164# we lost this in Bison 1.50.
55f48c48 1165AT_BISON_OPTION_PUSHDEFS
ab7f29f8
JD
1166AT_DATA_GRAMMAR([input.y],
1167[[%{
1168 #include <stdio.h>
55f48c48
AD
1169 ]AT_YYERROR_DECLARE[
1170 ]AT_YYLEX_DECLARE[
ab7f29f8
JD
1171%}
1172
1173%error-verbose
9d6af153 1174%right END 0
ab7f29f8
JD
1175%left TK1 1 TK2 2 "tok alias" 3
1176
1177%%
1178
9d6af153
JD
1179start:
1180 TK1 sr_conflict "tok alias"
1181 | start %prec END
1182 ;
ab7f29f8
JD
1183sr_conflict:
1184 TK2
1185 | TK2 "tok alias"
1186 ;
1187
1188%%
1189
55f48c48 1190]AT_YYERROR_DEFINE[
087dcd78 1191]AT_YYLEX_DEFINE([{ 1, 2, 3, 0 }])[
ab7f29f8
JD
1192
1193int
1194main (void)
1195{
1196 return yyparse ();
1197}
1198]])
55f48c48 1199AT_BISON_OPTION_POPDEFS
ab7f29f8
JD
1200
1201AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
9d6af153
JD
1202[[input.y:23.5-19: warning: rule useless in parser due to conflicts: start: start
1203input.y:27.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias"
ab7f29f8
JD
1204]])
1205AT_COMPILE([[input]])
1206AT_PARSER_CHECK([[./input]])
1207
1208AT_CLEANUP
873ac263
JD
1209
1210
1211
1212## --------------------------- ##
1213## parse-gram.y: LALR = IELR. ##
1214## --------------------------- ##
1215
1216# If parse-gram.y's LALR and IELR parser tables ever begin to differ, we
1217# need to fix parse-gram.y or start using IELR.
1218
1219AT_SETUP([[parse-gram.y: LALR = IELR]])
1220
1221# Avoid differences in synclines by telling bison that the output files
1222# have the same name.
4b7a4c1b
JD
1223[cp $abs_top_srcdir/src/parse-gram.y input.y]
1224AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]])
035810ed
AD
1225[mv input.c lalr.c]
1226AT_CAPTURE_FILE([lalr.c])
4b7a4c1b
JD
1227AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]])
1228[mv input.c ielr.c]
035810ed
AD
1229AT_CAPTURE_FILE([ielr.c])
1230AT_CHECK([[diff lalr.c ielr.c]], [[0]])
873ac263
JD
1231
1232AT_CLEANUP
d88cf117
JD
1233
1234
1235
1236## --------------------------------------- ##
1237## %error-verbose and YYSTACK_USE_ALLOCA. ##
1238## --------------------------------------- ##
1239
1240AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]])
1241
55f48c48 1242AT_BISON_OPTION_PUSHDEFS
d88cf117
JD
1243AT_DATA_GRAMMAR([input.y],
1244[[%code {
1245 #include <stdio.h>
55f48c48
AD
1246 ]AT_YYERROR_DECLARE[
1247 ]AT_YYLEX_DECLARE[
d88cf117
JD
1248 #define YYSTACK_USE_ALLOCA 1
1249}
1250
1251%error-verbose
1252
1253%%
1254
1255start: check syntax_error syntax_error ;
1256
1257check:
1258{
1259 if (128 < sizeof yymsgbuf)
1260 {
1261 fprintf (stderr,
1262 "The initial size of yymsgbuf in yyparse has increased\n"
1263 "since this test group was last updated. As a result,\n"
1264 "this test group may no longer manage to induce a\n"
1265 "reallocation of the syntax error message buffer.\n"
1266 "This test group must be adjusted to produce a longer\n"
1267 "error message.\n");
1268 YYABORT;
1269 }
1270}
1271;
1272
1273// Induce a syntax error message whose total length is more than
1274// sizeof yymsgbuf in yyparse. Each token here is 64 bytes.
1275syntax_error:
1276 "123456789112345678921234567893123456789412345678951234567896123A"
1277| "123456789112345678921234567893123456789412345678951234567896123B"
1278| error 'a' 'b' 'c'
1279;
1280
1281%%
1282
55f48c48
AD
1283]AT_YYERROR_DEFINE[
1284/* Induce two syntax error messages (which requires full error
1285 recovery by shifting 3 tokens) in order to detect any loss of the
1286 reallocated buffer. */
95361618 1287]AT_YYLEX_DEFINE(["abc"])[
d88cf117
JD
1288int
1289main (void)
1290{
1291 return yyparse ();
1292}
1293]])
55f48c48 1294AT_BISON_OPTION_POPDEFS
d88cf117
JD
1295
1296AT_BISON_CHECK([[-o input.c input.y]])
1297AT_COMPILE([[input]])
1298AT_PARSER_CHECK([[./input]], [[1]], [],
1299[[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1300syntax error, unexpected $end, expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1301]])
1302
1303AT_CLEANUP
1304
1305
1306
1307## ------------------------- ##
1308## %error-verbose overflow. ##
1309## ------------------------- ##
1310
1311# Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an
1312# invocation of yysyntax_error has caused yymsg_alloc to grow to exactly
1313# YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had
69a2ab11
JD
1314# to be clipped to YYSTACK_ALLOC_MAXIMUM). In an old version of yacc.c,
1315# a subsequent invocation of yysyntax_error that overflows during its
1316# size calculation would return YYSIZE_MAXIMUM to yyparse. Then,
1317# yyparse would invoke yyerror using the old contents of yymsg.
d88cf117
JD
1318
1319AT_SETUP([[%error-verbose overflow]])
55f48c48 1320AT_BISON_OPTION_PUSHDEFS
d88cf117
JD
1321AT_DATA_GRAMMAR([input.y],
1322[[%code {
1323 #include <stdio.h>
55f48c48
AD
1324 ]AT_YYERROR_DECLARE[
1325 ]AT_YYLEX_DECLARE[
d88cf117
JD
1326
1327 /* This prevents this test case from having to induce error messages
1328 large enough to overflow size_t. */
1329 #define YYSIZE_T unsigned char
1330
ea6046b9 1331 /* Bring in malloc and set EXIT_SUCCESS so yacc.c doesn't try to
23761f42 1332 provide a malloc prototype using our YYSIZE_T. */
d88cf117 1333 #include <stdlib.h>
ea6046b9
PE
1334 #ifndef EXIT_SUCCESS
1335 # define EXIT_SUCCESS 0
23761f42 1336 #endif
d88cf117
JD
1337
1338 /* Max depth is usually much smaller than YYSTACK_ALLOC_MAXIMUM, and
1339 we don't want gcc to warn everywhere this constant would be too big
1340 to make sense for our YYSIZE_T. */
1341 #define YYMAXDEPTH 100
1342}
1343
1344%error-verbose
1345
1346%%
1347
1348start: syntax_error1 check syntax_error2 ;
1349
1350// Induce a syntax error message whose total length causes yymsg in
1351// yyparse to be reallocated to size YYSTACK_ALLOC_MAXIMUM, which
1352// should be 255. Each token here is 64 bytes.
1353syntax_error1:
1354 "123456789112345678921234567893123456789412345678951234567896123A"
1355| "123456789112345678921234567893123456789412345678951234567896123B"
1356| "123456789112345678921234567893123456789412345678951234567896123C"
1357| error 'a' 'b' 'c'
1358;
1359
1360check:
1361{
1362 if (yymsg_alloc != YYSTACK_ALLOC_MAXIMUM
1363 || YYSTACK_ALLOC_MAXIMUM != YYSIZE_MAXIMUM
1364 || YYSIZE_MAXIMUM != 255)
1365 {
1366 fprintf (stderr,
1367 "The assumptions of this test group are no longer\n"
1368 "valid, so it may no longer catch the error it was\n"
1369 "designed to catch. Specifically, the following\n"
1370 "values should all be 255:\n\n");
1371 fprintf (stderr, " yymsg_alloc = %d\n", yymsg_alloc);
1372 fprintf (stderr, " YYSTACK_ALLOC_MAXIMUM = %d\n",
1373 YYSTACK_ALLOC_MAXIMUM);
1374 fprintf (stderr, " YYSIZE_MAXIMUM = %d\n", YYSIZE_MAXIMUM);
1375 YYABORT;
1376 }
1377}
1378;
1379
1380// Now overflow.
1381syntax_error2:
1382 "123456789112345678921234567893123456789412345678951234567896123A"
1383| "123456789112345678921234567893123456789412345678951234567896123B"
1384| "123456789112345678921234567893123456789412345678951234567896123C"
1385| "123456789112345678921234567893123456789412345678951234567896123D"
1386| "123456789112345678921234567893123456789412345678951234567896123E"
1387;
1388
1389%%
1390
55f48c48
AD
1391]AT_YYERROR_DEFINE[
1392/* Induce two syntax error messages (which requires full error
1393 recovery by shifting 3 tokens). */
95361618 1394]AT_YYLEX_DEFINE(["abc"])[
d88cf117
JD
1395int
1396main (void)
1397{
1398 /* Push parsers throw away the message buffer between tokens, so skip
1399 this test under maintainer-push-check. */
1400 if (YYPUSH)
1401 return 77;
1402 return yyparse ();
1403}
1404]])
1405
1406AT_BISON_CHECK([[-o input.c input.y]])
1407
1408# gcc warns about tautologies and fallacies involving comparisons for
1409# unsigned char. However, it doesn't produce these same warnings for
1410# size_t and many other types when the warnings would seem to make just
1411# as much sense. We ignore the warnings.
1412[CFLAGS="$NO_WERROR_CFLAGS"]
1413AT_COMPILE([[input]])
1414
1415AT_PARSER_CHECK([[./input]], [[2]], [],
1416[[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B or 123456789112345678921234567893123456789412345678951234567896123C
1417syntax error
1418memory exhausted
1419]])
55f48c48 1420AT_BISON_OPTION_POPDEFS
d88cf117 1421AT_CLEANUP
ea13bea8
JD
1422
1423
1424
1425## ------------------------ ##
1426## LAC: Exploratory stack. ##
1427## ------------------------ ##
1428
1429AT_SETUP([[LAC: Exploratory stack]])
1430
1431m4_pushdef([AT_LAC_CHECK], [
1432
1433AT_BISON_OPTION_PUSHDEFS([$1])
1434
1435AT_DATA_GRAMMAR([input.y],
1436[[%code {
1437 #include <stdio.h>
55f48c48 1438 ]AT_YYERROR_DECLARE[
ea13bea8
JD
1439 int yylex (]AT_PURE_IF([[YYSTYPE *]], [[void]])[);
1440}
1441
1442]$1[
1443%error-verbose
1444%token 'c'
1445
1446%%
1447
1448// default reductions in inconsistent states
1449// v v v v v v v v v v v v v v
1450S: A B A A B A A A A B A A A A A A A B C C A A A A A A A A A A A A B ;
723fe7d1
JD
1451// ^ ^ ^
1452// LAC reallocs
ea13bea8
JD
1453
1454A: 'a' | /*empty*/ { printf ("inconsistent default reduction\n"); } ;
1455B: 'b' ;
1456C: /*empty*/ { printf ("consistent default reduction\n"); } ;
1457
1458%%
55f48c48 1459]AT_YYERROR_DEFINE[
ea13bea8
JD
1460int
1461yylex (]AT_PURE_IF([[YYSTYPE *v]], [[void]])[)
1462{
1463 static char const *input = "bbbbc";]AT_PURE_IF([[
1464 *v = 0;]])[
1465 return *input++;
1466}
1467
1468int
1469main (void)
1470{
1471 yydebug = 1;
1472 return yyparse ();
1473}
1474]])
1475
723fe7d1
JD
1476AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
1477 -Dparse.lac.memory-trace=full \
ea13bea8
JD
1478 -t -o input.c input.y]], [[0]], [],
1479[[input.y: conflicts: 21 shift/reduce
1480]])
1481AT_COMPILE([[input]])
1482AT_PARSER_CHECK([[./input > stdout.txt 2> stderr.txt]], [[1]])
1483
1484# Make sure syntax error doesn't forget that 'a' is expected. It would
1485# be forgotten without lookahead correction.
1486AT_CHECK([[grep 'syntax error,' stderr.txt]], [[0]],
1487[[syntax error, unexpected 'c', expecting 'a' or 'b'
1488]])
1489
1490# Check number of default reductions in inconsistent states to be sure
1491# syntax error is detected before unnecessary reductions are performed.
ff020c30 1492AT_CHECK([[$PERL -0777 -ne 'print s/inconsistent default reduction//g;' \
ea13bea8
JD
1493 < stdout.txt || exit 77]], [[0]], [[14]])
1494
1495# Check number of default reductions in consistent states to be sure
1496# it is performed before the syntax error is detected.
ff020c30 1497AT_CHECK([[$PERL -0777 -ne 'print s/\bconsistent default reduction//g;' \
ea13bea8
JD
1498 < stdout.txt || exit 77]], [[0]], [[2]])
1499
723fe7d1
JD
1500# Check number of reallocs to be sure reallocated memory isn't somehow
1501# lost between LAC invocations.
ff020c30 1502AT_CHECK([[$PERL -0777 -ne 'print s/\(realloc//g;' < stderr.txt \
723fe7d1
JD
1503 || exit 77]], [[0]], [[3]])
1504
ea13bea8
JD
1505AT_BISON_OPTION_POPDEFS
1506])
1507
1508AT_LAC_CHECK([[%define api.push-pull pull]])
1509AT_LAC_CHECK([[%define api.push-pull pull %define api.pure]])
1510AT_LAC_CHECK([[%define api.push-pull both]])
1511AT_LAC_CHECK([[%define api.push-pull both %define api.pure]])
1512
1513m4_popdef([AT_LAC_CHECK])
1514
1515AT_CLEANUP
1516
1517
1518
1519## ------------------------ ##
1520## LAC: Memory exhaustion. ##
1521## ------------------------ ##
1522
1523AT_SETUP([[LAC: Memory exhaustion]])
1524
55f48c48
AD
1525m4_pushdef([AT_LAC_CHECK],
1526[AT_BISON_OPTION_PUSHDEFS
ea13bea8
JD
1527AT_DATA_GRAMMAR([input.y],
1528[[%code {
1529 #include <stdio.h>
55f48c48
AD
1530 ]AT_YYERROR_DECLARE[
1531 ]AT_YYLEX_DECLARE[
723fe7d1 1532 #define YYMAXDEPTH 8
ea13bea8
JD
1533}
1534
1535%error-verbose
1536
1537%%
1538
1539S: A A A A A A A A A ;
1540A: /*empty*/ | 'a' ;
1541
1542%%
55f48c48 1543]AT_YYERROR_DEFINE[
95361618 1544]AT_YYLEX_DEFINE(["$1"])[
ea13bea8
JD
1545int
1546main (void)
1547{
1548 yydebug = 1;
1549 return yyparse ();
1550}
1551]])
1552
723fe7d1 1553AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
ea13bea8
JD
1554 -t -o input.c input.y]], [[0]], [],
1555[[input.y: conflicts: 8 shift/reduce
1556]])
1557AT_COMPILE([[input]])
55f48c48 1558AT_BISON_OPTION_POPDEFS
ea13bea8
JD
1559])
1560
1561# Check for memory exhaustion during parsing.
55f48c48
AD
1562AT_LAC_CHECK([])
1563AT_PARSER_CHECK([[./input]], [[2]], [],
ea13bea8
JD
1564[[Starting parse
1565Entering state 0
1566Reading a token: Now at end of input.
1567LAC: initial context established for $end
723fe7d1 1568LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
ea13bea8
JD
1569memory exhausted
1570Cleanup: discarding lookahead token $end ()
1571Stack now 0
1572]])
1573
1574# Induce an immediate syntax error with an undefined token, and check
1575# for memory exhaustion while building syntax error message.
55f48c48
AD
1576AT_LAC_CHECK([z], [[0]])
1577AT_PARSER_CHECK([[./input]], [[2]], [],
ea13bea8
JD
1578[[Starting parse
1579Entering state 0
1580Reading a token: Next token is token $undefined ()
1581LAC: initial context established for $undefined
1582LAC: checking lookahead $undefined: Always Err
1583Constructing syntax error message
723fe7d1 1584LAC: checking lookahead $end: R2 G3 R2 G5 R2 G6 R2 G7 R2 G8 R2 G9 R2 G10 R2 G11 R2 (max size exceeded)
ea13bea8
JD
1585syntax error
1586memory exhausted
1587Cleanup: discarding lookahead token $undefined ()
1588Stack now 0
1589]])
1590
1591m4_popdef([AT_LAC_CHECK])
1592
1593AT_CLEANUP
c9d546b2
AD
1594
1595
1596## ---------------------- ##
1597## Lex and parse params. ##
1598## ---------------------- ##
1599
1600# AT_TEST(SKELETON)
1601# -----------------
1602# Check that the identifier of the params is properly fetched
1603# even when there are trailing blanks.
1604
1605m4_pushdef([AT_TEST],
1606[AT_SETUP([[Lex and parse params: $1]])
1607
3472de82 1608AT_BISON_OPTION_PUSHDEFS([%locations %skeleton "$1" %parse-param { int x } %parse-param { int y }])
c9d546b2
AD
1609
1610## FIXME: Improve parsing of parse-param and use the generated
1611## yyerror.
1612AT_DATA_GRAMMAR([input.y],
1613[[%defines
1614%locations
3472de82 1615%skeleton "$1"
c9d546b2
AD
1616%union { int ival; }
1617%parse-param { int x }
1618// Spaces, tabs, and new lines.
1619%parse-param { @&t@
1620 int y @&t@
1621 @&t@
1622 @&t@
1623}
1624
1625%{
1626#include <stdio.h>
1627#include <stdlib.h>
1628
3472de82 1629 ]AT_YYERROR_DECLARE[
c9d546b2
AD
1630 ]AT_YYLEX_DECLARE[
1631%}
1632
1633%%
1634exp: 'a' { fprintf (stdout, "x: %d, y: %d\n", x, y); };
1635%%
3472de82 1636]AT_YYERROR_DEFINE[
c9d546b2
AD
1637]AT_YYLEX_DEFINE(["a"])[
1638
1639]AT_SKEL_CC_IF(
3472de82 1640[int
c9d546b2
AD
1641yyparse (int x, int y)
1642{
1643 yy::parser parser(x, y);
1644 return parser.parse ();
1645}
1646])[
1647
1648int
1649main (void)
1650{
1651 return !!yyparse(1, 2);
1652}
1653]])
1654
1655AT_FULL_COMPILE([input])
2bb8f621 1656AT_PARSER_CHECK([./input], 0, [[x: 1, y: 2
c9d546b2
AD
1657]])
1658AT_BISON_OPTION_POPDEFS
1659
1660AT_CLEANUP
1661])
1662
1663## FIXME: test Java, and iterate over skeletons.
3472de82
AD
1664AT_TEST([yacc.c])
1665AT_TEST([glr.c])
1666AT_TEST([lalr1.cc])
1667AT_TEST([glr.cc])
c9d546b2
AD
1668
1669m4_popdef([AT_TEST])