]> git.saurik.com Git - bison.git/blame - tests/regression.at
tests: fix SKIP_IF for Java.
[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
296state 0
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
308state 1
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
317state 2
318
88bce5a2 319 0 $accept: expr . $end
2ca209c1 320
88bce5a2 321 $end shift, and go to state 5
2ca209c1
AD
322
323
324state 3
325
f91b1629 326 4 expr: $@2 . 'c'
2ca209c1 327
87675353 328 'c' shift, and go to state 6
2ca209c1
AD
329
330
331state 4
332
f91b1629 333 2 expr: 'a' $@1 . 'b'
2ca209c1 334
87675353 335 'b' shift, and go to state 7
2ca209c1
AD
336
337
338state 5
339
88bce5a2 340 0 $accept: expr $end .
2ca209c1 341
e8832397 342 $default accept
2ca209c1
AD
343
344
345state 6
346
f91b1629 347 4 expr: $@2 'c' .
b365aa05 348
87675353 349 $default reduce using rule 4 (expr)
2ca209c1
AD
350
351
352state 7
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], [],
9874f80b
JM
404[[input.y:2.1: invalid character: '?'
405input.y:3.14: invalid character: '}'
406input.y:4.1: invalid character: '%'
407input.y:4.2: invalid character: '&'
408input.y:5.1-17: invalid directive: '%a-does-not-exist'
409input.y:6.1: invalid character: '%'
410input.y:6.2: invalid character: '-'
411input.y:7.1-8.0: missing '%}' at end of file
47aee066 412input.y:7.1-8.0: 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], [],
e9071366 431[[input.y:3.1-15: 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]])
ca407bdf 484AT_COMPILE([input])
1cfe6375
JD
485
486# Checking the error message here guarantees that yytname, which does contain
487# C-string literals, does have the trigraph escaped correctly. Thus, the
488# symbol name reported by the parser is exactly the same as that reported by
489# Bison itself.
3d54b576 490AT_DATA([experr],
1cfe6375 491[[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201??!", expecting a
3d54b576
PE
492]])
493AT_PARSER_CHECK([./input], 1, [], [experr])
b87f8b21
AD
494AT_CLEANUP
495
496
497
eb714592
AD
498## -------------------- ##
499## Characters Escapes. ##
500## -------------------- ##
501
502
503AT_SETUP([Characters Escapes])
504
55f48c48 505AT_BISON_OPTION_PUSHDEFS
9501dc6e 506AT_DATA_GRAMMAR([input.y],
eb714592 507[%{
55f48c48
AD
508]AT_YYERROR_DECLARE_EXTERN[
509]AT_YYLEX_DECLARE_EXTERN[
eb714592 510%}
6d0ef4ec 511[%%
eb714592
AD
512exp:
513 '\'' "\'"
514| '\"' "\""
55f48c48 515| '"' "'" /* Pacify font-lock-mode: ". */
eb714592
AD
516;
517]])
55f48c48
AD
518
519AT_BISON_OPTION_POPDEFS
eb714592 520
da730230 521AT_BISON_CHECK([-o input.c input.y])
91ce0b3a 522AT_COMPILE([input.o])
eb714592
AD
523AT_CLEANUP
524
525
526
b9752825
AD
527## -------------- ##
528## Web2c Report. ##
529## -------------- ##
776209d6
AD
530
531# The generation of the reduction was once wrong in Bison, and made it
532# miss some reductions. In the following test case, the reduction on
9874f80b 533# 'undef_id_tok' in state 1 was missing. This is stripped down from
776209d6
AD
534# the actual web2c.y.
535
b9752825 536AT_SETUP([Web2c Report])
776209d6 537
6b98e4b5
AD
538AT_KEYWORDS([report])
539
776209d6
AD
540AT_DATA([input.y],
541[[%token undef_id_tok const_id_tok
542
543%start CONST_DEC_PART
544\f
545%%
546CONST_DEC_PART:
547 CONST_DEC_LIST
548 ;
549
550CONST_DEC_LIST:
551 CONST_DEC
552 | CONST_DEC_LIST CONST_DEC
553 ;
554
555CONST_DEC:
556 { } undef_id_tok '=' const_id_tok ';'
557 ;
558%%
776209d6
AD
559]])
560
da730230 561AT_BISON_CHECK([-v input.y])
87675353 562AT_CHECK([cat input.output], 0,
776209d6 563[[Grammar
87675353 564
88bce5a2 565 0 $accept: CONST_DEC_PART $end
87675353 566
6b98e4b5 567 1 CONST_DEC_PART: CONST_DEC_LIST
87675353 568
6b98e4b5
AD
569 2 CONST_DEC_LIST: CONST_DEC
570 3 | CONST_DEC_LIST CONST_DEC
87675353 571
f91b1629 572 4 $@1: /* empty */
87675353 573
f91b1629 574 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';'
87675353
AD
575
576
776209d6 577Terminals, with rules where they appear
87675353 578
88bce5a2 579$end (0) 0
776209d6
AD
580';' (59) 5
581'=' (61) 5
582error (256)
007a50a4
AD
583undef_id_tok (258) 5
584const_id_tok (259) 5
87675353
AD
585
586
776209d6 587Nonterminals, with rules where they appear
87675353 588
88bce5a2 589$accept (7)
78d5bae9
AD
590 on left: 0
591CONST_DEC_PART (8)
592 on left: 1, on right: 0
593CONST_DEC_LIST (9)
776209d6 594 on left: 2 3, on right: 1 3
78d5bae9 595CONST_DEC (10)
776209d6 596 on left: 5, on right: 2 3
f91b1629 597$@1 (11)
776209d6 598 on left: 4, on right: 5
87675353
AD
599
600
776209d6 601state 0
87675353 602
88bce5a2 603 0 $accept: . CONST_DEC_PART $end
87675353 604
f91b1629 605 $default reduce using rule 4 ($@1)
87675353
AD
606
607 CONST_DEC_PART go to state 1
608 CONST_DEC_LIST go to state 2
609 CONST_DEC go to state 3
f91b1629 610 $@1 go to state 4
87675353
AD
611
612
776209d6 613state 1
87675353 614
88bce5a2 615 0 $accept: CONST_DEC_PART . $end
87675353 616
88bce5a2 617 $end shift, and go to state 5
87675353
AD
618
619
78d5bae9 620state 2
87675353 621
ce4ccb4b
AD
622 1 CONST_DEC_PART: CONST_DEC_LIST .
623 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
87675353 624
f91b1629 625 undef_id_tok reduce using rule 4 ($@1)
87675353
AD
626 $default reduce using rule 1 (CONST_DEC_PART)
627
628 CONST_DEC go to state 6
f91b1629 629 $@1 go to state 4
87675353
AD
630
631
78d5bae9 632state 3
87675353 633
ce4ccb4b 634 2 CONST_DEC_LIST: CONST_DEC .
87675353
AD
635
636 $default reduce using rule 2 (CONST_DEC_LIST)
637
638
776209d6 639state 4
87675353 640
f91b1629 641 5 CONST_DEC: $@1 . undef_id_tok '=' const_id_tok ';'
87675353
AD
642
643 undef_id_tok shift, and go to state 7
644
645
78d5bae9 646state 5
87675353 647
88bce5a2 648 0 $accept: CONST_DEC_PART $end .
87675353 649
e8832397 650 $default accept
87675353
AD
651
652
78d5bae9 653state 6
87675353 654
ce4ccb4b 655 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
87675353
AD
656
657 $default reduce using rule 3 (CONST_DEC_LIST)
658
659
78d5bae9 660state 7
87675353 661
f91b1629 662 5 CONST_DEC: $@1 undef_id_tok . '=' const_id_tok ';'
87675353
AD
663
664 '=' shift, and go to state 8
665
666
78d5bae9 667state 8
87675353 668
f91b1629 669 5 CONST_DEC: $@1 undef_id_tok '=' . const_id_tok ';'
87675353
AD
670
671 const_id_tok shift, and go to state 9
672
673
78d5bae9 674state 9
87675353 675
f91b1629 676 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok . ';'
87675353
AD
677
678 ';' shift, and go to state 10
679
680
78d5bae9 681state 10
87675353 682
f91b1629 683 5 CONST_DEC: $@1 undef_id_tok '=' const_id_tok ';' .
87675353
AD
684
685 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
686]])
687
688AT_CLEANUP
b9752825
AD
689
690
691## --------------- ##
692## Web2c Actions. ##
693## --------------- ##
694
9874f80b 695# The generation of the mapping 'state -> action' was once wrong in
b9752825
AD
696# extremely specific situations. web2c.y exhibits this situation.
697# Below is a stripped version of the grammar. It looks like one can
698# simplify it further, but just don't: it is tuned to exhibit a bug,
699# which disapears when applying sane grammar transformations.
700#
701# It used to be wrong on yydefact only:
702#
d42cf844 703# static const yytype_uint8 yydefact[] =
b9752825
AD
704# {
705# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
706# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
707# 0, 0
708# };
709#
710# but let's check all the tables.
711
712
713AT_SETUP([Web2c Actions])
714
6b98e4b5
AD
715AT_KEYWORDS([report])
716
b9752825
AD
717AT_DATA([input.y],
718[[%%
719statement: struct_stat;
720struct_stat: /* empty. */ | if else;
721if: "if" "const" "then" statement;
722else: "else" statement;
723%%
724]])
725
da730230 726AT_BISON_CHECK([-v -o input.c input.y])
b9752825 727
728c4be2 728# Check only the tables.
ce4ccb4b
AD
729[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
730
731AT_CHECK([[cat tables.c]], 0,
d42cf844 732[[static const yytype_uint8 yytranslate[] =
b9752825
AD
733{
734 0, 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,
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,
007a50a4
AD
759 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
760 5, 6
b9752825 761};
d42cf844 762static const yytype_uint8 yyprhs[] =
b9752825 763{
e7b8bef1 764 0, 0, 3, 5, 6, 9, 14
b9752825 765};
d42cf844 766static const yytype_int8 yyrhs[] =
b9752825 767{
e7b8bef1
AD
768 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
769 4, 5, 8, -1, 6, 8, -1
b9752825 770};
d42cf844 771static const yytype_uint8 yyrline[] =
b9752825 772{
e7b8bef1 773 0, 2, 2, 3, 3, 4, 5
b9752825
AD
774};
775static const char *const yytname[] =
776{
9e0876fb 777 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
ef51bfa7 778 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", YY_NULL
b9752825 779};
d42cf844 780static const yytype_uint16 yytoknum[] =
b9752825 781{
3650b4b8 782 0, 256, 257, 258, 259, 260, 261
b9752825 783};
d42cf844 784static const yytype_uint8 yyr1[] =
b9752825 785{
e7b8bef1 786 0, 7, 8, 9, 9, 10, 11
b9752825 787};
d42cf844 788static const yytype_uint8 yyr2[] =
b9752825 789{
e7b8bef1 790 0, 2, 1, 0, 2, 4, 2
b9752825 791};
d42cf844 792static const yytype_uint8 yydefact[] =
b9752825 793{
e8832397 794 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
e7b8bef1 795 6, 5
b9752825 796};
d42cf844 797static const yytype_int8 yydefgoto[] =
b9752825 798{
e7b8bef1 799 -1, 2, 3, 4, 8
b9752825 800};
d42cf844 801static const yytype_int8 yypact[] =
b9752825 802{
12b0043a
AD
803 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
804 -8, -8
b9752825 805};
d42cf844 806static const yytype_int8 yypgoto[] =
b9752825 807{
12b0043a 808 -8, -7, -8, -8, -8
b9752825 809};
d42cf844 810static const yytype_uint8 yytable[] =
b9752825 811{
e7b8bef1 812 10, 1, 11, 5, 6, 0, 7, 9
b9752825 813};
d42cf844 814static const yytype_int8 yycheck[] =
b9752825 815{
e7b8bef1 816 7, 3, 9, 4, 0, -1, 6, 5
b9752825 817};
d42cf844 818static const yytype_uint8 yystos[] =
5504898e
AD
819{
820 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
821 8, 8
822};
b9752825
AD
823]])
824
825AT_CLEANUP
22e304a6
AD
826
827
828## ------------------------- ##
829## yycheck Bound Violation. ##
830## ------------------------- ##
831
832
833# _AT_DATA_DANCER_Y(BISON-OPTIONS)
834# --------------------------------
835# The following grammar, taken from Andrew Suffield's GPL'd implementation
836# of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
837# yycheck's bounds where issuing a verbose error message. Keep this test
838# so that possible bound checking compilers could check all the skeletons.
839m4_define([_AT_DATA_DANCER_Y],
840[AT_DATA_GRAMMAR([dancer.y],
087dcd78
AD
841[[%code provides
842{
843 ]AT_YYERROR_DECLARE[
844 ]AT_YYLEX_DECLARE[
845}
22e304a6
AD
846$1
847%token ARROW INVALID NUMBER STRING DATA
848%defines
849%verbose
850%error-verbose
851/* Grammar follows */
852%%
853line: header body
854 ;
855
856header: '<' from ARROW to '>' type ':'
857 | '<' ARROW to '>' type ':'
858 | ARROW to type ':'
859 | type ':'
860 | '<' '>'
861 ;
862
863from: DATA
864 | STRING
865 | INVALID
866 ;
867
868to: DATA
869 | STRING
870 | INVALID
871 ;
872
873type: DATA
874 | STRING
875 | INVALID
876 ;
877
878body: /* empty */
879 | body member
880 ;
881
882member: STRING
883 | DATA
884 | '+' NUMBER
885 | '-' NUMBER
886 | NUMBER
887 | INVALID
888 ;
889%%
087dcd78
AD
890]AT_YYERROR_DEFINE[
891]AT_YYLEX_DEFINE([":"])[
290a8ff2
AD
892]AT_LALR1_CC_IF(
893[int
99880de5 894yyparse ()
22e304a6 895{
99880de5 896 yy::parser parser;
fa7b79c0
PE
897#if YYDEBUG
898 parser.set_debug_level (YYDEBUG);
899#endif
22e304a6
AD
900 return parser.parse ();
901}
087dcd78 902])[
22e304a6
AD
903
904int
905main (void)
906{
907 return yyparse ();
908}
087dcd78 909]])
22e304a6
AD
910])# _AT_DATA_DANCER_Y
911
912
913# AT_CHECK_DANCER(BISON-OPTIONS)
914# ------------------------------
915# Generate the grammar, compile it, run it.
916m4_define([AT_CHECK_DANCER],
917[AT_SETUP([Dancer $1])
918AT_BISON_OPTION_PUSHDEFS([$1])
919_AT_DATA_DANCER_Y([$1])
da730230 920AT_BISON_CHECK([-o dancer.c dancer.y])
11c4e57d 921AT_FULL_COMPILE([dancer])
22e304a6 922AT_PARSER_CHECK([./dancer], 1, [],
d5286af1 923[syntax error, unexpected ':'
22e304a6
AD
924])
925AT_BISON_OPTION_POPDEFS
926AT_CLEANUP
927])
928
929AT_CHECK_DANCER()
930AT_CHECK_DANCER([%glr-parser])
931AT_CHECK_DANCER([%skeleton "lalr1.cc"])
d6645148
PE
932
933
934## ------------------------------------------ ##
935## Diagnostic that expects two alternatives. ##
936## ------------------------------------------ ##
937
938
939# _AT_DATA_EXPECT2_Y(BISON-OPTIONS)
940# --------------------------------
941m4_define([_AT_DATA_EXPECT2_Y],
942[AT_DATA_GRAMMAR([expect2.y],
71c7e24f
AD
943[[%{
944static int yylex (]AT_LALR1_CC_IF([int *], [void]));
d6645148 945AT_LALR1_CC_IF([],
71c7e24f 946[[#include <stdio.h>
c4bd5bf7 947#include <stdlib.h>
71c7e24f 948]AT_YYERROR_DECLARE])[
d6645148
PE
949%}
950$1
951%defines
952%error-verbose
953%token A 1000
954%token B
955
956%%
957program: /* empty */
958 | program e ';'
959 | program error ';';
960
961e: e '+' t | t;
962t: A | B;
963
964%%
71c7e24f
AD
965]AT_YYERROR_DEFINE[
966]AT_LALR1_CC_IF(
967[int
d6645148
PE
968yyparse ()
969{
970 yy::parser parser;
971 return parser.parse ();
972}
71c7e24f 973])[
d6645148 974
77519a7d 975#include <assert.h>
d6645148 976static int
71c7e24f
AD
977yylex (]AT_LALR1_CC_IF([int *lval], [void])[)
978{
cf806753 979 static int const tokens[] =
d6645148
PE
980 {
981 1000, '+', '+', -1
982 };
cf806753 983 static size_t toknum;
d6645148 984 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
77519a7d 985 assert (toknum < sizeof tokens / sizeof *tokens);
d6645148 986 return tokens[toknum++];
71c7e24f 987}
d6645148
PE
988
989int
990main (void)
991{
992 return yyparse ();
993}
71c7e24f 994]])
d6645148
PE
995])# _AT_DATA_EXPECT2_Y
996
997
998# AT_CHECK_EXPECT2(BISON-OPTIONS)
71c7e24f 999# -------------------------------
d6645148
PE
1000# Generate the grammar, compile it, run it.
1001m4_define([AT_CHECK_EXPECT2],
1002[AT_SETUP([Expecting two tokens $1])
1003AT_BISON_OPTION_PUSHDEFS([$1])
1004_AT_DATA_EXPECT2_Y([$1])
da730230 1005AT_BISON_CHECK([-o expect2.c expect2.y])
11c4e57d 1006AT_FULL_COMPILE([expect2])
d6645148
PE
1007AT_PARSER_CHECK([./expect2], 1, [],
1008[syntax error, unexpected '+', expecting A or B
1009])
1010AT_BISON_OPTION_POPDEFS
1011AT_CLEANUP
1012])
1013
1014AT_CHECK_EXPECT2()
1015AT_CHECK_EXPECT2([%glr-parser])
1016AT_CHECK_EXPECT2([%skeleton "lalr1.cc"])
4210cd0b
JD
1017
1018
1019
1020## --------------------------------------------- ##
1021## Braced code in declaration in rules section. ##
1022## --------------------------------------------- ##
1023
1024AT_SETUP([Braced code in declaration in rules section])
1025
1026# Bison once mistook braced code in a declaration in the rules section to be a
1027# rule action.
55f48c48 1028AT_BISON_OPTION_PUSHDEFS
4210cd0b
JD
1029AT_DATA_GRAMMAR([input.y],
1030[[%{
1031#include <stdio.h>
55f48c48
AD
1032]AT_YYERROR_DECLARE[
1033]AT_YYLEX_DECLARE[
4210cd0b
JD
1034%}
1035
1036%error-verbose
1037
1038%%
1039
1040start:
1041 {
1042 printf ("Bison would once convert this action to a midrule because of the"
1043 " subsequent braced code.\n");
1044 }
1045 ;
1046
1047%destructor { fprintf (stderr, "DESTRUCTOR\n"); } 'a';
1048%printer { fprintf (yyoutput, "PRINTER"); } 'a';
1049
1050%%
55f48c48 1051]AT_YYERROR_DEFINE[
087dcd78 1052]AT_YYLEX_DEFINE(["a"])[
4210cd0b
JD
1053
1054int
1055main (void)
1056{
1057 yydebug = 1;
1058 return !yyparse ();
1059}
1060]])
55f48c48 1061AT_BISON_OPTION_POPDEFS
4210cd0b 1062
da730230 1063AT_BISON_CHECK([-t -o input.c input.y])
4210cd0b
JD
1064AT_COMPILE([input])
1065AT_PARSER_CHECK([./input], 0,
1066[[Bison would once convert this action to a midrule because of the subsequent braced code.
1067]],
1068[[Starting parse
1069Entering state 0
231ed89a 1070Reducing stack by rule 1 (line 20):
4210cd0b
JD
1071-> $$ = nterm start ()
1072Stack now 0
1073Entering state 1
1074Reading a token: Next token is token 'a' (PRINTER)
1075syntax error, unexpected 'a', expecting $end
1076Error: popping nterm start ()
1077Stack now 0
1078Cleanup: discarding lookahead token 'a' (PRINTER)
1079DESTRUCTOR
1080Stack now 0
1081]])
1082
1083AT_CLEANUP
965537bc
JD
1084
1085
1086
1087## --------------------------------- ##
1088## String alias declared after use. ##
1089## --------------------------------- ##
1090
1091AT_SETUP([String alias declared after use])
1092
1093# Bison once incorrectly asserted that the symbol number for either a token or
1094# its alias was the highest symbol number so far at the point of the alias
1095# declaration. That was true unless the declaration appeared after their first
6d0ef4ec 1096# uses and other tokens appeared in between.
965537bc
JD
1097
1098AT_DATA([input.y],
1099[[%%
1100start: 'a' "A" 'b';
1101%token 'a' "A";
1102]])
1103
da730230 1104AT_BISON_CHECK([-t -o input.c input.y])
965537bc
JD
1105
1106AT_CLEANUP
a0de5091
JD
1107
1108
1109
1110## -------------------------------- ##
1111## Extra lookahead sets in report. ##
1112## -------------------------------- ##
1113
1114AT_SETUP([[Extra lookahead sets in report]])
1115
88c78747
JD
1116# Bison prints each reduction's lookahead set only next to the associated
1117# state's one item that (1) is associated with the same rule as the reduction
1118# and (2) has its dot at the end of its RHS. Previously, Bison also
1119# erroneously printed the lookahead set next to all of the state's other items
9874f80b 1120# associated with the same rule. This bug affected only the '.output' file and
88c78747 1121# not the generated parser source code.
a0de5091
JD
1122
1123AT_DATA([[input.y]],
1124[[%%
1125start: a | 'a' a 'a' ;
1126a: 'a' ;
1127]])
1128
da730230 1129AT_BISON_CHECK([[--report=all input.y]])
a0de5091
JD
1130AT_CHECK([[sed -n '/^state 1$/,/^state 2$/p' input.output]], [[0]],
1131[[state 1
1132
1133 2 start: 'a' . a 'a'
1134 3 a: . 'a'
1135 3 | 'a' . [$end]
1136
1137 'a' shift, and go to state 4
1138
1139 $default reduce using rule 3 (a)
1140
1141 a go to state 5
1142
1143
1144state 2
1145]])
1146
1147AT_CLEANUP
ab7f29f8
JD
1148
1149
1150
1151## ---------------------------------------- ##
1152## Token number in precedence declaration. ##
1153## ---------------------------------------- ##
1154
14da0cdd 1155AT_SETUP([[Token number in precedence declaration]])
ab7f29f8
JD
1156
1157# POSIX says token numbers can be declared in %left, %right, and %nonassoc, but
1158# we lost this in Bison 1.50.
55f48c48 1159AT_BISON_OPTION_PUSHDEFS
ab7f29f8
JD
1160AT_DATA_GRAMMAR([input.y],
1161[[%{
1162 #include <stdio.h>
55f48c48
AD
1163 ]AT_YYERROR_DECLARE[
1164 ]AT_YYLEX_DECLARE[
ab7f29f8
JD
1165%}
1166
1167%error-verbose
9d6af153 1168%right END 0
ab7f29f8
JD
1169%left TK1 1 TK2 2 "tok alias" 3
1170
1171%%
1172
9d6af153
JD
1173start:
1174 TK1 sr_conflict "tok alias"
1175 | start %prec END
1176 ;
ab7f29f8
JD
1177sr_conflict:
1178 TK2
1179 | TK2 "tok alias"
1180 ;
1181
1182%%
1183
55f48c48 1184]AT_YYERROR_DEFINE[
087dcd78 1185]AT_YYLEX_DEFINE([{ 1, 2, 3, 0 }])[
ab7f29f8
JD
1186
1187int
1188main (void)
1189{
1190 return yyparse ();
1191}
1192]])
55f48c48 1193AT_BISON_OPTION_POPDEFS
ab7f29f8
JD
1194
1195AT_BISON_CHECK([[-o input.c input.y]], [[0]],,
9d6af153
JD
1196[[input.y:23.5-19: warning: rule useless in parser due to conflicts: start: start
1197input.y:27.5-19: warning: rule useless in parser due to conflicts: sr_conflict: TK2 "tok alias"
ab7f29f8
JD
1198]])
1199AT_COMPILE([[input]])
1200AT_PARSER_CHECK([[./input]])
1201
1202AT_CLEANUP
873ac263
JD
1203
1204
1205
1206## --------------------------- ##
1207## parse-gram.y: LALR = IELR. ##
1208## --------------------------- ##
1209
1210# If parse-gram.y's LALR and IELR parser tables ever begin to differ, we
1211# need to fix parse-gram.y or start using IELR.
1212
1213AT_SETUP([[parse-gram.y: LALR = IELR]])
1214
1215# Avoid differences in synclines by telling bison that the output files
1216# have the same name.
4b7a4c1b
JD
1217[cp $abs_top_srcdir/src/parse-gram.y input.y]
1218AT_BISON_CHECK([[-o input.c -Dlr.type=lalr input.y]])
035810ed
AD
1219[mv input.c lalr.c]
1220AT_CAPTURE_FILE([lalr.c])
4b7a4c1b
JD
1221AT_BISON_CHECK([[-o input.c -Dlr.type=ielr input.y]])
1222[mv input.c ielr.c]
035810ed
AD
1223AT_CAPTURE_FILE([ielr.c])
1224AT_CHECK([[diff lalr.c ielr.c]], [[0]])
873ac263
JD
1225
1226AT_CLEANUP
d88cf117
JD
1227
1228
1229
1230## --------------------------------------- ##
1231## %error-verbose and YYSTACK_USE_ALLOCA. ##
1232## --------------------------------------- ##
1233
1234AT_SETUP([[%error-verbose and YYSTACK_USE_ALLOCA]])
1235
55f48c48 1236AT_BISON_OPTION_PUSHDEFS
d88cf117
JD
1237AT_DATA_GRAMMAR([input.y],
1238[[%code {
1239 #include <stdio.h>
55f48c48
AD
1240 ]AT_YYERROR_DECLARE[
1241 ]AT_YYLEX_DECLARE[
d88cf117
JD
1242 #define YYSTACK_USE_ALLOCA 1
1243}
1244
1245%error-verbose
1246
1247%%
1248
1249start: check syntax_error syntax_error ;
1250
1251check:
1252{
1253 if (128 < sizeof yymsgbuf)
1254 {
1255 fprintf (stderr,
1256 "The initial size of yymsgbuf in yyparse has increased\n"
1257 "since this test group was last updated. As a result,\n"
1258 "this test group may no longer manage to induce a\n"
1259 "reallocation of the syntax error message buffer.\n"
1260 "This test group must be adjusted to produce a longer\n"
1261 "error message.\n");
1262 YYABORT;
1263 }
1264}
1265;
1266
1267// Induce a syntax error message whose total length is more than
1268// sizeof yymsgbuf in yyparse. Each token here is 64 bytes.
1269syntax_error:
1270 "123456789112345678921234567893123456789412345678951234567896123A"
1271| "123456789112345678921234567893123456789412345678951234567896123B"
1272| error 'a' 'b' 'c'
1273;
1274
1275%%
1276
55f48c48
AD
1277]AT_YYERROR_DEFINE[
1278/* Induce two syntax error messages (which requires full error
1279 recovery by shifting 3 tokens) in order to detect any loss of the
1280 reallocated buffer. */
95361618 1281]AT_YYLEX_DEFINE(["abc"])[
d88cf117
JD
1282int
1283main (void)
1284{
1285 return yyparse ();
1286}
1287]])
55f48c48 1288AT_BISON_OPTION_POPDEFS
d88cf117
JD
1289
1290AT_BISON_CHECK([[-o input.c input.y]])
1291AT_COMPILE([[input]])
1292AT_PARSER_CHECK([[./input]], [[1]], [],
1293[[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1294syntax error, unexpected $end, expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B
1295]])
1296
1297AT_CLEANUP
1298
1299
1300
1301## ------------------------- ##
1302## %error-verbose overflow. ##
1303## ------------------------- ##
1304
1305# Imagine the case where YYSTACK_ALLOC_MAXIMUM = YYSIZE_MAXIMUM and an
1306# invocation of yysyntax_error has caused yymsg_alloc to grow to exactly
1307# YYSTACK_ALLOC_MAXIMUM (perhaps because the normal doubling of size had
69a2ab11
JD
1308# to be clipped to YYSTACK_ALLOC_MAXIMUM). In an old version of yacc.c,
1309# a subsequent invocation of yysyntax_error that overflows during its
1310# size calculation would return YYSIZE_MAXIMUM to yyparse. Then,
1311# yyparse would invoke yyerror using the old contents of yymsg.
d88cf117
JD
1312
1313AT_SETUP([[%error-verbose overflow]])
55f48c48 1314AT_BISON_OPTION_PUSHDEFS
d88cf117
JD
1315AT_DATA_GRAMMAR([input.y],
1316[[%code {
1317 #include <stdio.h>
55f48c48
AD
1318 ]AT_YYERROR_DECLARE[
1319 ]AT_YYLEX_DECLARE[
d88cf117
JD
1320
1321 /* This prevents this test case from having to induce error messages
1322 large enough to overflow size_t. */
1323 #define YYSIZE_T unsigned char
1324
ea6046b9 1325 /* Bring in malloc and set EXIT_SUCCESS so yacc.c doesn't try to
23761f42 1326 provide a malloc prototype using our YYSIZE_T. */
d88cf117 1327 #include <stdlib.h>
ea6046b9
PE
1328 #ifndef EXIT_SUCCESS
1329 # define EXIT_SUCCESS 0
23761f42 1330 #endif
d88cf117
JD
1331
1332 /* Max depth is usually much smaller than YYSTACK_ALLOC_MAXIMUM, and
1333 we don't want gcc to warn everywhere this constant would be too big
1334 to make sense for our YYSIZE_T. */
1335 #define YYMAXDEPTH 100
1336}
1337
1338%error-verbose
1339
1340%%
1341
1342start: syntax_error1 check syntax_error2 ;
1343
1344// Induce a syntax error message whose total length causes yymsg in
1345// yyparse to be reallocated to size YYSTACK_ALLOC_MAXIMUM, which
1346// should be 255. Each token here is 64 bytes.
1347syntax_error1:
1348 "123456789112345678921234567893123456789412345678951234567896123A"
1349| "123456789112345678921234567893123456789412345678951234567896123B"
1350| "123456789112345678921234567893123456789412345678951234567896123C"
1351| error 'a' 'b' 'c'
1352;
1353
1354check:
1355{
1356 if (yymsg_alloc != YYSTACK_ALLOC_MAXIMUM
1357 || YYSTACK_ALLOC_MAXIMUM != YYSIZE_MAXIMUM
1358 || YYSIZE_MAXIMUM != 255)
1359 {
1360 fprintf (stderr,
1361 "The assumptions of this test group are no longer\n"
1362 "valid, so it may no longer catch the error it was\n"
1363 "designed to catch. Specifically, the following\n"
1364 "values should all be 255:\n\n");
1365 fprintf (stderr, " yymsg_alloc = %d\n", yymsg_alloc);
1366 fprintf (stderr, " YYSTACK_ALLOC_MAXIMUM = %d\n",
1367 YYSTACK_ALLOC_MAXIMUM);
1368 fprintf (stderr, " YYSIZE_MAXIMUM = %d\n", YYSIZE_MAXIMUM);
1369 YYABORT;
1370 }
1371}
1372;
1373
1374// Now overflow.
1375syntax_error2:
1376 "123456789112345678921234567893123456789412345678951234567896123A"
1377| "123456789112345678921234567893123456789412345678951234567896123B"
1378| "123456789112345678921234567893123456789412345678951234567896123C"
1379| "123456789112345678921234567893123456789412345678951234567896123D"
1380| "123456789112345678921234567893123456789412345678951234567896123E"
1381;
1382
1383%%
1384
55f48c48
AD
1385]AT_YYERROR_DEFINE[
1386/* Induce two syntax error messages (which requires full error
1387 recovery by shifting 3 tokens). */
95361618 1388]AT_YYLEX_DEFINE(["abc"])[
d88cf117
JD
1389int
1390main (void)
1391{
1392 /* Push parsers throw away the message buffer between tokens, so skip
1393 this test under maintainer-push-check. */
1394 if (YYPUSH)
1395 return 77;
1396 return yyparse ();
1397}
1398]])
1399
1400AT_BISON_CHECK([[-o input.c input.y]])
1401
1402# gcc warns about tautologies and fallacies involving comparisons for
1403# unsigned char. However, it doesn't produce these same warnings for
1404# size_t and many other types when the warnings would seem to make just
1405# as much sense. We ignore the warnings.
1406[CFLAGS="$NO_WERROR_CFLAGS"]
1407AT_COMPILE([[input]])
1408
1409AT_PARSER_CHECK([[./input]], [[2]], [],
1410[[syntax error, unexpected 'a', expecting 123456789112345678921234567893123456789412345678951234567896123A or 123456789112345678921234567893123456789412345678951234567896123B or 123456789112345678921234567893123456789412345678951234567896123C
1411syntax error
1412memory exhausted
1413]])
55f48c48 1414AT_BISON_OPTION_POPDEFS
d88cf117 1415AT_CLEANUP
ea13bea8
JD
1416
1417
1418
1419## ------------------------ ##
1420## LAC: Exploratory stack. ##
1421## ------------------------ ##
1422
1423AT_SETUP([[LAC: Exploratory stack]])
1424
1425m4_pushdef([AT_LAC_CHECK], [
1426
1427AT_BISON_OPTION_PUSHDEFS([$1])
1428
1429AT_DATA_GRAMMAR([input.y],
1430[[%code {
1431 #include <stdio.h>
55f48c48 1432 ]AT_YYERROR_DECLARE[
ea13bea8
JD
1433 int yylex (]AT_PURE_IF([[YYSTYPE *]], [[void]])[);
1434}
1435
1436]$1[
1437%error-verbose
1438%token 'c'
1439
1440%%
1441
1442// default reductions in inconsistent states
1443// v v v v v v v v v v v v v v
1444S: 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
1445// ^ ^ ^
1446// LAC reallocs
ea13bea8
JD
1447
1448A: 'a' | /*empty*/ { printf ("inconsistent default reduction\n"); } ;
1449B: 'b' ;
1450C: /*empty*/ { printf ("consistent default reduction\n"); } ;
1451
1452%%
55f48c48 1453]AT_YYERROR_DEFINE[
ea13bea8
JD
1454int
1455yylex (]AT_PURE_IF([[YYSTYPE *v]], [[void]])[)
1456{
1457 static char const *input = "bbbbc";]AT_PURE_IF([[
1458 *v = 0;]])[
1459 return *input++;
1460}
1461
1462int
1463main (void)
1464{
1465 yydebug = 1;
1466 return yyparse ();
1467}
1468]])
1469
723fe7d1
JD
1470AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
1471 -Dparse.lac.memory-trace=full \
ea13bea8
JD
1472 -t -o input.c input.y]], [[0]], [],
1473[[input.y: conflicts: 21 shift/reduce
1474]])
1475AT_COMPILE([[input]])
1476AT_PARSER_CHECK([[./input > stdout.txt 2> stderr.txt]], [[1]])
1477
1478# Make sure syntax error doesn't forget that 'a' is expected. It would
1479# be forgotten without lookahead correction.
1480AT_CHECK([[grep 'syntax error,' stderr.txt]], [[0]],
1481[[syntax error, unexpected 'c', expecting 'a' or 'b'
1482]])
1483
1484# Check number of default reductions in inconsistent states to be sure
1485# syntax error is detected before unnecessary reductions are performed.
1486AT_CHECK([[perl -0777 -ne 'print s/inconsistent default reduction//g;' \
1487 < stdout.txt || exit 77]], [[0]], [[14]])
1488
1489# Check number of default reductions in consistent states to be sure
1490# it is performed before the syntax error is detected.
1491AT_CHECK([[perl -0777 -ne 'print s/\bconsistent default reduction//g;' \
1492 < stdout.txt || exit 77]], [[0]], [[2]])
1493
723fe7d1
JD
1494# Check number of reallocs to be sure reallocated memory isn't somehow
1495# lost between LAC invocations.
1496AT_CHECK([[perl -0777 -ne 'print s/\(realloc//g;' < stderr.txt \
1497 || exit 77]], [[0]], [[3]])
1498
ea13bea8
JD
1499AT_BISON_OPTION_POPDEFS
1500])
1501
1502AT_LAC_CHECK([[%define api.push-pull pull]])
1503AT_LAC_CHECK([[%define api.push-pull pull %define api.pure]])
1504AT_LAC_CHECK([[%define api.push-pull both]])
1505AT_LAC_CHECK([[%define api.push-pull both %define api.pure]])
1506
1507m4_popdef([AT_LAC_CHECK])
1508
1509AT_CLEANUP
1510
1511
1512
1513## ------------------------ ##
1514## LAC: Memory exhaustion. ##
1515## ------------------------ ##
1516
1517AT_SETUP([[LAC: Memory exhaustion]])
1518
55f48c48
AD
1519m4_pushdef([AT_LAC_CHECK],
1520[AT_BISON_OPTION_PUSHDEFS
ea13bea8
JD
1521AT_DATA_GRAMMAR([input.y],
1522[[%code {
1523 #include <stdio.h>
55f48c48
AD
1524 ]AT_YYERROR_DECLARE[
1525 ]AT_YYLEX_DECLARE[
723fe7d1 1526 #define YYMAXDEPTH 8
ea13bea8
JD
1527}
1528
1529%error-verbose
1530
1531%%
1532
1533S: A A A A A A A A A ;
1534A: /*empty*/ | 'a' ;
1535
1536%%
55f48c48 1537]AT_YYERROR_DEFINE[
95361618 1538]AT_YYLEX_DEFINE(["$1"])[
ea13bea8
JD
1539int
1540main (void)
1541{
1542 yydebug = 1;
1543 return yyparse ();
1544}
1545]])
1546
723fe7d1 1547AT_BISON_CHECK([[-Dparse.lac=full -Dparse.lac.es-capacity-initial=1 \
ea13bea8
JD
1548 -t -o input.c input.y]], [[0]], [],
1549[[input.y: conflicts: 8 shift/reduce
1550]])
1551AT_COMPILE([[input]])
55f48c48 1552AT_BISON_OPTION_POPDEFS
ea13bea8
JD
1553])
1554
1555# Check for memory exhaustion during parsing.
55f48c48
AD
1556AT_LAC_CHECK([])
1557AT_PARSER_CHECK([[./input]], [[2]], [],
ea13bea8
JD
1558[[Starting parse
1559Entering state 0
1560Reading a token: Now at end of input.
1561LAC: initial context established for $end
723fe7d1 1562LAC: 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
1563memory exhausted
1564Cleanup: discarding lookahead token $end ()
1565Stack now 0
1566]])
1567
1568# Induce an immediate syntax error with an undefined token, and check
1569# for memory exhaustion while building syntax error message.
55f48c48
AD
1570AT_LAC_CHECK([z], [[0]])
1571AT_PARSER_CHECK([[./input]], [[2]], [],
ea13bea8
JD
1572[[Starting parse
1573Entering state 0
1574Reading a token: Next token is token $undefined ()
1575LAC: initial context established for $undefined
1576LAC: checking lookahead $undefined: Always Err
1577Constructing syntax error message
723fe7d1 1578LAC: 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
1579syntax error
1580memory exhausted
1581Cleanup: discarding lookahead token $undefined ()
1582Stack now 0
1583]])
1584
1585m4_popdef([AT_LAC_CHECK])
1586
1587AT_CLEANUP