]> git.saurik.com Git - bison.git/blame_incremental - tests/glr-regr1.at
(Badly Collapsed GLR States): Switch to Yacc-style conflict reports.
[bison.git] / tests / glr-regr1.at
... / ...
CommitLineData
1# Checking GLR Parsing: Regression Test -*- Autotest -*-
2# Copyright (C) 2002 Free Software Foundation, Inc.
3
4# This program is free software; you can redistribute it and/or modify
5# it under the terms of the GNU General Public License as published by
6# the Free Software Foundation; either version 2, or (at your option)
7# any later version.
8
9# This program is distributed in the hope that it will be useful,
10# but WITHOUT ANY WARRANTY; without even the implied warranty of
11# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12# GNU General Public License for more details.
13
14# You should have received a copy of the GNU General Public License
15# along with this program; if not, write to the Free Software
16# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
17# 02111-1307, USA.
18
19AT_BANNER([[GLR Regression Test #1.]])
20
21AT_SETUP([Badly Collapsed GLR States])
22
23AT_DATA_GRAMMAR([glr-regr1.y],
24[[/* Regression Test: Improper state compression */
25/* Reported by Scott McPeak */
26
27%{
28#include <stdio.h>
29
30#define YYSTYPE int
31static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
32int yylex (void);
33int yyerror (char const *msg);
34%}
35
36
37%glr-parser
38
39
40/* -------- productions ------ */
41%%
42
43StartSymbol: E { $$=0; } %merge <exprMerge>
44 ;
45
46E: E 'P' E { $$=1; printf("E -> E 'P' E\n"); } %merge <exprMerge>
47 | 'B' { $$=2; printf("E -> 'B'\n"); } %merge <exprMerge>
48 ;
49
50
51
52/* ---------- C code ----------- */
53%%
54
55static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1)
56{
57 (void) x0;
58 (void) x1;
59 printf ("<OR>\n");
60 return 0;
61}
62
63int
64main (void)
65{
66 return yyparse ();
67}
68
69int
70yyerror (char const *msg)
71{
72 fprintf (stderr, "%s\n", msg);
73 exit (4);
74}
75
76
77int
78yylex (void)
79{
80 for (;;)
81 {
82 int ch = getchar ();
83 if (ch == EOF)
84 return 0;
85 else if (ch == 'B' || ch == 'P')
86 return ch;
87 }
88}
89]])
90
91AT_CHECK([[bison -o glr-regr1.c glr-regr1.y]], 0, [],
92[glr-regr1.y: conflicts: 1 shift/reduce
93])
94AT_COMPILE([glr-regr1])
95AT_CHECK([[echo BPBPB | ./glr-regr1]], 0,
96[[E -> 'B'
97E -> 'B'
98E -> E 'P' E
99E -> 'B'
100E -> E 'P' E
101E -> 'B'
102E -> E 'P' E
103E -> E 'P' E
104<OR>
105]], [])
106
107AT_CLEANUP