]>
Commit | Line | Data |
---|---|---|
342b8b6e | 1 | # Checking the output filenames. -*- Autotest -*- |
7548fed2 | 2 | # Copyright (C) 2000, 2001, 2002, 2003 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 | |
7548fed2 | 58 | ]AT_LALR1_CC_IF([typedef yy::Location YYLTYPE;])[ |
bfb07874 AD |
59 | %} |
60 | ||
5a08f1ce | 61 | /* Exercise %union. */ |
213e640e AD |
62 | %union |
63 | { | |
e3aa2baa | 64 | value ival; |
213e640e AD |
65 | }; |
66 | ||
c19988b7 | 67 | %{ |
c19988b7 | 68 | static int power (int base, int exponent); |
d02b25f9 | 69 | ]AT_LALR1_CC_IF([], [ |
2a8d363a AD |
70 | /* yyerror receives the location if: |
71 | - %location & %pure & %glr | |
72 | - %location & %pure & %yacc & %parse-param. */ | |
d02b25f9 AD |
73 | static void yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ]) |
74 | AT_PARAM_IF([value *result, int *count, ]) | |
93724f13 | 75 | const char *s |
d02b25f9 | 76 | );])[ |
7548fed2 AD |
77 | static int yylex (]AT_LEX_FORMALS[); |
78 | static int yygetc (]AT_LEX_FORMALS[); | |
79 | static void yyungetc (]AT_LEX_PRE_FORMALS[ int c); | |
c19988b7 AD |
80 | %} |
81 | ||
6b7e85b9 | 82 | /* Bison Declarations */ |
c19988b7 | 83 | %token CALC_EOF 0 "end of input" |
213e640e AD |
84 | %token <ival> NUM "number" |
85 | %type <ival> exp | |
bfb07874 AD |
86 | |
87 | %nonassoc '=' /* comparison */ | |
88 | %left '-' '+' | |
89 | %left '*' '/' | |
90 | %left NEG /* negation--unary minus */ | |
91 | %right '^' /* exponentiation */ | |
92 | ||
93 | /* Grammar follows */ | |
94 | %% | |
95 | input: | |
b7c49edf | 96 | line |
2a8d363a | 97 | | input line { ]AT_PARAM_IF([++*count; ++global_count;])[ } |
bfb07874 AD |
98 | ; |
99 | ||
100 | line: | |
c19988b7 | 101 | '\n' |
2a8d363a | 102 | | exp '\n' { ]AT_PARAM_IF([*result = global_result = $1;])[ } |
bfb07874 AD |
103 | ; |
104 | ||
105 | exp: | |
106 | NUM { $$ = $1; } | |
107 | | exp '=' exp | |
108 | { | |
2a8d363a AD |
109 | if ($1 != $3) |
110 | fprintf (stderr, "calc: error: %d != %d\n", $1, $3); | |
111 | $$ = $1; | |
bfb07874 AD |
112 | } |
113 | | exp '+' exp { $$ = $1 + $3; } | |
114 | | exp '-' exp { $$ = $1 - $3; } | |
115 | | exp '*' exp { $$ = $1 * $3; } | |
116 | | exp '/' exp { $$ = $1 / $3; } | |
117 | | '-' exp %prec NEG { $$ = -$2; } | |
118 | | exp '^' exp { $$ = power ($1, $3); } | |
119 | | '(' exp ')' { $$ = $2; } | |
0b86fc41 AD |
120 | | '(' error ')' { $$ = 1111; } |
121 | | '!' { YYERROR; } | |
bfb07874 AD |
122 | ; |
123 | %% | |
124 | /* The input. */ | |
4e8c79eb | 125 | static FILE *yyin; |
bfb07874 | 126 | |
7548fed2 AD |
127 | ]AT_LALR1_CC_IF( |
128 | [/* Currently, print_ is required in C++. */ | |
129 | void | |
130 | yy::Parser::print_ () | |
bfb07874 | 131 | { |
d02b25f9 AD |
132 | AT_LOCATION_IF([ |
133 | std::cerr << location;]) | |
bfb07874 AD |
134 | } |
135 | ||
7548fed2 AD |
136 | /* A C++ error reporting function. */ |
137 | void | |
138 | yy::Parser::error_ () | |
139 | { | |
d02b25f9 | 140 | std::cerr << AT_LOCATION_IF([location << ": " << ])message << std::endl; |
7548fed2 AD |
141 | } |
142 | ||
143 | int | |
144 | yyparse (void) | |
145 | { | |
146 | yy::Parser parser = yy::Parser (!!YYDEBUG[]AT_LOCATION_IF([, | |
147 | yy::Location::Location ()])); | |
148 | return parser.parse (); | |
149 | } | |
150 | ], | |
151 | [static void | |
152 | yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *yylloc, ]) | |
153 | AT_PARAM_IF([value *result, int *count, ]) | |
154 | const char *s) | |
155 | { | |
156 | AT_PARAM_IF([(void) result; (void) count;]) | |
157 | AT_YYERROR_SEES_LOC_IF([ | |
158 | fprintf (stderr, "%d.%d", | |
159 | AT_LOC.first_line, AT_LOC.first_column); | |
160 | if (AT_LOC.first_line != AT_LOC.last_line) | |
161 | fprintf (stderr, "-%d.%d", | |
162 | AT_LOC.last_line, AT_LOC.last_column - 1); | |
163 | else if (AT_LOC.first_column != AT_LOC.last_column - 1) | |
164 | fprintf (stderr, "-%d", | |
165 | AT_LOC.last_column - 1); | |
166 | fprintf (stderr, ": ");]) | |
167 | fprintf (stderr, "%s\n", s); | |
168 | }])[ | |
169 | ||
b7c49edf | 170 | |
2a8d363a | 171 | ]AT_LOCATION_IF([ |
b7c49edf | 172 | static YYLTYPE last_yylloc; |
2a8d363a | 173 | ])[ |
bfb07874 | 174 | static int |
7548fed2 | 175 | yygetc (]AT_LEX_FORMALS[) |
bfb07874 AD |
176 | { |
177 | int res = getc (yyin); | |
7548fed2 | 178 | ]AT_USE_LEX_ARGS[; |
2a8d363a | 179 | ]AT_LOCATION_IF([ |
7548fed2 | 180 | last_yylloc = AT_LOC; |
bfb07874 AD |
181 | if (res == '\n') |
182 | { | |
7548fed2 AD |
183 | AT_LALR1_CC_IF( |
184 | [ AT_LOC.end.line++; | |
185 | AT_LOC.end.column = 0;], | |
186 | [ AT_LOC.last_line++; | |
187 | AT_LOC.last_column = 0;]) | |
bfb07874 AD |
188 | } |
189 | else | |
7548fed2 AD |
190 | AT_LALR1_CC_IF( |
191 | [ AT_LOC.end.column++;], | |
192 | [ AT_LOC.last_column++;]) | |
2a8d363a | 193 | ])[ |
bfb07874 AD |
194 | return res; |
195 | } | |
196 | ||
197 | ||
198 | static void | |
7548fed2 | 199 | yyungetc (]AT_LEX_PRE_FORMALS[ int c) |
bfb07874 | 200 | { |
7548fed2 | 201 | ]AT_USE_LEX_ARGS[; |
2a8d363a | 202 | ]AT_LOCATION_IF([ |
bfb07874 | 203 | /* Wrong when C == `\n'. */ |
7548fed2 | 204 | AT_LOC = last_yylloc; |
2a8d363a | 205 | ])[ |
bfb07874 AD |
206 | ungetc (c, yyin); |
207 | } | |
208 | ||
209 | static int | |
7548fed2 | 210 | read_signed_integer (]AT_LEX_FORMALS[) |
bfb07874 | 211 | { |
7548fed2 | 212 | int c = yygetc (]AT_LEX_ARGS[); |
bfb07874 AD |
213 | int sign = 1; |
214 | int n = 0; | |
215 | ||
7548fed2 | 216 | ]AT_USE_LEX_ARGS[; |
bfb07874 AD |
217 | if (c == '-') |
218 | { | |
7548fed2 | 219 | c = yygetc (]AT_LEX_ARGS[); |
bfb07874 AD |
220 | sign = -1; |
221 | } | |
222 | ||
223 | while (isdigit (c)) | |
224 | { | |
225 | n = 10 * n + (c - '0'); | |
7548fed2 | 226 | c = yygetc (]AT_LEX_ARGS[); |
bfb07874 AD |
227 | } |
228 | ||
7548fed2 | 229 | yyungetc (]AT_LEX_PRE_ARGS[ c); |
bfb07874 AD |
230 | |
231 | return sign * n; | |
232 | } | |
233 | ||
234 | ||
235 | ||
236 | /*---------------------------------------------------------------. | |
237 | | Lexical analyzer returns an integer on the stack and the token | | |
238 | | NUM, or the ASCII character read if not a number. Skips all | | |
239 | | blanks and tabs, returns 0 for EOF. | | |
240 | `---------------------------------------------------------------*/ | |
241 | ||
242 | static int | |
7548fed2 | 243 | yylex (]AT_LEX_FORMALS[) |
bfb07874 | 244 | { |
c19988b7 | 245 | static int init = 1; |
bfb07874 AD |
246 | int c; |
247 | ||
c19988b7 AD |
248 | if (init) |
249 | { | |
250 | init = 0; | |
7548fed2 AD |
251 | ]AT_LALR1_CC_IF([], |
252 | [AT_LOCATION_IF([ | |
253 | AT_LOC.last_column = 0; | |
254 | AT_LOC.last_line = 1; | |
255 | ])])[ | |
c19988b7 AD |
256 | } |
257 | ||
d02b25f9 | 258 | ]AT_LOCATION_IF([AT_LALR1_CC_IF( |
7548fed2 | 259 | [ AT_LOC.begin = AT_LOC.end;], |
d02b25f9 | 260 | [ AT_LOC.first_column = AT_LOC.last_column; |
7548fed2 AD |
261 | AT_LOC.first_line = AT_LOC.last_line; |
262 | ])])[ | |
bfb07874 AD |
263 | |
264 | /* Skip white space. */ | |
7548fed2 | 265 | while ((c = yygetc (]AT_LEX_ARGS[)) == ' ' || c == '\t') |
bfb07874 | 266 | { |
d02b25f9 | 267 | ]AT_LOCATION_IF([AT_LALR1_CC_IF( |
7548fed2 | 268 | [ AT_LOC.begin = AT_LOC.end;], |
d02b25f9 | 269 | [ AT_LOC.first_column = AT_LOC.last_column; |
7548fed2 AD |
270 | AT_LOC.first_line = AT_LOC.last_line; |
271 | ])])[ | |
bfb07874 AD |
272 | } |
273 | ||
274 | /* process numbers */ | |
275 | if (c == '.' || isdigit (c)) | |
276 | { | |
7548fed2 AD |
277 | yyungetc (]AT_LEX_PRE_ARGS[ c); |
278 | ]AT_VAL[.ival = read_signed_integer (]AT_LEX_ARGS[); | |
bfb07874 AD |
279 | return NUM; |
280 | } | |
281 | ||
282 | /* Return end-of-file. */ | |
283 | if (c == EOF) | |
6b7e85b9 | 284 | return CALC_EOF; |
bfb07874 AD |
285 | |
286 | /* Return single chars. */ | |
287 | return c; | |
288 | } | |
289 | ||
290 | static int | |
291 | power (int base, int exponent) | |
292 | { | |
293 | int res = 1; | |
294 | if (exponent < 0) | |
295 | exit (1); | |
296 | for (/* Niente */; exponent; --exponent) | |
297 | res *= base; | |
298 | return res; | |
299 | } | |
300 | ||
7548fed2 | 301 | |
bfb07874 | 302 | int |
342b8b6e | 303 | main (int argc, const char **argv) |
bfb07874 | 304 | { |
e3aa2baa | 305 | value result = 0; |
e7cb57c0 | 306 | int count = 0; |
4e8c79eb | 307 | int status; |
342b8b6e AD |
308 | |
309 | if (argc == 2) | |
bfb07874 AD |
310 | yyin = fopen (argv[1], "r"); |
311 | else | |
312 | yyin = stdin; | |
313 | ||
342b8b6e | 314 | if (!yyin) |
bfb07874 AD |
315 | { |
316 | perror (argv[1]); | |
317 | exit (1); | |
318 | } | |
319 | ||
d02b25f9 AD |
320 | ]AT_LALR1_CC_IF([], [m4_bmatch([$4], [%debug], |
321 | [ yydebug = 1;])])[ | |
b0f98b10 | 322 | status = yyparse (]AT_PARAM_IF([&result, &count])[); |
63d0fb9c PE |
323 | if (global_result != result) |
324 | abort (); | |
325 | if (global_count != count) | |
326 | abort (); | |
b0f98b10 | 327 | return status; |
bfb07874 AD |
328 | } |
329 | ]]) | |
330 | ])# _AT_DATA_CALC_Y | |
331 | ||
332 | ||
333 | # AT_DATA_CALC_Y([BISON-OPTIONS]) | |
334 | # ------------------------------- | |
335 | # Produce `calc.y'. | |
342b8b6e | 336 | m4_define([AT_DATA_CALC_Y], |
9e32add8 | 337 | [_AT_DATA_CALC_Y($[1], $[2], $[3], [$1]) |
f50adbbd | 338 | ]) |
bfb07874 AD |
339 | |
340 | ||
341 | ||
342b8b6e AD |
342 | # _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES = 0]) |
343 | # ------------------------------------------------------------ | |
bfb07874 | 344 | # Run `calc' on INPUT and expect no STDOUT nor STDERR. |
342b8b6e | 345 | # |
f50adbbd AD |
346 | # If BISON-OPTIONS contains `%debug' but not `%glr-parser', then |
347 | # NUM-STDERR-LINES is the number of expected lines on stderr. | |
348 | # | |
349 | # We don't count GLR's traces yet, since its traces are somewhat | |
350 | # different from LALR's. | |
342b8b6e AD |
351 | m4_define([_AT_CHECK_CALC], |
352 | [AT_DATA([[input]], | |
353 | [[$2 | |
354 | ]]) | |
f50adbbd AD |
355 | AT_PARSER_CHECK([./calc input], 0, [], [stderr]) |
356 | m4_bmatch([$1], | |
357 | [%debug.*%glr\|%glr.*%debug], | |
358 | [], | |
359 | [%debug], | |
360 | [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$3 | |
361 | ])]) | |
342b8b6e AD |
362 | ]) |
363 | ||
364 | ||
b0f98b10 AD |
365 | # _AT_CHECK_CALC_ERROR(BISON-OPTIONS, EXIT-STATUS, INPUT, |
366 | # [NUM-DEBUG-LINES], | |
2a8d363a | 367 | # [VERBOSE-AND-LOCATED-ERROR-MESSAGE]) |
b0f98b10 | 368 | # --------------------------------------------------------- |
6e649e65 | 369 | # Run `calc' on INPUT, and expect a `syntax error' message. |
342b8b6e | 370 | # |
b7c49edf AD |
371 | # If INPUT starts with a slash, it is used as absolute input file name, |
372 | # otherwise as contents. | |
373 | # | |
9e32add8 | 374 | # If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION |
342b8b6e AD |
375 | # is correctly output on stderr. |
376 | # | |
f50adbbd | 377 | # If BISON-OPTIONS contains `%error-verbose', then make sure the |
6e649e65 | 378 | # IF-YYERROR-VERBOSE message is properly output after `syntax error, ' |
342b8b6e AD |
379 | # on STDERR. |
380 | # | |
f50adbbd AD |
381 | # If BISON-OPTIONS contains `%debug' but not `%glr', then NUM-STDERR-LINES |
382 | # is the number of expected lines on stderr. | |
342b8b6e | 383 | m4_define([_AT_CHECK_CALC_ERROR], |
b0f98b10 AD |
384 | [m4_bmatch([$3], [^/], |
385 | [AT_PARSER_CHECK([./calc $3], $2, [], [stderr])], | |
b7c49edf | 386 | [AT_DATA([[input]], |
b0f98b10 | 387 | [[$3 |
342b8b6e | 388 | ]]) |
b0f98b10 | 389 | AT_PARSER_CHECK([./calc input], $2, [], [stderr])]) |
f50adbbd AD |
390 | m4_bmatch([$1], |
391 | [%debug.*%glr\|%glr.*%debug], | |
392 | [], | |
393 | [%debug], | |
b0f98b10 | 394 | [AT_CHECK([wc -l <stderr | sed 's/[[^0-9]]//g'], 0, [$4 |
51dec47b | 395 | ])]) |
342b8b6e | 396 | |
51dec47b AD |
397 | # Normalize the observed and expected error messages, depending upon the |
398 | # options. | |
399 | # 1. Remove the traces from observed. | |
9280d3ef AD |
400 | sed '/^Starting/d |
401 | /^Entering/d | |
f50adbbd | 402 | /^Stack/d |
9280d3ef AD |
403 | /^Reading/d |
404 | /^Reducing/d | |
405 | /^Shifting/d | |
406 | /^state/d | |
407 | /^Error:/d | |
408 | /^Next/d | |
409 | /^Discarding/d | |
410 | /^yydestructor:/d' stderr >at-stderr | |
342b8b6e | 411 | mv at-stderr stderr |
51dec47b AD |
412 | # 2. Create the reference error message. |
413 | AT_DATA([[expout]], | |
b0f98b10 | 414 | [$5 |
342b8b6e | 415 | ]) |
51dec47b | 416 | # 3. If locations are not used, remove them. |
2a8d363a | 417 | AT_YYERROR_SEES_LOC_IF([], |
51dec47b AD |
418 | [[sed 's/^[-0-9.]*: //' expout >at-expout |
419 | mv at-expout expout]]) | |
420 | # 4. If error-verbose is not used, strip the`, unexpected....' part. | |
f50adbbd | 421 | m4_bmatch([$1], [%error-verbose], [], |
6e649e65 | 422 | [[sed 's/syntax error, .*$/syntax error/' expout >at-expout |
51dec47b AD |
423 | mv at-expout expout]]) |
424 | # 5. Check | |
425 | AT_CHECK([cat stderr], 0, [expout]) | |
342b8b6e | 426 | ]) |
bfb07874 AD |
427 | |
428 | ||
2a8d363a AD |
429 | # AT_CALC_PUSHDEFS($1, $2, [BISON-OPTIONS]) |
430 | # ----------------------------------------- | |
431 | # This macro works around the impossibility to define macros | |
432 | # inside macros, because issuing `[$1]' is not possible in M4 :(. | |
433 | # This sucks hard, GNU M4 should really provide M5 like $$1. | |
434 | m4_define([AT_CHECK_PUSHDEFS], | |
435 | [m4_if([$1$2], $[1]$[2], [], | |
436 | [m4_fatal([$0: Invalid arguments: $@])])dnl | |
7548fed2 AD |
437 | m4_pushdef([AT_LALR1_CC_IF], |
438 | [m4_bmatch([$3], ["lalr1.cc"], [$1], [$2])]) | |
439 | m4_pushdef([AT_GLR_IF], | |
440 | [m4_bmatch([$3], [%glr-parser], [$1], [$2])]) | |
d02b25f9 AD |
441 | # Using yacc.c? |
442 | m4_pushdef([AT_YACC_IF], | |
443 | [m4_bmatch([$3], [%glr-parser\|%skeleton], [$2], [$1])]) | |
2a8d363a AD |
444 | m4_pushdef([AT_PARAM_IF], |
445 | [m4_bmatch([$3], [%parse-param], [$1], [$2])]) | |
446 | m4_pushdef([AT_LOCATION_IF], | |
447 | [m4_bmatch([$3], [%locations], [$1], [$2])]) | |
448 | m4_pushdef([AT_PURE_IF], | |
449 | [m4_bmatch([$3], [%pure-parser], [$1], [$2])]) | |
2a8d363a AD |
450 | m4_pushdef([AT_PURE_AND_LOC_IF], |
451 | [m4_bmatch([$3], [%locations.*%pure-parser\|%pure-parser.*%locations], | |
452 | [$1], [$2])]) | |
453 | m4_pushdef([AT_GLR_OR_PARAM_IF], | |
454 | [m4_bmatch([$3], [%glr-parser\|%parse-param], [$1], [$2])]) | |
455 | ||
456 | # yyerror receives the location if %location & %pure & (%glr or %parse-param). | |
457 | m4_pushdef([AT_YYERROR_ARG_LOC_IF], | |
458 | [AT_GLR_OR_PARAM_IF([AT_PURE_AND_LOC_IF([$1], [$2])], | |
459 | [$2])]) | |
d02b25f9 AD |
460 | # yyerror always sees the locations (when activated), except if |
461 | # yacc & pure & !param. | |
2a8d363a | 462 | m4_pushdef([AT_YYERROR_SEES_LOC_IF], |
d02b25f9 AD |
463 | [AT_LOCATION_IF([AT_YACC_IF([AT_PURE_IF([AT_PARAM_IF([$1], [$2])], |
464 | [$1])], | |
465 | [$1])], | |
466 | [$2])]) | |
7548fed2 AD |
467 | |
468 | # The interface is pure: either because %pure-parser, or because we | |
469 | # are using the C++ parsers. | |
470 | m4_pushdef([AT_PURE_LEX_IF], | |
471 | [AT_PURE_IF([$1], | |
472 | [AT_LALR1_CC_IF([$1], [$2])])]) | |
473 | ||
474 | AT_PURE_LEX_IF( | |
475 | [m4_pushdef([AT_LOC], [(*yylloc)]) | |
476 | m4_pushdef([AT_VAL], [(*yylval)]) | |
477 | m4_pushdef([AT_LEX_FORMALS], | |
478 | [YYSTYPE *yylval[]AT_LOCATION_IF([, YYLTYPE *yylloc])]) | |
479 | m4_pushdef([AT_LEX_ARGS], | |
480 | [yylval[]AT_LOCATION_IF([, yylloc])]) | |
481 | m4_pushdef([AT_USE_LEX_ARGS], | |
482 | [(void) yylval;AT_LOCATION_IF([(void) yylloc])]) | |
483 | m4_pushdef([AT_LEX_PRE_FORMALS], | |
484 | [AT_LEX_FORMALS, ]) | |
485 | m4_pushdef([AT_LEX_PRE_ARGS], | |
486 | [AT_LEX_ARGS, ]) | |
487 | ], | |
488 | [m4_pushdef([AT_LOC], [(yylloc)]) | |
489 | m4_pushdef([AT_VAL], [(yylval)]) | |
490 | m4_pushdef([AT_LEX_FORMALS], [void]) | |
491 | m4_pushdef([AT_LEX_ARGS], []) | |
492 | m4_pushdef([AT_USE_LEX_ARGS], []) | |
493 | m4_pushdef([AT_LEX_PRE_FORMALS], []) | |
494 | m4_pushdef([AT_LEX_PRE_ARGS], []) | |
2a8d363a | 495 | ]) |
7548fed2 | 496 | ])# AT_CALC_PUSHDEFS |
2a8d363a AD |
497 | |
498 | ||
499 | # AT_CALC_POPDEFS | |
500 | # --------------- | |
501 | m4_define([AT_CHECK_POPDEFS], | |
7548fed2 AD |
502 | [m4_popdef([AT_LEX_PRE_ARGS]) |
503 | m4_popdef([AT_LEX_PRE_FORMALS]) | |
504 | m4_popdef([AT_USE_LEX_ARGS]) | |
505 | m4_popdef([AT_LEX_ARGS]) | |
506 | m4_popdef([AT_LEX_FORMALS]) | |
507 | m4_popdef([AT_VAL]) | |
508 | m4_popdef([AT_LOC]) | |
509 | m4_popdef([AT_PURE_LEX_IF]) | |
510 | m4_popdef([AT_YYERROR_SEES_LOC_IF]) | |
2a8d363a AD |
511 | m4_popdef([AT_YYERROR_ARG_LOC_IF]) |
512 | m4_popdef([AT_GLR_OR_PARAM_IF]) | |
513 | m4_popdef([AT_PURE_AND_LOC_IF]) | |
2a8d363a AD |
514 | m4_popdef([AT_LOCATION_IF]) |
515 | m4_popdef([AT_PARAM_IF]) | |
d02b25f9 | 516 | m4_popdef([AT_YACC_IF]) |
7548fed2 AD |
517 | m4_popdef([AT_GLR_IF]) |
518 | m4_popdef([AT_LALR1_CC_IF]) | |
2a8d363a AD |
519 | ]) |
520 | ||
521 | ||
522 | ||
f50adbbd AD |
523 | # AT_CHECK_CALC([BISON-OPTIONS]) |
524 | # ------------------------------ | |
bfb07874 AD |
525 | # Start a testing chunk which compiles `calc' grammar with |
526 | # BISON-OPTIONS, and performs several tests over the parser. | |
342b8b6e | 527 | m4_define([AT_CHECK_CALC], |
bfb07874 AD |
528 | [# We use integers to avoid dependencies upon the precision of doubles. |
529 | AT_SETUP([Calculator $1]) | |
530 | ||
2a8d363a AD |
531 | AT_CHECK_PUSHDEFS($[1], $[2], [$1]) |
532 | ||
bfb07874 AD |
533 | AT_DATA_CALC_Y([$1]) |
534 | ||
535 | # Specify the output files to avoid problems on different file systems. | |
9e32add8 | 536 | AT_CHECK([bison -o calc.c calc.y], |
bfb07874 | 537 | [0], [], []) |
3c1a79b3 | 538 | |
7548fed2 AD |
539 | AT_LALR1_CC_IF( |
540 | [AT_CHECK([$CXX --version || exit 77], 0, ignore, ignore) | |
541 | AT_COMPILE_CXX([calc])], | |
542 | [AT_COMPILE([calc])]) | |
bfb07874 AD |
543 | |
544 | # Test the priorities. | |
545 | _AT_CHECK_CALC([$1], | |
546 | [1 + 2 * 3 = 7 | |
547 | 1 + 2 * -3 = -5 | |
548 | ||
549 | -1^2 = -1 | |
550 | (-1)^2 = 1 | |
551 | ||
552 | ---1 = -1 | |
553 | ||
554 | 1 - 2 - 3 = -4 | |
555 | 1 - (2 - 3) = 2 | |
556 | ||
557 | 2^2^3 = 256 | |
e7cb57c0 AD |
558 | (2^2)^3 = 64], |
559 | [486]) | |
bfb07874 | 560 | |
6e649e65 | 561 | # Some syntax errors. |
b0f98b10 | 562 | _AT_CHECK_CALC_ERROR([$1], [1], [0 0], [11], |
7548fed2 | 563 | [1.2: syntax error, unexpected "number"]) |
b0f98b10 | 564 | _AT_CHECK_CALC_ERROR([$1], [1], [1//2], [15], |
0b86fc41 | 565 | [1.2: syntax error, unexpected '/', expecting "number" or '-' or '(' or '!']) |
b0f98b10 | 566 | _AT_CHECK_CALC_ERROR([$1], [1], [error], [4], |
0b86fc41 | 567 | [1.0: syntax error, unexpected $undefined]) |
b0f98b10 | 568 | _AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [22], |
7548fed2 | 569 | [1.6: syntax error, unexpected '=']) |
b0f98b10 | 570 | _AT_CHECK_CALC_ERROR([$1], [1], |
bfb07874 AD |
571 | [ |
572 | +1], | |
366eea36 | 573 | [14], |
7548fed2 | 574 | [2.0: syntax error, unexpected '+']) |
b7c49edf | 575 | # Exercise error messages with EOF: work on an empty file. |
b0f98b10 | 576 | _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4], |
0b86fc41 | 577 | [1.0: syntax error, unexpected "end of input"]) |
51dec47b AD |
578 | |
579 | # Exercise the error token: without it, we die at the first error, | |
0b86fc41 AD |
580 | # hence be sure to |
581 | # | |
582 | # - have several errors which exercise different shift/discardings | |
583 | # - (): nothing to pop, nothing to discard | |
584 | # - (1 + 1 + 1 +): a lot to pop, nothing to discard | |
585 | # - (* * *): nothing to pop, a lot to discard | |
586 | # - (1 + 2 * *): some to pop and discard | |
587 | # | |
588 | # - test the action associated to `error' | |
589 | # | |
590 | # - check the lookahead that triggers an error is not discarded | |
591 | # when we enter error recovery. Below, the lookahead causing the | |
592 | # first error is ")", which is needed to recover from the error and | |
593 | # produce the "0" that triggers the "0 != 1" error. | |
594 | # | |
595 | _AT_CHECK_CALC_ERROR([$1], [0], | |
596 | [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1], | |
597 | [156], | |
598 | [1.1: syntax error, unexpected ')', expecting "number" or '-' or '(' or '!' | |
599 | 1.17: syntax error, unexpected ')', expecting "number" or '-' or '(' or '!' | |
600 | 1.22: syntax error, unexpected '*', expecting "number" or '-' or '(' or '!' | |
601 | 1.40: syntax error, unexpected '*', expecting "number" or '-' or '(' or '!' | |
602 | calc: error: 4444 != 1]) | |
603 | ||
604 | # The same, but this time exercising explicitly triggered syntax errors. | |
605 | # POSIX says the lookahead causing the error should not be discarded. | |
606 | _AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [64], | |
607 | [1.9: syntax error, unexpected "number" | |
608 | calc: error: 2222 != 1]) | |
2a8d363a AD |
609 | AT_CHECK_POPDEFS |
610 | ||
d803322e | 611 | AT_CLEANUP |
bfb07874 AD |
612 | ])# AT_CHECK_CALC |
613 | ||
614 | ||
615 | ||
616 | ||
f50adbbd AD |
617 | # ------------------------ # |
618 | # Simple LALR Calculator. # | |
619 | # ------------------------ # | |
620 | ||
621 | AT_BANNER([[Simple LALR Calculator.]]) | |
622 | ||
623 | # AT_CHECK_CALC_LALR([BISON-OPTIONS]) | |
624 | # ----------------------------------- | |
625 | # Start a testing chunk which compiles `calc' grammar with | |
626 | # BISON-OPTIONS, and performs several tests over the parser. | |
627 | m4_define([AT_CHECK_CALC_LALR], | |
628 | [AT_CHECK_CALC($@)]) | |
629 | ||
630 | AT_CHECK_CALC_LALR() | |
631 | ||
9e32add8 | 632 | AT_CHECK_CALC_LALR([%defines]) |
ae7453f2 | 633 | AT_CHECK_CALC_LALR([%locations]) |
9e32add8 AD |
634 | AT_CHECK_CALC_LALR([%name-prefix="calc"]) |
635 | AT_CHECK_CALC_LALR([%verbose]) | |
636 | AT_CHECK_CALC_LALR([%yacc]) | |
f50adbbd AD |
637 | AT_CHECK_CALC_LALR([%error-verbose]) |
638 | ||
ae7453f2 | 639 | AT_CHECK_CALC_LALR([%error-verbose %locations]) |
f50adbbd | 640 | |
9e32add8 | 641 | AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) |
f50adbbd AD |
642 | |
643 | AT_CHECK_CALC_LALR([%debug]) | |
9e32add8 | 644 | AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
c19988b7 | 645 | |
2a8d363a AD |
646 | AT_CHECK_CALC_LALR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
647 | ||
e3aa2baa | 648 | 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 |
649 | |
650 | ||
651 | # ----------------------- # | |
652 | # Simple GLR Calculator. # | |
653 | # ----------------------- # | |
654 | ||
655 | AT_BANNER([[Simple GLR Calculator.]]) | |
656 | ||
657 | # AT_CHECK_CALC_GLR([BISON-OPTIONS]) | |
658 | # ---------------------------------- | |
659 | # Start a testing chunk which compiles `calc' grammar with | |
660 | # BISON-OPTIONS and %glr-parser, and performs several tests over the parser. | |
661 | m4_define([AT_CHECK_CALC_GLR], | |
ae7453f2 | 662 | [AT_CHECK_CALC([%glr-parser] $@)]) |
f50adbbd | 663 | |
bfb07874 | 664 | |
f50adbbd | 665 | AT_CHECK_CALC_GLR() |
bfb07874 | 666 | |
9e32add8 | 667 | AT_CHECK_CALC_GLR([%defines]) |
ae7453f2 | 668 | AT_CHECK_CALC_GLR([%locations]) |
9e32add8 AD |
669 | AT_CHECK_CALC_GLR([%name-prefix="calc"]) |
670 | AT_CHECK_CALC_GLR([%verbose]) | |
671 | AT_CHECK_CALC_GLR([%yacc]) | |
f50adbbd | 672 | AT_CHECK_CALC_GLR([%error-verbose]) |
bfb07874 | 673 | |
ae7453f2 | 674 | AT_CHECK_CALC_GLR([%error-verbose %locations]) |
bfb07874 | 675 | |
9e32add8 | 676 | AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) |
bfb07874 | 677 | |
f50adbbd | 678 | AT_CHECK_CALC_GLR([%debug]) |
9e32add8 | 679 | AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
21964f43 | 680 | |
2a8d363a AD |
681 | AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
682 | ||
e3aa2baa | 683 | AT_CHECK_CALC_GLR([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}]) |
7548fed2 AD |
684 | |
685 | ||
686 | # ----------------------------- # | |
687 | # Simple LALR1 C++ Calculator. # | |
688 | # ----------------------------- # | |
689 | ||
690 | AT_BANNER([[Simple LALR1 C++ Calculator.]]) | |
691 | ||
692 | # AT_CHECK_CALC_LALR1_CC([BISON-OPTIONS]) | |
693 | # --------------------------------------- | |
694 | # Start a testing chunk which compiles `calc' grammar with | |
695 | # BISON-OPTIONS and %glr-parser, and performs several tests over the parser. | |
696 | m4_define([AT_CHECK_CALC_LALR1_CC], | |
697 | [AT_CHECK_CALC([%skeleton "lalr1.cc"] $@)]) | |
698 | ||
699 | # AT_CHECK_CALC_LALR1_CC() | |
700 | ||
d02b25f9 | 701 | AT_CHECK_CALC_LALR1_CC([%defines %locations]) |
0b86fc41 | 702 | |
d02b25f9 | 703 | AT_CHECK_CALC_LALR1_CC([%defines]) |
7548fed2 AD |
704 | # AT_CHECK_CALC_LALR1_CC([%locations]) |
705 | # AT_CHECK_CALC_LALR1_CC([%name-prefix="calc"]) | |
706 | # AT_CHECK_CALC_LALR1_CC([%verbose]) | |
707 | # AT_CHECK_CALC_LALR1_CC([%yacc]) | |
708 | # AT_CHECK_CALC_LALR1_CC([%error-verbose]) | |
709 | ||
710 | # AT_CHECK_CALC_LALR1_CC([%error-verbose %locations]) | |
711 | ||
d02b25f9 | 712 | AT_CHECK_CALC_LALR1_CC([%error-verbose %locations %defines %name-prefix="calc" %verbose %yacc]) |
7548fed2 AD |
713 | |
714 | # AT_CHECK_CALC_LALR1_CC([%debug]) | |
d02b25f9 | 715 | AT_CHECK_CALC_LALR1_CC([%error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
7548fed2 | 716 | |
d02b25f9 | 717 | AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc]) |
7548fed2 AD |
718 | |
719 | # AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %locations %defines %name-prefix="calc" %verbose %yacc %parse-param {value *result} %parse-param {int *count}]) |