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