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