]>
Commit | Line | Data |
---|---|---|
342b8b6e | 1 | # Checking the output filenames. -*- Autotest -*- |
5504898e | 2 | # Copyright (C) 2000, 2001, 2002 Free Software Foundation, Inc. |
bfb07874 | 3 | |
342b8b6e AD |
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. | |
bfb07874 | 8 | |
342b8b6e AD |
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. | |
bfb07874 | 13 | |
342b8b6e AD |
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. | |
bfb07874 | 18 | |
bfb07874 AD |
19 | ## ---------------------------------------------------- ## |
20 | ## Compile the grammar described in the documentation. ## | |
21 | ## ---------------------------------------------------- ## | |
22 | ||
23 | ||
24 | # ------------------------- # | |
25 | # Helping Autotest macros. # | |
26 | # ------------------------- # | |
27 | ||
28 | ||
2a8d363a AD |
29 | # _AT_DATA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES]) |
30 | # ----------------------------------------------- | |
bfb07874 AD |
31 | # Produce `calc.y'. Don't call this macro directly, because it contains |
32 | # some occurrences of `$1' etc. which will be interpreted by m4. So | |
33 | # you should call it with $1, $2, and $3 as arguments, which is what | |
34 | # AT_DATA_CALC_Y does. | |
342b8b6e AD |
35 | m4_define([_AT_DATA_CALC_Y], |
36 | [m4_if([$1$2$3], $[1]$[2]$[3], [], | |
37 | [m4_fatal([$0: Invalid arguments: $@])])dnl | |
bfb07874 AD |
38 | AT_DATA([calc.y], |
39 | [[/* Infix notation calculator--calc */ | |
2a8d363a | 40 | ]$4[ |
bfb07874 | 41 | %{ |
2ce10144 | 42 | #include <config.h> |
d9684243 | 43 | /* We don't need perfect functions for these tests. */ |
342b8b6e | 44 | #undef malloc |
d9684243 PE |
45 | #undef memcmp |
46 | #undef realloc | |
bfb07874 | 47 | #include <stdio.h> |
2ce10144 AD |
48 | |
49 | #if STDC_HEADERS | |
50 | # include <stdlib.h> | |
51 | # include <string.h> | |
2ce10144 | 52 | #endif |
bfb07874 | 53 | #include <ctype.h> |
e7cb57c0 | 54 | #include <assert.h> |
bfb07874 | 55 | |
bfb07874 | 56 | extern void perror (const char *s); |
0dd1580a RA |
57 | |
58 | /* Exercise pre-prologue dependency to %union. */ | |
59 | typedef int value_t; | |
60 | ||
e7cb57c0 AD |
61 | value_t global_result = 0; |
62 | int global_count = 0; | |
63 | ||
bfb07874 AD |
64 | %} |
65 | ||
5a08f1ce | 66 | /* Exercise %union. */ |
213e640e AD |
67 | %union |
68 | { | |
5a08f1ce | 69 | value_t ival; |
213e640e AD |
70 | }; |
71 | ||
c19988b7 AD |
72 | %{ |
73 | #if YYPURE | |
74 | # define LOC (*yylloc) | |
75 | # define VAL (*yylval) | |
76 | #else | |
77 | # define LOC (yylloc) | |
78 | # define VAL (yylval) | |
79 | #endif | |
80 | ||
2a8d363a AD |
81 | #define YYLLOC_FORMAL ]AT_LOCATION_IF([, YYLTYPE *yylloc])[ |
82 | #define YYLLOC_ARG ]AT_LOCATION_IF([, yylloc])[ | |
83 | #define USE_YYLLOC ]AT_LOCATION_IF([(void) yylloc;])[ | |
84 | ||
c19988b7 | 85 | #if YYPURE |
2a8d363a AD |
86 | # define LEX_FORMALS YYSTYPE *yylval YYLLOC_FORMAL |
87 | # define LEX_ARGS yylval YYLLOC_ARG | |
88 | # define USE_LEX_ARGS (void) yylval; USE_YYLLOC | |
c19988b7 AD |
89 | # define LEX_PRE_FORMALS LEX_FORMALS, |
90 | # define LEX_PRE_ARGS LEX_ARGS, | |
91 | #else | |
92 | # define LEX_FORMALS void | |
93 | # define LEX_PRE_FORMALS | |
94 | # define LEX_ARGS | |
95 | # define LEX_PRE_ARGS | |
96 | # define USE_LEX_ARGS | |
97 | #endif | |
98 | ||
99 | static int power (int base, int exponent); | |
2a8d363a AD |
100 | /* yyerror receives the location if: |
101 | - %location & %pure & %glr | |
102 | - %location & %pure & %yacc & %parse-param. */ | |
103 | static void yyerror (const char *s | |
104 | ]AT_YYERROR_ARG_LOC_IF([, YYLTYPE *yylloc])[ | |
105 | ]AT_PARAM_IF([, value_t *result, int *count])[ | |
106 | ); | |
c19988b7 AD |
107 | static int yylex (LEX_FORMALS); |
108 | static int yygetc (LEX_FORMALS); | |
109 | static void yyungetc (LEX_PRE_FORMALS int c); | |
110 | %} | |
111 | ||
6b7e85b9 | 112 | /* Bison Declarations */ |
c19988b7 | 113 | %token CALC_EOF 0 "end of input" |
213e640e AD |
114 | %token <ival> NUM "number" |
115 | %type <ival> exp | |
bfb07874 AD |
116 | |
117 | %nonassoc '=' /* comparison */ | |
118 | %left '-' '+' | |
119 | %left '*' '/' | |
120 | %left NEG /* negation--unary minus */ | |
121 | %right '^' /* exponentiation */ | |
122 | ||
123 | /* Grammar follows */ | |
124 | %% | |
125 | input: | |
b7c49edf | 126 | line |
2a8d363a | 127 | | input line { ]AT_PARAM_IF([++*count; ++global_count;])[ } |
bfb07874 AD |
128 | ; |
129 | ||
130 | line: | |
c19988b7 | 131 | '\n' |
2a8d363a | 132 | | exp '\n' { ]AT_PARAM_IF([*result = global_result = $1;])[ } |
bfb07874 AD |
133 | ; |
134 | ||
135 | exp: | |
136 | NUM { $$ = $1; } | |
137 | | exp '=' exp | |
138 | { | |
2a8d363a AD |
139 | if ($1 != $3) |
140 | fprintf (stderr, "calc: error: %d != %d\n", $1, $3); | |
141 | $$ = $1; | |
bfb07874 AD |
142 | } |
143 | | exp '+' exp { $$ = $1 + $3; } | |
144 | | exp '-' exp { $$ = $1 - $3; } | |
145 | | exp '*' exp { $$ = $1 * $3; } | |
146 | | exp '/' exp { $$ = $1 / $3; } | |
147 | | '-' exp %prec NEG { $$ = -$2; } | |
148 | | exp '^' exp { $$ = power ($1, $3); } | |
149 | | '(' exp ')' { $$ = $2; } | |
51dec47b | 150 | | '(' error ')' { $$ = 0; } |
bfb07874 AD |
151 | ; |
152 | %% | |
153 | /* The input. */ | |
154 | FILE *yyin; | |
155 | ||
156 | static void | |
2a8d363a AD |
157 | yyerror (const char *s |
158 | ]AT_YYERROR_ARG_LOC_IF([, YYLTYPE *yylloc])[ | |
159 | ]AT_PARAM_IF([, value_t *result, int *count])[) | |
bfb07874 | 160 | { |
2a8d363a | 161 | ]AT_YYERROR_SEES_LOC_IF([ |
51dec47b | 162 | fprintf (stderr, "%d.%d-%d.%d: ", |
c19988b7 AD |
163 | LOC.first_line, LOC.first_column, |
164 | LOC.last_line, LOC.last_column); | |
2a8d363a | 165 | ])[ |
bfb07874 AD |
166 | fprintf (stderr, "%s\n", s); |
167 | } | |
168 | ||
b7c49edf | 169 | |
2a8d363a | 170 | ]AT_LOCATION_IF([ |
b7c49edf | 171 | static YYLTYPE last_yylloc; |
2a8d363a | 172 | ])[ |
bfb07874 | 173 | static int |
c19988b7 | 174 | yygetc (LEX_FORMALS) |
bfb07874 AD |
175 | { |
176 | int res = getc (yyin); | |
c19988b7 | 177 | USE_LEX_ARGS; |
2a8d363a | 178 | ]AT_LOCATION_IF([ |
c19988b7 | 179 | last_yylloc = LOC; |
bfb07874 AD |
180 | if (res == '\n') |
181 | { | |
c19988b7 AD |
182 | LOC.last_line++; |
183 | LOC.last_column = 1; | |
bfb07874 AD |
184 | } |
185 | else | |
c19988b7 | 186 | LOC.last_column++; |
2a8d363a | 187 | ])[ |
bfb07874 AD |
188 | return res; |
189 | } | |
190 | ||
191 | ||
192 | static void | |
c19988b7 | 193 | yyungetc (LEX_PRE_FORMALS int c) |
bfb07874 | 194 | { |
c19988b7 | 195 | USE_LEX_ARGS; |
2a8d363a | 196 | ]AT_LOCATION_IF([ |
bfb07874 | 197 | /* Wrong when C == `\n'. */ |
c19988b7 | 198 | LOC = last_yylloc; |
2a8d363a | 199 | ])[ |
bfb07874 AD |
200 | ungetc (c, yyin); |
201 | } | |
202 | ||
203 | static int | |
c19988b7 | 204 | read_signed_integer (LEX_FORMALS) |
bfb07874 | 205 | { |
c19988b7 | 206 | int c = yygetc (LEX_ARGS); |
bfb07874 AD |
207 | int sign = 1; |
208 | int n = 0; | |
209 | ||
c19988b7 | 210 | USE_LEX_ARGS; |
bfb07874 AD |
211 | if (c == '-') |
212 | { | |
c19988b7 | 213 | c = yygetc (LEX_ARGS); |
bfb07874 AD |
214 | sign = -1; |
215 | } | |
216 | ||
217 | while (isdigit (c)) | |
218 | { | |
219 | n = 10 * n + (c - '0'); | |
c19988b7 | 220 | c = yygetc (LEX_ARGS); |
bfb07874 AD |
221 | } |
222 | ||
c19988b7 | 223 | yyungetc (LEX_PRE_ARGS c); |
bfb07874 AD |
224 | |
225 | return sign * n; | |
226 | } | |
227 | ||
228 | ||
229 | ||
230 | /*---------------------------------------------------------------. | |
231 | | Lexical analyzer returns an integer on the stack and the token | | |
232 | | NUM, or the ASCII character read if not a number. Skips all | | |
233 | | blanks and tabs, returns 0 for EOF. | | |
234 | `---------------------------------------------------------------*/ | |
235 | ||
236 | static int | |
c19988b7 | 237 | yylex (LEX_FORMALS) |
bfb07874 | 238 | { |
c19988b7 | 239 | static int init = 1; |
bfb07874 AD |
240 | int c; |
241 | ||
c19988b7 AD |
242 | if (init) |
243 | { | |
244 | init = 0; | |
2a8d363a | 245 | ]AT_LOCATION_IF([ |
21964f43 AD |
246 | LOC.last_column = 1; |
247 | LOC.last_line = 1; | |
2a8d363a | 248 | ])[ |
c19988b7 AD |
249 | } |
250 | ||
2a8d363a | 251 | ]AT_LOCATION_IF([ |
c19988b7 AD |
252 | LOC.first_column = LOC.last_column; |
253 | LOC.first_line = LOC.last_line; | |
2a8d363a | 254 | ])[ |
bfb07874 AD |
255 | |
256 | /* Skip white space. */ | |
c19988b7 | 257 | while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t') |
bfb07874 | 258 | { |
2a8d363a | 259 | ]AT_LOCATION_IF([ |
c19988b7 AD |
260 | LOC.first_column = LOC.last_column; |
261 | LOC.first_line = LOC.last_line; | |
2a8d363a | 262 | ])[ |
bfb07874 AD |
263 | } |
264 | ||
265 | /* process numbers */ | |
266 | if (c == '.' || isdigit (c)) | |
267 | { | |
c19988b7 AD |
268 | yyungetc (LEX_PRE_ARGS c); |
269 | VAL.ival = read_signed_integer (LEX_ARGS); | |
bfb07874 AD |
270 | return NUM; |
271 | } | |
272 | ||
273 | /* Return end-of-file. */ | |
274 | if (c == EOF) | |
6b7e85b9 | 275 | return CALC_EOF; |
bfb07874 AD |
276 | |
277 | /* Return single chars. */ | |
278 | return c; | |
279 | } | |
280 | ||
281 | static int | |
282 | power (int base, int exponent) | |
283 | { | |
284 | int res = 1; | |
285 | if (exponent < 0) | |
286 | exit (1); | |
287 | for (/* Niente */; exponent; --exponent) | |
288 | res *= base; | |
289 | return res; | |
290 | } | |
291 | ||
292 | int | |
342b8b6e | 293 | main (int argc, const char **argv) |
bfb07874 | 294 | { |
e7cb57c0 AD |
295 | value_t result = 0; |
296 | int count = 0; | |
342b8b6e AD |
297 | yyin = NULL; |
298 | ||
299 | if (argc == 2) | |
bfb07874 AD |
300 | yyin = fopen (argv[1], "r"); |
301 | else | |
302 | yyin = stdin; | |
303 | ||
342b8b6e | 304 | if (!yyin) |
bfb07874 AD |
305 | { |
306 | perror (argv[1]); | |
307 | exit (1); | |
308 | } | |
309 | ||
310 | #if YYDEBUG | |
311 | yydebug = 1; | |
bfb07874 | 312 | #endif |
2a8d363a | 313 | yyparse (]AT_PARAM_IF([&result, &count])[); |
e7cb57c0 AD |
314 | assert (global_result == result); |
315 | assert (global_count == count); | |
316 | ||
bfb07874 AD |
317 | return 0; |
318 | } | |
319 | ]]) | |
320 | ])# _AT_DATA_CALC_Y | |
321 | ||
322 | ||
323 | # AT_DATA_CALC_Y([BISON-OPTIONS]) | |
324 | # ------------------------------- | |
325 | # Produce `calc.y'. | |
342b8b6e | 326 | m4_define([AT_DATA_CALC_Y], |
9e32add8 | 327 | [_AT_DATA_CALC_Y($[1], $[2], $[3], [$1]) |
f50adbbd | 328 | ]) |
bfb07874 AD |
329 | |
330 | ||
331 | ||
342b8b6e AD |
332 | # _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES = 0]) |
333 | # ------------------------------------------------------------ | |
bfb07874 | 334 | # Run `calc' on INPUT and expect no STDOUT nor STDERR. |
342b8b6e | 335 | # |
f50adbbd AD |
336 | # If BISON-OPTIONS contains `%debug' but not `%glr-parser', then |
337 | # NUM-STDERR-LINES is the number of expected lines on stderr. | |
338 | # | |
339 | # We don't count GLR's traces yet, since its traces are somewhat | |
340 | # different from LALR's. | |
342b8b6e AD |
341 | m4_define([_AT_CHECK_CALC], |
342 | [AT_DATA([[input]], | |
343 | [[$2 | |
344 | ]]) | |
f50adbbd AD |
345 | AT_PARSER_CHECK([./calc input], 0, [], [stderr]) |
346 | m4_bmatch([$1], | |
347 | [%debug.*%glr\|%glr.*%debug], | |
348 | [], | |
349 | [%debug], | |
350 | [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3 | |
351 | ])]) | |
342b8b6e AD |
352 | ]) |
353 | ||
354 | ||
355 | # _AT_CHECK_CALC_ERROR(BISON-OPTIONS, INPUT, [NUM-DEBUG-LINES], | |
2a8d363a AD |
356 | # [VERBOSE-AND-LOCATED-ERROR-MESSAGE]) |
357 | # ------------------------------------------------------------- | |
342b8b6e AD |
358 | # Run `calc' on INPUT, and expect a `parse error' message. |
359 | # | |
b7c49edf AD |
360 | # If INPUT starts with a slash, it is used as absolute input file name, |
361 | # otherwise as contents. | |
362 | # | |
9e32add8 | 363 | # If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION |
342b8b6e AD |
364 | # is correctly output on stderr. |
365 | # | |
f50adbbd | 366 | # If BISON-OPTIONS contains `%error-verbose', then make sure the |
342b8b6e AD |
367 | # IF-YYERROR-VERBOSE message is properly output after `parse error, ' |
368 | # on STDERR. | |
369 | # | |
f50adbbd AD |
370 | # If BISON-OPTIONS contains `%debug' but not `%glr', then NUM-STDERR-LINES |
371 | # is the number of expected lines on stderr. | |
342b8b6e | 372 | m4_define([_AT_CHECK_CALC_ERROR], |
b7c49edf | 373 | [m4_bmatch([$2], [^/], |
1154cced | 374 | [AT_PARSER_CHECK([./calc $2], 0, [], [stderr])], |
b7c49edf | 375 | [AT_DATA([[input]], |
342b8b6e AD |
376 | [[$2 |
377 | ]]) | |
1154cced | 378 | AT_PARSER_CHECK([./calc input], 0, [], [stderr])]) |
f50adbbd AD |
379 | m4_bmatch([$1], |
380 | [%debug.*%glr\|%glr.*%debug], | |
381 | [], | |
382 | [%debug], | |
383 | [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3 | |
51dec47b | 384 | ])]) |
342b8b6e | 385 | |
51dec47b AD |
386 | # Normalize the observed and expected error messages, depending upon the |
387 | # options. | |
388 | # 1. Remove the traces from observed. | |
9280d3ef AD |
389 | sed '/^Starting/d |
390 | /^Entering/d | |
f50adbbd | 391 | /^Stack/d |
9280d3ef AD |
392 | /^Reading/d |
393 | /^Reducing/d | |
394 | /^Shifting/d | |
395 | /^state/d | |
396 | /^Error:/d | |
397 | /^Next/d | |
398 | /^Discarding/d | |
399 | /^yydestructor:/d' stderr >at-stderr | |
342b8b6e | 400 | mv at-stderr stderr |
51dec47b AD |
401 | # 2. Create the reference error message. |
402 | AT_DATA([[expout]], | |
403 | [$4 | |
342b8b6e | 404 | ]) |
51dec47b | 405 | # 3. If locations are not used, remove them. |
2a8d363a | 406 | AT_YYERROR_SEES_LOC_IF([], |
51dec47b AD |
407 | [[sed 's/^[-0-9.]*: //' expout >at-expout |
408 | mv at-expout expout]]) | |
409 | # 4. If error-verbose is not used, strip the`, unexpected....' part. | |
f50adbbd | 410 | m4_bmatch([$1], [%error-verbose], [], |
51dec47b AD |
411 | [[sed 's/parse error, .*$/parse error/' expout >at-expout |
412 | mv at-expout expout]]) | |
413 | # 5. Check | |
414 | AT_CHECK([cat stderr], 0, [expout]) | |
342b8b6e | 415 | ]) |
bfb07874 AD |
416 | |
417 | ||
2a8d363a AD |
418 | # AT_CALC_PUSHDEFS($1, $2, [BISON-OPTIONS]) |
419 | # ----------------------------------------- | |
420 | # This macro works around the impossibility to define macros | |
421 | # inside macros, because issuing `[$1]' is not possible in M4 :(. | |
422 | # This sucks hard, GNU M4 should really provide M5 like $$1. | |
423 | m4_define([AT_CHECK_PUSHDEFS], | |
424 | [m4_if([$1$2], $[1]$[2], [], | |
425 | [m4_fatal([$0: Invalid arguments: $@])])dnl | |
426 | m4_pushdef([AT_PARAM_IF], | |
427 | [m4_bmatch([$3], [%parse-param], [$1], [$2])]) | |
428 | m4_pushdef([AT_LOCATION_IF], | |
429 | [m4_bmatch([$3], [%locations], [$1], [$2])]) | |
430 | m4_pushdef([AT_PURE_IF], | |
431 | [m4_bmatch([$3], [%pure-parser], [$1], [$2])]) | |
432 | m4_pushdef([AT_GLR_IF], | |
433 | [m4_bmatch([$3], [%glr-parser], [$1], [$2])]) | |
434 | m4_pushdef([AT_PURE_AND_LOC_IF], | |
435 | [m4_bmatch([$3], [%locations.*%pure-parser\|%pure-parser.*%locations], | |
436 | [$1], [$2])]) | |
437 | m4_pushdef([AT_GLR_OR_PARAM_IF], | |
438 | [m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])]) | |
439 | ||
440 | # yyerror receives the location if %location & %pure & (%glr or %parse-param). | |
441 | m4_pushdef([AT_YYERROR_ARG_LOC_IF], | |
442 | [AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])], | |
443 | [$2])]) | |
444 | # yyerror cannot see the locations if !glr & pure. | |
445 | m4_pushdef([AT_YYERROR_SEES_LOC_IF], | |
446 | [AT_LOCATION_IF([AT_GLR_IF([$1], | |
447 | [AT_PURE_IF([$2], [$1])])], | |
448 | [$2])]) | |
449 | ]) | |
450 | ||
451 | ||
452 | # AT_CALC_POPDEFS | |
453 | # --------------- | |
454 | m4_define([AT_CHECK_POPDEFS], | |
455 | [m4_popdef([AT_YYERROR_SEES_LOC_IF]) | |
456 | m4_popdef([AT_YYERROR_ARG_LOC_IF]) | |
457 | m4_popdef([AT_GLR_OR_PARAM_IF]) | |
458 | m4_popdef([AT_PURE_AND_LOC_IF]) | |
459 | m4_popdef([AT_GLR_IF]) | |
460 | m4_popdef([AT_LOCATION_IF]) | |
461 | m4_popdef([AT_PARAM_IF]) | |
462 | ]) | |
463 | ||
464 | ||
465 | ||
f50adbbd AD |
466 | # AT_CHECK_CALC([BISON-OPTIONS]) |
467 | # ------------------------------ | |
bfb07874 AD |
468 | # Start a testing chunk which compiles `calc' grammar with |
469 | # BISON-OPTIONS, and performs several tests over the parser. | |
342b8b6e | 470 | m4_define([AT_CHECK_CALC], |
bfb07874 AD |
471 | [# We use integers to avoid dependencies upon the precision of doubles. |
472 | AT_SETUP([Calculator $1]) | |
473 | ||
2a8d363a AD |
474 | AT_CHECK_PUSHDEFS($[1], $[2], [$1]) |
475 | ||
bfb07874 AD |
476 | AT_DATA_CALC_Y([$1]) |
477 | ||
478 | # Specify the output files to avoid problems on different file systems. | |
9e32add8 | 479 | AT_CHECK([bison -o calc.c calc.y], |
bfb07874 | 480 | [0], [], []) |
3c1a79b3 | 481 | |
1154cced | 482 | AT_COMPILE([calc]) |
bfb07874 AD |
483 | |
484 | # Test the priorities. | |
485 | _AT_CHECK_CALC([$1], | |
486 | [1 + 2 * 3 = 7 | |
487 | 1 + 2 * -3 = -5 | |
488 | ||
489 | -1^2 = -1 | |
490 | (-1)^2 = 1 | |
491 | ||
492 | ---1 = -1 | |
493 | ||
494 | 1 - 2 - 3 = -4 | |
495 | 1 - (2 - 3) = 2 | |
496 | ||
497 | 2^2^3 = 256 | |
e7cb57c0 AD |
498 | (2^2)^3 = 64], |
499 | [486]) | |
bfb07874 AD |
500 | |
501 | # Some parse errors. | |
366eea36 | 502 | _AT_CHECK_CALC_ERROR([$1], [0 0], [11], |
51dec47b | 503 | [1.3-1.4: parse error, unexpected "number"]) |
366eea36 | 504 | _AT_CHECK_CALC_ERROR([$1], [1//2], [15], |
51dec47b | 505 | [1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '(']) |
b7c49edf | 506 | _AT_CHECK_CALC_ERROR([$1], [error], [4], |
88bce5a2 | 507 | [1.1-1.2: parse error, unexpected $undefined, expecting "number" or '-' or '\n' or '(']) |
366eea36 | 508 | _AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [22], |
51dec47b | 509 | [1.7-1.8: parse error, unexpected '=']) |
bfb07874 AD |
510 | _AT_CHECK_CALC_ERROR([$1], |
511 | [ | |
512 | +1], | |
366eea36 | 513 | [14], |
51dec47b | 514 | [2.1-2.2: parse error, unexpected '+']) |
b7c49edf | 515 | # Exercise error messages with EOF: work on an empty file. |
366eea36 | 516 | _AT_CHECK_CALC_ERROR([$1], [/dev/null], [4], |
c19988b7 | 517 | [1.1-1.2: parse error, unexpected "end of input", expecting "number" or '-' or '\n' or '(']) |
51dec47b AD |
518 | |
519 | # Exercise the error token: without it, we die at the first error, | |
520 | # hence be sure i. to have several errors, ii. to test the action | |
521 | # associated to `error'. | |
366eea36 | 522 | _AT_CHECK_CALC_ERROR([$1], [(1 ++ 2) + (0 0) = 1], [82], |
51dec47b AD |
523 | [1.5-1.6: parse error, unexpected '+', expecting "number" or '-' or '(' |
524 | 1.15-1.16: parse error, unexpected "number" | |
525 | calc: error: 0 != 1]) | |
526 | ||
2a8d363a AD |
527 | AT_CHECK_POPDEFS |
528 | ||
d803322e | 529 | AT_CLEANUP |
bfb07874 AD |
530 | ])# AT_CHECK_CALC |
531 | ||
532 | ||
533 | ||
534 | ||
f50adbbd AD |
535 | # ------------------------ # |
536 | # Simple LALR Calculator. # | |
537 | # ------------------------ # | |
538 | ||
539 | AT_BANNER([[Simple LALR Calculator.]]) | |
540 | ||
541 | # AT_CHECK_CALC_LALR([BISON-OPTIONS]) | |
542 | # ----------------------------------- | |
543 | # Start a testing chunk which compiles `calc' grammar with | |
544 | # BISON-OPTIONS, and performs several tests over the parser. | |
545 | m4_define([AT_CHECK_CALC_LALR], | |
546 | [AT_CHECK_CALC($@)]) | |
547 | ||
548 | AT_CHECK_CALC_LALR() | |
549 | ||
9e32add8 | 550 | AT_CHECK_CALC_LALR([%defines]) |
ae7453f2 | 551 | AT_CHECK_CALC_LALR([%locations]) |
9e32add8 AD |
552 | AT_CHECK_CALC_LALR([%name-prefix="calc"]) |
553 | AT_CHECK_CALC_LALR([%verbose]) | |
554 | AT_CHECK_CALC_LALR([%yacc]) | |
f50adbbd AD |
555 | AT_CHECK_CALC_LALR([%error-verbose]) |
556 | ||
ae7453f2 | 557 | AT_CHECK_CALC_LALR([%error-verbose %locations]) |
f50adbbd | 558 | |
9e32add8 | 559 | AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) |
f50adbbd AD |
560 | |
561 | AT_CHECK_CALC_LALR([%debug]) | |
9e32add8 | 562 | AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
c19988b7 | 563 | |
2a8d363a AD |
564 | AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
565 | ||
566 | AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param "value_t *result", "result" %parse-param "int *count", "count"]) | |
f50adbbd AD |
567 | |
568 | ||
569 | # ----------------------- # | |
570 | # Simple GLR Calculator. # | |
571 | # ----------------------- # | |
572 | ||
573 | AT_BANNER([[Simple GLR Calculator.]]) | |
574 | ||
575 | # AT_CHECK_CALC_GLR([BISON-OPTIONS]) | |
576 | # ---------------------------------- | |
577 | # Start a testing chunk which compiles `calc' grammar with | |
578 | # BISON-OPTIONS and %glr-parser, and performs several tests over the parser. | |
579 | m4_define([AT_CHECK_CALC_GLR], | |
ae7453f2 | 580 | [AT_CHECK_CALC([%glr-parser] $@)]) |
f50adbbd | 581 | |
bfb07874 | 582 | |
f50adbbd | 583 | AT_CHECK_CALC_GLR() |
bfb07874 | 584 | |
9e32add8 | 585 | AT_CHECK_CALC_GLR([%defines]) |
ae7453f2 | 586 | AT_CHECK_CALC_GLR([%locations]) |
9e32add8 AD |
587 | AT_CHECK_CALC_GLR([%name-prefix="calc"]) |
588 | AT_CHECK_CALC_GLR([%verbose]) | |
589 | AT_CHECK_CALC_GLR([%yacc]) | |
f50adbbd | 590 | AT_CHECK_CALC_GLR([%error-verbose]) |
bfb07874 | 591 | |
ae7453f2 | 592 | AT_CHECK_CALC_GLR([%error-verbose %locations]) |
bfb07874 | 593 | |
9e32add8 | 594 | AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) |
bfb07874 | 595 | |
f50adbbd | 596 | AT_CHECK_CALC_GLR([%debug]) |
9e32add8 | 597 | AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
21964f43 | 598 | |
2a8d363a AD |
599 | AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
600 | ||
601 | AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param "value_t *result", "result" %parse-param "int *count", "count"]) |