]> git.saurik.com Git - bison.git/blame - tests/glr-regression.at
Regenerate.
[bison.git] / tests / glr-regression.at
CommitLineData
ede3d3bc 1# Checking GLR Parsing: Regression Tests -*- Autotest -*-
d6d67dbd 2# Copyright (C) 2002, 2003, 2005 Free Software Foundation, Inc.
ede3d3bc
PH
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 Tests]])
20
21## --------------------------- ##
22## Badly Collapsed GLR States. ##
23## --------------------------- ##
24
25AT_SETUP([Badly Collapsed GLR States])
26
27AT_DATA_GRAMMAR([glr-regr1.y],
28[[/* Regression Test: Improper state compression */
29/* Reported by Scott McPeak */
30
31%{
32#include <stdio.h>
33
34#define YYSTYPE int
35static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1);
36int yylex (void);
37int yyerror (char const *msg);
38%}
39
40
41%glr-parser
42
43
44/* -------- productions ------ */
45%%
46
47StartSymbol: E { $$=0; } %merge <exprMerge>
48 ;
49
50E: E 'P' E { $$=1; printf("E -> E 'P' E\n"); } %merge <exprMerge>
51 | 'B' { $$=2; printf("E -> 'B'\n"); } %merge <exprMerge>
52 ;
53
54
55
56/* ---------- C code ----------- */
57%%
58
59static YYSTYPE exprMerge (YYSTYPE x0, YYSTYPE x1)
60{
61 (void) x0;
62 (void) x1;
63 printf ("<OR>\n");
64 return 0;
65}
66
67int
68main (void)
69{
70 return yyparse ();
71}
72
73int
74yyerror (char const *msg)
75{
76 fprintf (stderr, "%s\n", msg);
77 exit (4);
78}
79
80
81int
82yylex (void)
83{
84 for (;;)
85 {
86 int ch = getchar ();
87 if (ch == EOF)
88 return 0;
89 else if (ch == 'B' || ch == 'P')
90 return ch;
91 }
92}
93]])
94
95AT_CHECK([[bison -o glr-regr1.c glr-regr1.y]], 0, [],
96[glr-regr1.y: conflicts: 1 shift/reduce
97])
98AT_COMPILE([glr-regr1])
99AT_CHECK([[echo BPBPB | ./glr-regr1]], 0,
100[[E -> 'B'
101E -> 'B'
102E -> E 'P' E
103E -> 'B'
104E -> E 'P' E
105E -> 'B'
106E -> E 'P' E
107E -> E 'P' E
108<OR>
109]], [])
110
111AT_CLEANUP
112
113## ------------------------------------------------------------ ##
114## Improper handling of embedded actions and $-N in GLR parsers ##
115## ------------------------------------------------------------ ##
116
d6d67dbd 117AT_SETUP([Improper handling of embedded actions and dollar(-N) in GLR parsers])
ede3d3bc
PH
118
119AT_DATA_GRAMMAR([glr-regr2a.y],
120[[/* Regression Test: Improper handling of embedded actions and $-N */
121/* Reported by S. Eken */
122
123%{
124 #define YYSTYPE char const *
125 #define yyfalse 0
126 #define yytrue 1
127
128 #include <ctype.h>
129 #include <stdio.h>
130 #include <string.h>
131 int yylex (void);
132 void yyerror (char const *);
133%}
134
135%glr-parser
136
137%%
138
139command:
140 's' var 't'
d6d67dbd 141 { printf ("Variable: '%s'\n", $2); }
ede3d3bc
PH
142 'v' 'x' 'q'
143 | 's' var_list 't' 'e'
144 { printf ("Varlist: '%s'\n", $2); }
145 | 's' var 't' var_printer 'x'
146 ;
147
148var:
149 'V'
150 { $$ = $1; }
151 ;
152
153var_list:
154 var
155 { $$ = $1; }
156 | var ',' var_list
157 {
158 char buffer[50];
d6d67dbd 159 strcpy (buffer, $1);
ede3d3bc
PH
160 strcat (buffer, ",");
161 strcat (buffer, $3);
162 $$ = strdup (buffer);
d6d67dbd 163 }
ede3d3bc
PH
164 ;
165
166var_printer: 'v'
167 { printf ("Variable: '%s'\n", $-1); }
168
169%%
170
171FILE *yyin = NULL;
172
173int
174yylex (void)
d6d67dbd 175{
ede3d3bc
PH
176 char buf[50];
177 switch (fscanf (yyin, " %1[a-z,]", buf)) {
178 case 1:
179 return buf[0];
180 case EOF:
181 return 0;
182 default:
183 break;
184 }
185 fscanf (yyin, "%s", buf);
186 yylval = strdup (buf);
187 return 'V';
188}
189
190void
191yyerror (char const *s)
192{ printf ("%s\n", s);
193}
194
195int
196main (int argc, char **argv)
d6d67dbd 197{
ede3d3bc
PH
198 yyin = stdin;
199 if (argc == 2 && !(yyin = fopen (argv[1], "r"))) return 1;
200 return yyparse ();
201}
202]])
203
204AT_CHECK([[bison -o glr-regr2a.c glr-regr2a.y]], 0, [],
205[glr-regr2a.y: conflicts: 2 shift/reduce
206])
207AT_COMPILE([glr-regr2a])
208
209AT_CHECK([[echo s VARIABLE_1 t v x q | ./glr-regr2a]], 0,
210[[Variable: 'VARIABLE_1'
211]], [])
212AT_CHECK([[echo s VARIABLE_1 , ANOTHER_VARIABLE_2 t e | ./glr-regr2a]], 0,
213[[Varlist: 'VARIABLE_1,ANOTHER_VARIABLE_2'
214]])
215AT_CHECK([[echo s VARIABLE_3 t v x | ./glr-regr2a]], 0,
216[[Variable: 'VARIABLE_3'
217]], [])
218
219
220AT_CLEANUP