]>
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. */ | |
93724f13 AD |
103 | static void yyerror (]AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ])[ |
104 | ]AT_PARAM_IF([value_t *result, int *count, ])[ | |
105 | const char *s | |
2a8d363a | 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 | |
93724f13 AD |
157 | yyerror (]AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ])[ |
158 | ]AT_PARAM_IF([value_t *result, int *count, ])[ | |
159 | const char *s | |
160 | ) | |
bfb07874 | 161 | { |
793a58bb | 162 | ]AT_PARAM_IF([(void) result; (void) count; ])[ |
2a8d363a | 163 | ]AT_YYERROR_SEES_LOC_IF([ |
51dec47b | 164 | fprintf (stderr, "%d.%d-%d.%d: ", |
c19988b7 AD |
165 | LOC.first_line, LOC.first_column, |
166 | LOC.last_line, LOC.last_column); | |
2a8d363a | 167 | ])[ |
bfb07874 AD |
168 | fprintf (stderr, "%s\n", s); |
169 | } | |
170 | ||
b7c49edf | 171 | |
2a8d363a | 172 | ]AT_LOCATION_IF([ |
b7c49edf | 173 | static YYLTYPE last_yylloc; |
2a8d363a | 174 | ])[ |
bfb07874 | 175 | static int |
c19988b7 | 176 | yygetc (LEX_FORMALS) |
bfb07874 AD |
177 | { |
178 | int res = getc (yyin); | |
c19988b7 | 179 | USE_LEX_ARGS; |
2a8d363a | 180 | ]AT_LOCATION_IF([ |
c19988b7 | 181 | last_yylloc = LOC; |
bfb07874 AD |
182 | if (res == '\n') |
183 | { | |
c19988b7 AD |
184 | LOC.last_line++; |
185 | LOC.last_column = 1; | |
bfb07874 AD |
186 | } |
187 | else | |
c19988b7 | 188 | LOC.last_column++; |
2a8d363a | 189 | ])[ |
bfb07874 AD |
190 | return res; |
191 | } | |
192 | ||
193 | ||
194 | static void | |
c19988b7 | 195 | yyungetc (LEX_PRE_FORMALS int c) |
bfb07874 | 196 | { |
c19988b7 | 197 | USE_LEX_ARGS; |
2a8d363a | 198 | ]AT_LOCATION_IF([ |
bfb07874 | 199 | /* Wrong when C == `\n'. */ |
c19988b7 | 200 | LOC = last_yylloc; |
2a8d363a | 201 | ])[ |
bfb07874 AD |
202 | ungetc (c, yyin); |
203 | } | |
204 | ||
205 | static int | |
c19988b7 | 206 | read_signed_integer (LEX_FORMALS) |
bfb07874 | 207 | { |
c19988b7 | 208 | int c = yygetc (LEX_ARGS); |
bfb07874 AD |
209 | int sign = 1; |
210 | int n = 0; | |
211 | ||
c19988b7 | 212 | USE_LEX_ARGS; |
bfb07874 AD |
213 | if (c == '-') |
214 | { | |
c19988b7 | 215 | c = yygetc (LEX_ARGS); |
bfb07874 AD |
216 | sign = -1; |
217 | } | |
218 | ||
219 | while (isdigit (c)) | |
220 | { | |
221 | n = 10 * n + (c - '0'); | |
c19988b7 | 222 | c = yygetc (LEX_ARGS); |
bfb07874 AD |
223 | } |
224 | ||
c19988b7 | 225 | yyungetc (LEX_PRE_ARGS c); |
bfb07874 AD |
226 | |
227 | return sign * n; | |
228 | } | |
229 | ||
230 | ||
231 | ||
232 | /*---------------------------------------------------------------. | |
233 | | Lexical analyzer returns an integer on the stack and the token | | |
234 | | NUM, or the ASCII character read if not a number. Skips all | | |
235 | | blanks and tabs, returns 0 for EOF. | | |
236 | `---------------------------------------------------------------*/ | |
237 | ||
238 | static int | |
c19988b7 | 239 | yylex (LEX_FORMALS) |
bfb07874 | 240 | { |
c19988b7 | 241 | static int init = 1; |
bfb07874 AD |
242 | int c; |
243 | ||
c19988b7 AD |
244 | if (init) |
245 | { | |
246 | init = 0; | |
2a8d363a | 247 | ]AT_LOCATION_IF([ |
21964f43 AD |
248 | LOC.last_column = 1; |
249 | LOC.last_line = 1; | |
2a8d363a | 250 | ])[ |
c19988b7 AD |
251 | } |
252 | ||
2a8d363a | 253 | ]AT_LOCATION_IF([ |
c19988b7 AD |
254 | LOC.first_column = LOC.last_column; |
255 | LOC.first_line = LOC.last_line; | |
2a8d363a | 256 | ])[ |
bfb07874 AD |
257 | |
258 | /* Skip white space. */ | |
c19988b7 | 259 | while ((c = yygetc (LEX_ARGS)) == ' ' || c == '\t') |
bfb07874 | 260 | { |
2a8d363a | 261 | ]AT_LOCATION_IF([ |
c19988b7 AD |
262 | LOC.first_column = LOC.last_column; |
263 | LOC.first_line = LOC.last_line; | |
2a8d363a | 264 | ])[ |
bfb07874 AD |
265 | } |
266 | ||
267 | /* process numbers */ | |
268 | if (c == '.' || isdigit (c)) | |
269 | { | |
c19988b7 AD |
270 | yyungetc (LEX_PRE_ARGS c); |
271 | VAL.ival = read_signed_integer (LEX_ARGS); | |
bfb07874 AD |
272 | return NUM; |
273 | } | |
274 | ||
275 | /* Return end-of-file. */ | |
276 | if (c == EOF) | |
6b7e85b9 | 277 | return CALC_EOF; |
bfb07874 AD |
278 | |
279 | /* Return single chars. */ | |
280 | return c; | |
281 | } | |
282 | ||
283 | static int | |
284 | power (int base, int exponent) | |
285 | { | |
286 | int res = 1; | |
287 | if (exponent < 0) | |
288 | exit (1); | |
289 | for (/* Niente */; exponent; --exponent) | |
290 | res *= base; | |
291 | return res; | |
292 | } | |
293 | ||
294 | int | |
342b8b6e | 295 | main (int argc, const char **argv) |
bfb07874 | 296 | { |
e7cb57c0 AD |
297 | value_t result = 0; |
298 | int count = 0; | |
342b8b6e AD |
299 | yyin = NULL; |
300 | ||
301 | if (argc == 2) | |
bfb07874 AD |
302 | yyin = fopen (argv[1], "r"); |
303 | else | |
304 | yyin = stdin; | |
305 | ||
342b8b6e | 306 | if (!yyin) |
bfb07874 AD |
307 | { |
308 | perror (argv[1]); | |
309 | exit (1); | |
310 | } | |
311 | ||
312 | #if YYDEBUG | |
313 | yydebug = 1; | |
bfb07874 | 314 | #endif |
2a8d363a | 315 | yyparse (]AT_PARAM_IF([&result, &count])[); |
e7cb57c0 AD |
316 | assert (global_result == result); |
317 | assert (global_count == count); | |
318 | ||
bfb07874 AD |
319 | return 0; |
320 | } | |
321 | ]]) | |
322 | ])# _AT_DATA_CALC_Y | |
323 | ||
324 | ||
325 | # AT_DATA_CALC_Y([BISON-OPTIONS]) | |
326 | # ------------------------------- | |
327 | # Produce `calc.y'. | |
342b8b6e | 328 | m4_define([AT_DATA_CALC_Y], |
9e32add8 | 329 | [_AT_DATA_CALC_Y($[1], $[2], $[3], [$1]) |
f50adbbd | 330 | ]) |
bfb07874 AD |
331 | |
332 | ||
333 | ||
342b8b6e AD |
334 | # _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES = 0]) |
335 | # ------------------------------------------------------------ | |
bfb07874 | 336 | # Run `calc' on INPUT and expect no STDOUT nor STDERR. |
342b8b6e | 337 | # |
f50adbbd AD |
338 | # If BISON-OPTIONS contains `%debug' but not `%glr-parser', then |
339 | # NUM-STDERR-LINES is the number of expected lines on stderr. | |
340 | # | |
341 | # We don't count GLR's traces yet, since its traces are somewhat | |
342 | # different from LALR's. | |
342b8b6e AD |
343 | m4_define([_AT_CHECK_CALC], |
344 | [AT_DATA([[input]], | |
345 | [[$2 | |
346 | ]]) | |
f50adbbd AD |
347 | AT_PARSER_CHECK([./calc input], 0, [], [stderr]) |
348 | m4_bmatch([$1], | |
349 | [%debug.*%glr\|%glr.*%debug], | |
350 | [], | |
351 | [%debug], | |
352 | [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3 | |
353 | ])]) | |
342b8b6e AD |
354 | ]) |
355 | ||
356 | ||
357 | # _AT_CHECK_CALC_ERROR(BISON-OPTIONS, INPUT, [NUM-DEBUG-LINES], | |
2a8d363a AD |
358 | # [VERBOSE-AND-LOCATED-ERROR-MESSAGE]) |
359 | # ------------------------------------------------------------- | |
342b8b6e AD |
360 | # Run `calc' on INPUT, and expect a `parse error' message. |
361 | # | |
b7c49edf AD |
362 | # If INPUT starts with a slash, it is used as absolute input file name, |
363 | # otherwise as contents. | |
364 | # | |
9e32add8 | 365 | # If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION |
342b8b6e AD |
366 | # is correctly output on stderr. |
367 | # | |
f50adbbd | 368 | # If BISON-OPTIONS contains `%error-verbose', then make sure the |
342b8b6e AD |
369 | # IF-YYERROR-VERBOSE message is properly output after `parse error, ' |
370 | # on STDERR. | |
371 | # | |
f50adbbd AD |
372 | # If BISON-OPTIONS contains `%debug' but not `%glr', then NUM-STDERR-LINES |
373 | # is the number of expected lines on stderr. | |
342b8b6e | 374 | m4_define([_AT_CHECK_CALC_ERROR], |
b7c49edf | 375 | [m4_bmatch([$2], [^/], |
1154cced | 376 | [AT_PARSER_CHECK([./calc $2], 0, [], [stderr])], |
b7c49edf | 377 | [AT_DATA([[input]], |
342b8b6e AD |
378 | [[$2 |
379 | ]]) | |
1154cced | 380 | AT_PARSER_CHECK([./calc input], 0, [], [stderr])]) |
f50adbbd AD |
381 | m4_bmatch([$1], |
382 | [%debug.*%glr\|%glr.*%debug], | |
383 | [], | |
384 | [%debug], | |
385 | [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3 | |
51dec47b | 386 | ])]) |
342b8b6e | 387 | |
51dec47b AD |
388 | # Normalize the observed and expected error messages, depending upon the |
389 | # options. | |
390 | # 1. Remove the traces from observed. | |
9280d3ef AD |
391 | sed '/^Starting/d |
392 | /^Entering/d | |
f50adbbd | 393 | /^Stack/d |
9280d3ef AD |
394 | /^Reading/d |
395 | /^Reducing/d | |
396 | /^Shifting/d | |
397 | /^state/d | |
398 | /^Error:/d | |
399 | /^Next/d | |
400 | /^Discarding/d | |
401 | /^yydestructor:/d' stderr >at-stderr | |
342b8b6e | 402 | mv at-stderr stderr |
51dec47b AD |
403 | # 2. Create the reference error message. |
404 | AT_DATA([[expout]], | |
405 | [$4 | |
342b8b6e | 406 | ]) |
51dec47b | 407 | # 3. If locations are not used, remove them. |
2a8d363a | 408 | AT_YYERROR_SEES_LOC_IF([], |
51dec47b AD |
409 | [[sed 's/^[-0-9.]*: //' expout >at-expout |
410 | mv at-expout expout]]) | |
411 | # 4. If error-verbose is not used, strip the`, unexpected....' part. | |
f50adbbd | 412 | m4_bmatch([$1], [%error-verbose], [], |
51dec47b AD |
413 | [[sed 's/parse error, .*$/parse error/' expout >at-expout |
414 | mv at-expout expout]]) | |
415 | # 5. Check | |
416 | AT_CHECK([cat stderr], 0, [expout]) | |
342b8b6e | 417 | ]) |
bfb07874 AD |
418 | |
419 | ||
2a8d363a AD |
420 | # AT_CALC_PUSHDEFS($1, $2, [BISON-OPTIONS]) |
421 | # ----------------------------------------- | |
422 | # This macro works around the impossibility to define macros | |
423 | # inside macros, because issuing `[$1]' is not possible in M4 :(. | |
424 | # This sucks hard, GNU M4 should really provide M5 like $$1. | |
425 | m4_define([AT_CHECK_PUSHDEFS], | |
426 | [m4_if([$1$2], $[1]$[2], [], | |
427 | [m4_fatal([$0: Invalid arguments: $@])])dnl | |
428 | m4_pushdef([AT_PARAM_IF], | |
429 | [m4_bmatch([$3], [%parse-param], [$1], [$2])]) | |
430 | m4_pushdef([AT_LOCATION_IF], | |
431 | [m4_bmatch([$3], [%locations], [$1], [$2])]) | |
432 | m4_pushdef([AT_PURE_IF], | |
433 | [m4_bmatch([$3], [%pure-parser], [$1], [$2])]) | |
434 | m4_pushdef([AT_GLR_IF], | |
435 | [m4_bmatch([$3], [%glr-parser], [$1], [$2])]) | |
436 | m4_pushdef([AT_PURE_AND_LOC_IF], | |
437 | [m4_bmatch([$3], [%locations.*%pure-parser\|%pure-parser.*%locations], | |
438 | [$1], [$2])]) | |
439 | m4_pushdef([AT_GLR_OR_PARAM_IF], | |
440 | [m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])]) | |
441 | ||
442 | # yyerror receives the location if %location & %pure & (%glr or %parse-param). | |
443 | m4_pushdef([AT_YYERROR_ARG_LOC_IF], | |
444 | [AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])], | |
445 | [$2])]) | |
793a58bb | 446 | # yyerror cannot see the locations if !glr & pure & !param. |
2a8d363a AD |
447 | m4_pushdef([AT_YYERROR_SEES_LOC_IF], |
448 | [AT_LOCATION_IF([AT_GLR_IF([$1], | |
793a58bb AD |
449 | [AT_PURE_IF([AT_PARAM_IF([$1], [$2])], |
450 | [$1])])], | |
2a8d363a AD |
451 | [$2])]) |
452 | ]) | |
453 | ||
454 | ||
455 | # AT_CALC_POPDEFS | |
456 | # --------------- | |
457 | m4_define([AT_CHECK_POPDEFS], | |
458 | [m4_popdef([AT_YYERROR_SEES_LOC_IF]) | |
459 | m4_popdef([AT_YYERROR_ARG_LOC_IF]) | |
460 | m4_popdef([AT_GLR_OR_PARAM_IF]) | |
461 | m4_popdef([AT_PURE_AND_LOC_IF]) | |
462 | m4_popdef([AT_GLR_IF]) | |
463 | m4_popdef([AT_LOCATION_IF]) | |
464 | m4_popdef([AT_PARAM_IF]) | |
465 | ]) | |
466 | ||
467 | ||
468 | ||
f50adbbd AD |
469 | # AT_CHECK_CALC([BISON-OPTIONS]) |
470 | # ------------------------------ | |
bfb07874 AD |
471 | # Start a testing chunk which compiles `calc' grammar with |
472 | # BISON-OPTIONS, and performs several tests over the parser. | |
342b8b6e | 473 | m4_define([AT_CHECK_CALC], |
bfb07874 AD |
474 | [# We use integers to avoid dependencies upon the precision of doubles. |
475 | AT_SETUP([Calculator $1]) | |
476 | ||
2a8d363a AD |
477 | AT_CHECK_PUSHDEFS($[1], $[2], [$1]) |
478 | ||
bfb07874 AD |
479 | AT_DATA_CALC_Y([$1]) |
480 | ||
481 | # Specify the output files to avoid problems on different file systems. | |
9e32add8 | 482 | AT_CHECK([bison -o calc.c calc.y], |
bfb07874 | 483 | [0], [], []) |
3c1a79b3 | 484 | |
1154cced | 485 | AT_COMPILE([calc]) |
bfb07874 AD |
486 | |
487 | # Test the priorities. | |
488 | _AT_CHECK_CALC([$1], | |
489 | [1 + 2 * 3 = 7 | |
490 | 1 + 2 * -3 = -5 | |
491 | ||
492 | -1^2 = -1 | |
493 | (-1)^2 = 1 | |
494 | ||
495 | ---1 = -1 | |
496 | ||
497 | 1 - 2 - 3 = -4 | |
498 | 1 - (2 - 3) = 2 | |
499 | ||
500 | 2^2^3 = 256 | |
e7cb57c0 AD |
501 | (2^2)^3 = 64], |
502 | [486]) | |
bfb07874 AD |
503 | |
504 | # Some parse errors. | |
366eea36 | 505 | _AT_CHECK_CALC_ERROR([$1], [0 0], [11], |
51dec47b | 506 | [1.3-1.4: parse error, unexpected "number"]) |
366eea36 | 507 | _AT_CHECK_CALC_ERROR([$1], [1//2], [15], |
51dec47b | 508 | [1.3-1.4: parse error, unexpected '/', expecting "number" or '-' or '(']) |
b7c49edf | 509 | _AT_CHECK_CALC_ERROR([$1], [error], [4], |
88bce5a2 | 510 | [1.1-1.2: parse error, unexpected $undefined, expecting "number" or '-' or '\n' or '(']) |
366eea36 | 511 | _AT_CHECK_CALC_ERROR([$1], [1 = 2 = 3], [22], |
51dec47b | 512 | [1.7-1.8: parse error, unexpected '=']) |
bfb07874 AD |
513 | _AT_CHECK_CALC_ERROR([$1], |
514 | [ | |
515 | +1], | |
366eea36 | 516 | [14], |
51dec47b | 517 | [2.1-2.2: parse error, unexpected '+']) |
b7c49edf | 518 | # Exercise error messages with EOF: work on an empty file. |
366eea36 | 519 | _AT_CHECK_CALC_ERROR([$1], [/dev/null], [4], |
c19988b7 | 520 | [1.1-1.2: parse error, unexpected "end of input", expecting "number" or '-' or '\n' or '(']) |
51dec47b AD |
521 | |
522 | # Exercise the error token: without it, we die at the first error, | |
523 | # hence be sure i. to have several errors, ii. to test the action | |
524 | # associated to `error'. | |
366eea36 | 525 | _AT_CHECK_CALC_ERROR([$1], [(1 ++ 2) + (0 0) = 1], [82], |
51dec47b AD |
526 | [1.5-1.6: parse error, unexpected '+', expecting "number" or '-' or '(' |
527 | 1.15-1.16: parse error, unexpected "number" | |
528 | calc: error: 0 != 1]) | |
529 | ||
2a8d363a AD |
530 | AT_CHECK_POPDEFS |
531 | ||
d803322e | 532 | AT_CLEANUP |
bfb07874 AD |
533 | ])# AT_CHECK_CALC |
534 | ||
535 | ||
536 | ||
537 | ||
f50adbbd AD |
538 | # ------------------------ # |
539 | # Simple LALR Calculator. # | |
540 | # ------------------------ # | |
541 | ||
542 | AT_BANNER([[Simple LALR Calculator.]]) | |
543 | ||
544 | # AT_CHECK_CALC_LALR([BISON-OPTIONS]) | |
545 | # ----------------------------------- | |
546 | # Start a testing chunk which compiles `calc' grammar with | |
547 | # BISON-OPTIONS, and performs several tests over the parser. | |
548 | m4_define([AT_CHECK_CALC_LALR], | |
549 | [AT_CHECK_CALC($@)]) | |
550 | ||
551 | AT_CHECK_CALC_LALR() | |
552 | ||
9e32add8 | 553 | AT_CHECK_CALC_LALR([%defines]) |
ae7453f2 | 554 | AT_CHECK_CALC_LALR([%locations]) |
9e32add8 AD |
555 | AT_CHECK_CALC_LALR([%name-prefix="calc"]) |
556 | AT_CHECK_CALC_LALR([%verbose]) | |
557 | AT_CHECK_CALC_LALR([%yacc]) | |
f50adbbd AD |
558 | AT_CHECK_CALC_LALR([%error-verbose]) |
559 | ||
ae7453f2 | 560 | AT_CHECK_CALC_LALR([%error-verbose %locations]) |
f50adbbd | 561 | |
9e32add8 | 562 | AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) |
f50adbbd AD |
563 | |
564 | AT_CHECK_CALC_LALR([%debug]) | |
9e32add8 | 565 | AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
c19988b7 | 566 | |
2a8d363a AD |
567 | AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
568 | ||
569 | 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 |
570 | |
571 | ||
572 | # ----------------------- # | |
573 | # Simple GLR Calculator. # | |
574 | # ----------------------- # | |
575 | ||
576 | AT_BANNER([[Simple GLR Calculator.]]) | |
577 | ||
578 | # AT_CHECK_CALC_GLR([BISON-OPTIONS]) | |
579 | # ---------------------------------- | |
580 | # Start a testing chunk which compiles `calc' grammar with | |
581 | # BISON-OPTIONS and %glr-parser, and performs several tests over the parser. | |
582 | m4_define([AT_CHECK_CALC_GLR], | |
ae7453f2 | 583 | [AT_CHECK_CALC([%glr-parser] $@)]) |
f50adbbd | 584 | |
bfb07874 | 585 | |
f50adbbd | 586 | AT_CHECK_CALC_GLR() |
bfb07874 | 587 | |
9e32add8 | 588 | AT_CHECK_CALC_GLR([%defines]) |
ae7453f2 | 589 | AT_CHECK_CALC_GLR([%locations]) |
9e32add8 AD |
590 | AT_CHECK_CALC_GLR([%name-prefix="calc"]) |
591 | AT_CHECK_CALC_GLR([%verbose]) | |
592 | AT_CHECK_CALC_GLR([%yacc]) | |
f50adbbd | 593 | AT_CHECK_CALC_GLR([%error-verbose]) |
bfb07874 | 594 | |
ae7453f2 | 595 | AT_CHECK_CALC_GLR([%error-verbose %locations]) |
bfb07874 | 596 | |
9e32add8 | 597 | AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) |
bfb07874 | 598 | |
f50adbbd | 599 | AT_CHECK_CALC_GLR([%debug]) |
9e32add8 | 600 | AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
21964f43 | 601 | |
2a8d363a AD |
602 | AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
603 | ||
604 | 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"]) |