]> git.saurik.com Git - bison.git/blame - tests/regression.at
During deterministic GLR operation, user actions should be able to
[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
69078d4b
AD
24## ------------------------- ##
25## Early token definitions. ##
26## ------------------------- ##
27
28
29AT_SETUP([Early token definitions])
30
31# Found in GCJ: they expect the tokens to be defined before the user
32# prologue, so that they can use the token definitions in it.
33
9501dc6e 34AT_DATA_GRAMMAR([input.y],
69078d4b
AD
35[[%{
36void yyerror (const char *s);
37int yylex (void);
38%}
39
40%union
41{
42 int val;
43};
44%{
45#ifndef MY_TOKEN
46# error "MY_TOKEN not defined."
47#endif
48%}
49%token MY_TOKEN
50%%
51exp: MY_TOKEN;
52%%
53]])
54
b56471a6 55AT_CHECK([bison -o input.c input.y])
002b9b7d 56AT_COMPILE([input.o], [-c input.c])
69078d4b
AD
57
58AT_CLEANUP
59
60
61
2b25d624
AD
62## ---------------- ##
63## Braces parsing. ##
64## ---------------- ##
65
66
69078d4b 67AT_SETUP([Braces parsing])
2b25d624
AD
68
69AT_DATA([input.y],
70[[/* Bison used to swallow the character after `}'. */
71
72%%
bfcf1f3a 73exp: { tests = {{{{{{{{{{}}}}}}}}}}; };
2b25d624
AD
74%%
75]])
76
b56471a6 77AT_CHECK([bison -v -o input.c input.y])
2b25d624 78
a4bf0390 79AT_CHECK([grep 'tests = {{{{{{{{{{}}}}}}}}}};' input.c], 0, [ignore])
2b25d624
AD
80
81AT_CLEANUP
82
83
c95f2d78
AD
84## ------------------ ##
85## Duplicate string. ##
86## ------------------ ##
87
88
89AT_SETUP([Duplicate string])
90
f499b062 91AT_DATA([input.y],
c95f2d78
AD
92[[/* `Bison -v' used to dump core when two tokens are defined with the same
93 string, as LE and GE below. */
94
95%token NUM
96%token LE "<="
97%token GE "<="
98
99%%
100exp: '(' exp ')' | NUM ;
101%%
102]])
103
b56471a6 104AT_CHECK([bison -v -o input.c input.y], 0, [],
a5d50994 105[[input.y:6.8-14: warning: symbol `"<="' used more than once as a literal string
69078d4b 106]])
c95f2d78 107
d803322e 108AT_CLEANUP
c95f2d78
AD
109
110
2ca209c1
AD
111## ------------------- ##
112## Rule Line Numbers. ##
113## ------------------- ##
114
115AT_SETUP([Rule Line Numbers])
116
6b98e4b5
AD
117AT_KEYWORDS([report])
118
2ca209c1
AD
119AT_DATA([input.y],
120[[%%
121expr:
122'a'
123
124{
125
126}
127
128'b'
129
130{
131
132}
133
134|
135
136
137{
138
139
140}
141
142'c'
143
144{
145
bfcf1f3a 146};
2ca209c1
AD
147]])
148
b56471a6 149AT_CHECK([bison -o input.c -v input.y])
2ca209c1
AD
150
151# Check the contents of the report.
152AT_CHECK([cat input.output], [],
d2d1b42b 153[[Grammar
2ca209c1 154
88bce5a2 155 0 $accept: expr $end
6b98e4b5
AD
156
157 1 @1: /* empty */
158
159 2 expr: 'a' @1 'b'
160
161 3 @2: /* empty */
162
163 4 expr: @2 'c'
2ca209c1 164
d2d1b42b 165
2ca209c1
AD
166Terminals, with rules where they appear
167
88bce5a2 168$end (0) 0
2ca209c1
AD
169'a' (97) 2
170'b' (98) 2
171'c' (99) 4
172error (256)
173
d2d1b42b 174
2ca209c1
AD
175Nonterminals, with rules where they appear
176
88bce5a2 177$accept (6)
b365aa05
AD
178 on left: 0
179expr (7)
180 on left: 2 4, on right: 0
181@1 (8)
2ca209c1 182 on left: 1, on right: 2
b365aa05 183@2 (9)
2ca209c1
AD
184 on left: 3, on right: 4
185
186
187state 0
188
88bce5a2 189 0 $accept: . expr $end
643a5994 190
87675353 191 'a' shift, and go to state 1
2ca209c1 192
87675353 193 $default reduce using rule 3 (@2)
2ca209c1 194
87675353
AD
195 expr go to state 2
196 @2 go to state 3
2ca209c1
AD
197
198
199state 1
200
ce4ccb4b 201 2 expr: 'a' . @1 'b'
2ca209c1 202
87675353 203 $default reduce using rule 1 (@1)
2ca209c1 204
87675353 205 @1 go to state 4
2ca209c1
AD
206
207
208state 2
209
88bce5a2 210 0 $accept: expr . $end
2ca209c1 211
88bce5a2 212 $end shift, and go to state 5
2ca209c1
AD
213
214
215state 3
216
ce4ccb4b 217 4 expr: @2 . 'c'
2ca209c1 218
87675353 219 'c' shift, and go to state 6
2ca209c1
AD
220
221
222state 4
223
ce4ccb4b 224 2 expr: 'a' @1 . 'b'
2ca209c1 225
87675353 226 'b' shift, and go to state 7
2ca209c1
AD
227
228
229state 5
230
88bce5a2 231 0 $accept: expr $end .
2ca209c1 232
e8832397 233 $default accept
2ca209c1
AD
234
235
236state 6
237
ce4ccb4b 238 4 expr: @2 'c' .
b365aa05 239
87675353 240 $default reduce using rule 4 (expr)
2ca209c1
AD
241
242
243state 7
244
ce4ccb4b 245 2 expr: 'a' @1 'b' .
b365aa05 246
87675353 247 $default reduce using rule 2 (expr)
2ca209c1
AD
248]])
249
250AT_CLEANUP
251
252
253
cd5aafcf
AD
254## ---------------------- ##
255## Mixing %token styles. ##
256## ---------------------- ##
257
258
259AT_SETUP([Mixing %token styles])
260
261# Taken from the documentation.
262AT_DATA([input.y],
263[[%token <operator> OR "||"
264%token <operator> LE 134 "<="
265%left OR "<="
266%%
267exp: ;
268%%
269]])
270
b56471a6 271AT_CHECK([bison -v -o input.c input.y])
cd5aafcf 272
d803322e 273AT_CLEANUP
cd5aafcf
AD
274
275
276
29ae55f1
AD
277## ---------------- ##
278## Invalid inputs. ##
279## ---------------- ##
561f9a30
AD
280
281
29ae55f1 282AT_SETUP([Invalid inputs])
561f9a30
AD
283
284AT_DATA([input.y],
285[[%%
286?
561f9a30 287default: 'a' }
29ae55f1 288%&
2dfbfc12 289%a-does-not-exist
29ae55f1 290%-
e9955c83 291%{
561f9a30
AD
292]])
293
294AT_CHECK([bison input.y], [1], [],
e9955c83
AD
295[[input.y:2.1: invalid character: `?'
296input.y:3.14: invalid character: `}'
297input.y:4.1: invalid character: `%'
298input.y:4.2: invalid character: `&'
2dfbfc12 299input.y:5.1-17: invalid directive: `%a-does-not-exist'
e9955c83
AD
300input.y:6.1: invalid character: `%'
301input.y:6.2: invalid character: `-'
2115939b 302input.y:7.1-8.0: missing `%}' at end of file
e0c40012 303]])
561f9a30
AD
304
305AT_CLEANUP
306
307
fc01665e
PE
308AT_SETUP([Invalid inputs with {}])
309
310AT_DATA([input.y],
311[[
312%destructor
313%initial-action
314%lex-param
315%parse-param
316%printer
317%union
318]])
319
320AT_CHECK([bison input.y], [1], [],
321[[input.y:3.1: missing `{' in "%destructor {...}"
322input.y:4.1: missing `{' in "%initial-action {...}"
323input.y:4.1: syntax error, unexpected %initial-action {...}, expecting string or identifier
324]])
325
326AT_CLEANUP
327
328
270a173c 329
b87f8b21
AD
330## ------------------- ##
331## Token definitions. ##
332## ------------------- ##
333
334
335AT_SETUP([Token definitions])
336
337# Bison managed, when fed with `%token 'f' "f"' to #define 'f'!
9501dc6e 338AT_DATA_GRAMMAR([input.y],
db7c8e9a 339[%{
ca407bdf 340#include <stdio.h>
db7c8e9a
AD
341void yyerror (const char *s);
342int yylex (void);
343%}
ca407bdf
PE
344[%error-verbose
345%token MYEOF 0 "end of file"
b87f8b21 346%token 'a' "a"
4f136612
PE
347%token B_TOKEN "b"
348%token C_TOKEN 'c'
349%token 'd' D_TOKEN
3d54b576 350%token SPECIAL "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!"
b87f8b21 351%%
3d54b576 352exp: "a" "\\\'\?\"\a\b\f\n\r\t\v\001\201\x001\x000081??!";
ca407bdf
PE
353%%
354void
355yyerror (char const *s)
356{
357 fprintf (stderr, "%s\n", s);
358}
359
360int
361yylex (void)
362{
363 return SPECIAL;
364}
365
366int
367main (void)
368{
369 return yyparse ();
370}
b87f8b21
AD
371]])
372
b56471a6 373AT_CHECK([bison -o input.c input.y])
ca407bdf 374AT_COMPILE([input])
3d54b576
PE
375AT_DATA([experr],
376[[syntax error, unexpected "\\'?\"\a\b\f\n\r\t\v\001\201\001\201?\?!", expecting a
377]])
378AT_PARSER_CHECK([./input], 1, [], [experr])
b87f8b21
AD
379AT_CLEANUP
380
381
382
eb714592
AD
383## -------------------- ##
384## Characters Escapes. ##
385## -------------------- ##
386
387
388AT_SETUP([Characters Escapes])
389
9501dc6e 390AT_DATA_GRAMMAR([input.y],
eb714592
AD
391[%{
392void yyerror (const char *s);
393int yylex (void);
394%}
395[%%
396exp:
397 '\'' "\'"
398| '\"' "\""
399| '"' "'"
400;
401]])
9501dc6e 402# Pacify font-lock-mode: "
eb714592 403
b56471a6 404AT_CHECK([bison -o input.c input.y])
eb714592
AD
405AT_COMPILE([input.o], [-c input.c])
406AT_CLEANUP
407
408
409
b9752825
AD
410## -------------- ##
411## Web2c Report. ##
412## -------------- ##
776209d6
AD
413
414# The generation of the reduction was once wrong in Bison, and made it
415# miss some reductions. In the following test case, the reduction on
416# `undef_id_tok' in state 1 was missing. This is stripped down from
417# the actual web2c.y.
418
b9752825 419AT_SETUP([Web2c Report])
776209d6 420
6b98e4b5
AD
421AT_KEYWORDS([report])
422
776209d6
AD
423AT_DATA([input.y],
424[[%token undef_id_tok const_id_tok
425
426%start CONST_DEC_PART
427\f
428%%
429CONST_DEC_PART:
430 CONST_DEC_LIST
431 ;
432
433CONST_DEC_LIST:
434 CONST_DEC
435 | CONST_DEC_LIST CONST_DEC
436 ;
437
438CONST_DEC:
439 { } undef_id_tok '=' const_id_tok ';'
440 ;
441%%
776209d6
AD
442]])
443
444AT_CHECK([bison -v input.y])
87675353 445AT_CHECK([cat input.output], 0,
776209d6 446[[Grammar
87675353 447
88bce5a2 448 0 $accept: CONST_DEC_PART $end
87675353 449
6b98e4b5 450 1 CONST_DEC_PART: CONST_DEC_LIST
87675353 451
6b98e4b5
AD
452 2 CONST_DEC_LIST: CONST_DEC
453 3 | CONST_DEC_LIST CONST_DEC
87675353 454
6b98e4b5 455 4 @1: /* empty */
87675353 456
6b98e4b5 457 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';'
87675353
AD
458
459
776209d6 460Terminals, with rules where they appear
87675353 461
88bce5a2 462$end (0) 0
776209d6
AD
463';' (59) 5
464'=' (61) 5
465error (256)
007a50a4
AD
466undef_id_tok (258) 5
467const_id_tok (259) 5
87675353
AD
468
469
776209d6 470Nonterminals, with rules where they appear
87675353 471
88bce5a2 472$accept (7)
78d5bae9
AD
473 on left: 0
474CONST_DEC_PART (8)
475 on left: 1, on right: 0
476CONST_DEC_LIST (9)
776209d6 477 on left: 2 3, on right: 1 3
78d5bae9 478CONST_DEC (10)
776209d6 479 on left: 5, on right: 2 3
78d5bae9 480@1 (11)
776209d6 481 on left: 4, on right: 5
87675353
AD
482
483
776209d6 484state 0
87675353 485
88bce5a2 486 0 $accept: . CONST_DEC_PART $end
87675353
AD
487
488 $default reduce using rule 4 (@1)
489
490 CONST_DEC_PART go to state 1
491 CONST_DEC_LIST go to state 2
492 CONST_DEC go to state 3
493 @1 go to state 4
494
495
776209d6 496state 1
87675353 497
88bce5a2 498 0 $accept: CONST_DEC_PART . $end
87675353 499
88bce5a2 500 $end shift, and go to state 5
87675353
AD
501
502
78d5bae9 503state 2
87675353 504
ce4ccb4b
AD
505 1 CONST_DEC_PART: CONST_DEC_LIST .
506 3 CONST_DEC_LIST: CONST_DEC_LIST . CONST_DEC
87675353
AD
507
508 undef_id_tok reduce using rule 4 (@1)
509 $default reduce using rule 1 (CONST_DEC_PART)
510
511 CONST_DEC go to state 6
512 @1 go to state 4
513
514
78d5bae9 515state 3
87675353 516
ce4ccb4b 517 2 CONST_DEC_LIST: CONST_DEC .
87675353
AD
518
519 $default reduce using rule 2 (CONST_DEC_LIST)
520
521
776209d6 522state 4
87675353 523
ce4ccb4b 524 5 CONST_DEC: @1 . undef_id_tok '=' const_id_tok ';'
87675353
AD
525
526 undef_id_tok shift, and go to state 7
527
528
78d5bae9 529state 5
87675353 530
88bce5a2 531 0 $accept: CONST_DEC_PART $end .
87675353 532
e8832397 533 $default accept
87675353
AD
534
535
78d5bae9 536state 6
87675353 537
ce4ccb4b 538 3 CONST_DEC_LIST: CONST_DEC_LIST CONST_DEC .
87675353
AD
539
540 $default reduce using rule 3 (CONST_DEC_LIST)
541
542
78d5bae9 543state 7
87675353 544
ce4ccb4b 545 5 CONST_DEC: @1 undef_id_tok . '=' const_id_tok ';'
87675353
AD
546
547 '=' shift, and go to state 8
548
549
78d5bae9 550state 8
87675353 551
ce4ccb4b 552 5 CONST_DEC: @1 undef_id_tok '=' . const_id_tok ';'
87675353
AD
553
554 const_id_tok shift, and go to state 9
555
556
78d5bae9 557state 9
87675353 558
ce4ccb4b 559 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok . ';'
87675353
AD
560
561 ';' shift, and go to state 10
562
563
78d5bae9 564state 10
87675353 565
ce4ccb4b 566 5 CONST_DEC: @1 undef_id_tok '=' const_id_tok ';' .
87675353
AD
567
568 $default reduce using rule 5 (CONST_DEC)
776209d6
AD
569]])
570
571AT_CLEANUP
b9752825
AD
572
573
574## --------------- ##
575## Web2c Actions. ##
576## --------------- ##
577
578# The generation of the mapping `state -> action' was once wrong in
579# extremely specific situations. web2c.y exhibits this situation.
580# Below is a stripped version of the grammar. It looks like one can
581# simplify it further, but just don't: it is tuned to exhibit a bug,
582# which disapears when applying sane grammar transformations.
583#
584# It used to be wrong on yydefact only:
585#
d42cf844 586# static const yytype_uint8 yydefact[] =
b9752825
AD
587# {
588# - 2, 0, 1, 0, 0, 2, 3, 2, 5, 4,
589# + 2, 0, 1, 0, 0, 0, 3, 2, 5, 4,
590# 0, 0
591# };
592#
593# but let's check all the tables.
594
595
596AT_SETUP([Web2c Actions])
597
6b98e4b5
AD
598AT_KEYWORDS([report])
599
b9752825
AD
600AT_DATA([input.y],
601[[%%
602statement: struct_stat;
603struct_stat: /* empty. */ | if else;
604if: "if" "const" "then" statement;
605else: "else" statement;
606%%
607]])
608
b56471a6 609AT_CHECK([bison -v -o input.c input.y])
b9752825
AD
610
611# Check only the tables. We don't use --no-parser, because it is
612# still to be implemented in the experimental branch of Bison.
ce4ccb4b
AD
613[sed -n 's/ *$//;/^static const.*\[\] =/,/^}/p' input.c >tables.c]
614
615AT_CHECK([[cat tables.c]], 0,
d42cf844 616[[static const yytype_uint8 yytranslate[] =
b9752825
AD
617{
618 0, 2, 2, 2, 2, 2, 2, 2, 2, 2,
619 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
620 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
621 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
622 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
623 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
624 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
625 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
626 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
627 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
628 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
629 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
630 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
631 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
632 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
633 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
634 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
635 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
636 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
637 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
638 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
639 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
640 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
641 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
642 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
007a50a4
AD
643 2, 2, 2, 2, 2, 2, 1, 2, 3, 4,
644 5, 6
b9752825 645};
d42cf844 646static const yytype_uint8 yyprhs[] =
b9752825 647{
e7b8bef1 648 0, 0, 3, 5, 6, 9, 14
b9752825 649};
d42cf844 650static const yytype_int8 yyrhs[] =
b9752825 651{
e7b8bef1
AD
652 8, 0, -1, 9, -1, -1, 10, 11, -1, 3,
653 4, 5, 8, -1, 6, 8, -1
b9752825 654};
d42cf844 655static const yytype_uint8 yyrline[] =
b9752825 656{
e7b8bef1 657 0, 2, 2, 3, 3, 4, 5
b9752825
AD
658};
659static const char *const yytname[] =
660{
9e0876fb
PE
661 "$end", "error", "$undefined", "\"if\"", "\"const\"", "\"then\"",
662 "\"else\"", "$accept", "statement", "struct_stat", "if", "else", 0
b9752825 663};
d42cf844 664static const yytype_uint16 yytoknum[] =
b9752825 665{
3650b4b8 666 0, 256, 257, 258, 259, 260, 261
b9752825 667};
d42cf844 668static const yytype_uint8 yyr1[] =
b9752825 669{
e7b8bef1 670 0, 7, 8, 9, 9, 10, 11
b9752825 671};
d42cf844 672static const yytype_uint8 yyr2[] =
b9752825 673{
e7b8bef1 674 0, 2, 1, 0, 2, 4, 2
b9752825 675};
d42cf844 676static const yytype_uint8 yydefact[] =
b9752825 677{
e8832397 678 3, 0, 0, 2, 0, 0, 1, 3, 4, 3,
e7b8bef1 679 6, 5
b9752825 680};
d42cf844 681static const yytype_int8 yydefgoto[] =
b9752825 682{
e7b8bef1 683 -1, 2, 3, 4, 8
b9752825 684};
d42cf844 685static const yytype_int8 yypact[] =
b9752825 686{
12b0043a
AD
687 -2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
688 -8, -8
b9752825 689};
d42cf844 690static const yytype_int8 yypgoto[] =
b9752825 691{
12b0043a 692 -8, -7, -8, -8, -8
b9752825 693};
d42cf844 694static const yytype_uint8 yytable[] =
b9752825 695{
e7b8bef1 696 10, 1, 11, 5, 6, 0, 7, 9
b9752825 697};
d42cf844 698static const yytype_int8 yycheck[] =
b9752825 699{
e7b8bef1 700 7, 3, 9, 4, 0, -1, 6, 5
b9752825 701};
d42cf844 702static const yytype_uint8 yystos[] =
5504898e
AD
703{
704 0, 3, 8, 9, 10, 4, 0, 6, 11, 5,
705 8, 8
706};
b9752825
AD
707]])
708
709AT_CLEANUP
22e304a6
AD
710
711
712## ------------------------- ##
713## yycheck Bound Violation. ##
714## ------------------------- ##
715
716
717# _AT_DATA_DANCER_Y(BISON-OPTIONS)
718# --------------------------------
719# The following grammar, taken from Andrew Suffield's GPL'd implementation
720# of DGMTP, the Dancer Generic Message Transport Protocol, used to violate
721# yycheck's bounds where issuing a verbose error message. Keep this test
722# so that possible bound checking compilers could check all the skeletons.
723m4_define([_AT_DATA_DANCER_Y],
724[AT_DATA_GRAMMAR([dancer.y],
725[%{
848dc439
PE
726static int yylex (AT_LALR1_CC_IF([int *], [void]));
727AT_LALR1_CC_IF([],
22e304a6 728[#include <stdio.h>
848dc439 729static void yyerror (const char *);])
22e304a6
AD
730%}
731$1
732%token ARROW INVALID NUMBER STRING DATA
733%defines
734%verbose
735%error-verbose
736/* Grammar follows */
737%%
738line: header body
739 ;
740
741header: '<' from ARROW to '>' type ':'
742 | '<' ARROW to '>' type ':'
743 | ARROW to type ':'
744 | type ':'
745 | '<' '>'
746 ;
747
748from: DATA
749 | STRING
750 | INVALID
751 ;
752
753to: DATA
754 | STRING
755 | INVALID
756 ;
757
758type: DATA
759 | STRING
760 | INVALID
761 ;
762
763body: /* empty */
764 | body member
765 ;
766
767member: STRING
768 | DATA
769 | '+' NUMBER
770 | '-' NUMBER
771 | NUMBER
772 | INVALID
773 ;
774%%
775AT_LALR1_CC_IF(
68e11668 776[/* A C++ error reporting function. */
22e304a6 777void
99880de5 778yy::parser::error (const location&, const std::string& m)
22e304a6 779{
efeed023 780 std::cerr << m << std::endl;
22e304a6
AD
781}
782
783int
99880de5 784yyparse ()
22e304a6 785{
99880de5 786 yy::parser parser;
a3cb6248 787 parser.set_debug_level (!!YYDEBUG);
22e304a6
AD
788 return parser.parse ();
789}
790],
791[static void
792yyerror (const char *s)
793{
794 fprintf (stderr, "%s\n", s);
795}])
796
797static int
848dc439 798yylex (AT_LALR1_CC_IF([int *lval], [void]))
22e304a6
AD
799[{
800 static int toknum = 0;
801 int tokens[] =
802 {
803 ':', -1
804 };
848dc439 805 ]AT_LALR1_CC_IF([*lval = 0; /* Pacify GCC. */])[
22e304a6
AD
806 return tokens[toknum++];
807}]
808
809int
810main (void)
811{
812 return yyparse ();
813}
814])
815])# _AT_DATA_DANCER_Y
816
817
818# AT_CHECK_DANCER(BISON-OPTIONS)
819# ------------------------------
820# Generate the grammar, compile it, run it.
821m4_define([AT_CHECK_DANCER],
822[AT_SETUP([Dancer $1])
823AT_BISON_OPTION_PUSHDEFS([$1])
824_AT_DATA_DANCER_Y([$1])
825AT_CHECK([bison -o dancer.c dancer.y])
07971983
PE
826AT_LALR1_CC_IF(
827 [AT_CHECK([bison -o dancer.cc dancer.y])
828 AT_COMPILE_CXX([dancer])],
829 [AT_CHECK([bison -o dancer.c dancer.y])
830 AT_COMPILE([dancer])])
22e304a6 831AT_PARSER_CHECK([./dancer], 1, [],
d5286af1 832[syntax error, unexpected ':'
22e304a6
AD
833])
834AT_BISON_OPTION_POPDEFS
835AT_CLEANUP
836])
837
838AT_CHECK_DANCER()
839AT_CHECK_DANCER([%glr-parser])
840AT_CHECK_DANCER([%skeleton "lalr1.cc"])