88 |
|
|
89 |
AT_SETUP([Exotic Dollars]) |
AT_SETUP([Exotic Dollars]) |
90 |
|
|
|
# Make sure complex $n work. |
|
|
|
|
91 |
AT_DATA([[input.y]], |
AT_DATA([[input.y]], |
92 |
[[%{ |
[[%{ |
93 |
# include <stdio.h> |
# include <stdio.h> |
150 |
]]) |
]]) |
151 |
|
|
152 |
AT_CLEANUP |
AT_CLEANUP |
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
## ------------- ## |
157 |
|
## Destructors. ## |
158 |
|
## ------------- ## |
159 |
|
|
160 |
|
AT_SETUP([Destructors]) |
161 |
|
|
162 |
|
# Make sure complex $n work. |
163 |
|
|
164 |
|
AT_DATA([[input.y]], |
165 |
|
[[%{ |
166 |
|
#include <stdio.h> |
167 |
|
#include <stdlib.h> |
168 |
|
#include <assert.h> |
169 |
|
|
170 |
|
#define YYERROR_VERBOSE 1 |
171 |
|
#define YYDEBUG 1 |
172 |
|
/* #define YYPRINT yyprint */ |
173 |
|
|
174 |
|
static int yylex (void); |
175 |
|
static void yyerror (const char *msg); |
176 |
|
static void yyprint (FILE *out, int toknum, int tokval); |
177 |
|
%} |
178 |
|
|
179 |
|
%union |
180 |
|
{ |
181 |
|
int ival; |
182 |
|
} |
183 |
|
%type <ival> thing 'x' |
184 |
|
%destructor { printf ("Freeing thing %d\n", $$); } thing |
185 |
|
%destructor { printf ("Freeing 'x' %d\n", $$); } 'x' |
186 |
|
|
187 |
|
%% |
188 |
|
input: |
189 |
|
/* Nothing. */ |
190 |
|
| input line |
191 |
|
; |
192 |
|
|
193 |
|
line: |
194 |
|
thing thing thing ';' |
195 |
|
{ printf ("input: thing(%d) thing(%d) thing(%d) ';'\n", $1, $2, $3); } |
196 |
|
| thing thing ';' |
197 |
|
{ printf ("input: thing(%d) thing(%d) ';'\n", $1, $2); } |
198 |
|
| thing ';' |
199 |
|
{ printf ("input: thing(%d) ';'\n", $1); } |
200 |
|
| error ';' |
201 |
|
{ printf ("input: error ';'\n"); } |
202 |
|
; |
203 |
|
|
204 |
|
thing: |
205 |
|
'x' { printf ("thing: 'x' (%d)\n", $1); $$ = $1; } |
206 |
|
; |
207 |
|
%% |
208 |
|
static int |
209 |
|
yylex (void) |
210 |
|
{ |
211 |
|
static const int input[] = |
212 |
|
{ |
213 |
|
'x', 'x', 'x', 'x', 'x', 'x', ';', |
214 |
|
'x', 'x', ';', |
215 |
|
'x', ';', |
216 |
|
'x', 'y', ';' |
217 |
|
}; |
218 |
|
static int counter = 0; |
219 |
|
|
220 |
|
if (counter < (sizeof(input) / sizeof (input[0]))) |
221 |
|
{ |
222 |
|
yylval.ival = counter; |
223 |
|
return input[counter++]; |
224 |
|
} |
225 |
|
else |
226 |
|
return EOF; |
227 |
|
} |
228 |
|
|
229 |
|
static void |
230 |
|
yyerror (const char *msg) |
231 |
|
{ |
232 |
|
fprintf (stdout, "%s\n", msg); |
233 |
|
} |
234 |
|
|
235 |
|
static void |
236 |
|
yyprint (FILE *out, int toknum, int tokval) |
237 |
|
{ |
238 |
|
if (0 < toknum && toknum < 256) |
239 |
|
fprintf (out, " = %d", tokval); |
240 |
|
} |
241 |
|
|
242 |
|
int |
243 |
|
main (void) |
244 |
|
{ |
245 |
|
yydebug = !!getenv ("YYDEBUG"); |
246 |
|
if (yyparse ()) |
247 |
|
{ |
248 |
|
fprintf (stdout, "Parsing FAILED.\n"); |
249 |
|
exit (1); |
250 |
|
} |
251 |
|
fprintf (stdout, "Successful parse.\n"); |
252 |
|
return 0; |
253 |
|
} |
254 |
|
]]) |
255 |
|
|
256 |
|
AT_CHECK([bison input.y -d -v -o input.c]) |
257 |
|
AT_CHECK([$CC $CFLAGS $CPPFLAGS input.c -o input], 0, [], [ignore]) |
258 |
|
AT_CHECK([./input], 0, |
259 |
|
[[thing: 'x' (0) |
260 |
|
thing: 'x' (1) |
261 |
|
thing: 'x' (2) |
262 |
|
parse error, unexpected 'x', expecting ';' |
263 |
|
Freeing thing 2 |
264 |
|
Freeing thing 1 |
265 |
|
Freeing thing 0 |
266 |
|
Freeing 'x' 3 |
267 |
|
Freeing 'x' 4 |
268 |
|
Freeing 'x' 5 |
269 |
|
input: error ';' |
270 |
|
thing: 'x' (7) |
271 |
|
thing: 'x' (8) |
272 |
|
input: thing(7) thing(8) ';' |
273 |
|
thing: 'x' (10) |
274 |
|
input: thing(10) ';' |
275 |
|
thing: 'x' (12) |
276 |
|
parse error, unexpected $undefined., expecting 'x' or ';' |
277 |
|
Freeing thing 12 |
278 |
|
input: error ';' |
279 |
|
Successful parse. |
280 |
|
]]) |
281 |
|
|
282 |
|
AT_CLEANUP |