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