]> git.saurik.com Git - bison.git/blame - tests/calc.at
Partial m4sugar merge from autoconf: m4_map.
[bison.git] / tests / calc.at
CommitLineData
82c53be4 1# Simple calculator. -*- Autotest -*-
419ab105 2
279cabb6 3# Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007 Free Software
419ab105 4# Foundation, Inc.
bfb07874 5
f16b0819 6# This program is free software: you can redistribute it and/or modify
342b8b6e 7# it under the terms of the GNU General Public License as published by
f16b0819
PE
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
342b8b6e
AD
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
f16b0819 15#
342b8b6e 16# You should have received a copy of the GNU General Public License
f16b0819 17# along with this program. If not, see <http://www.gnu.org/licenses/>.
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
35m4_define([_AT_DATA_CALC_Y],
36[m4_if([$1$2$3], $[1]$[2]$[3], [],
37 [m4_fatal([$0: Invalid arguments: $@])])dnl
9501dc6e 38AT_DATA_GRAMMAR([calc.y],
bfb07874 39[[/* Infix notation calculator--calc */
fb9712a9 40]$4
8f7e3cf9 41AT_SKEL_CC_IF(
16dc6a9e 42[%define global_tokens_and_yystype])[
bfb07874
AD
43%{
44#include <stdio.h>
2ce10144 45
6e26ca8c
PE
46#include <stdlib.h>
47#include <string.h>
82c53be4
PE
48#if HAVE_UNISTD_H
49# include <unistd.h>
50#else
51# undef alarm
52# define alarm(seconds) /* empty */
53#endif
bfb07874 54#include <ctype.h>
affac613 55#define USE(Var)
bfb07874 56
0dd1580a 57/* Exercise pre-prologue dependency to %union. */
caf37a36 58typedef int semantic_value;
0dd1580a 59
caf37a36 60static semantic_value global_result = 0;
4e8c79eb 61static int global_count = 0;
bfb07874
AD
62%}
63
5a08f1ce 64/* Exercise %union. */
213e640e
AD
65%union
66{
caf37a36 67 semantic_value ival;
213e640e
AD
68};
69
c19988b7 70%{
c19988b7 71static int power (int base, int exponent);
8f7e3cf9
AD
72]AT_SKEL_CC_IF(
73[#ifndef YYLTYPE
aa08666d 74[#] define YYLTYPE AT_NAME_PREFIX::location
8f7e3cf9 75#endif
fb9712a9
AD
76#define first_line begin.line
77#define first_column begin.column
78#define last_line end.line
79#define last_column end.column
80],
67a25fed 81[/* yyerror receives the location if:
2a8d363a
AD
82 - %location & %pure & %glr
83 - %location & %pure & %yacc & %parse-param. */
ebc3737e 84static void yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])
caf37a36 85 AT_PARAM_IF([semantic_value *result, int *count, ])
93724f13 86 const char *s
d02b25f9 87 );])[
7548fed2 88static int yylex (]AT_LEX_FORMALS[);
a9739e7c
PE
89static int get_char (]AT_LEX_FORMALS[);
90static void unget_char (]AT_LEX_PRE_FORMALS[ int c);
c19988b7
AD
91%}
92
8f7e3cf9
AD
93]AT_SKEL_CC_IF(
94[/* The lalr1.cc skeleton, for backward compatibility, defines
95 a constructor for position that initializes the filename. The
96 glr.cc skeleton does not (and in fact cannot: location/position
97 are stored in a union, from which objects with constructors are
98 excluded in C++. */
99%initial-action {
ed94ef2a 100 @$.initialize (0);
8f7e3cf9
AD
101}
102])[
103
6b7e85b9 104/* Bison Declarations */
c19988b7 105%token CALC_EOF 0 "end of input"
213e640e
AD
106%token <ival> NUM "number"
107%type <ival> exp
bfb07874
AD
108
109%nonassoc '=' /* comparison */
110%left '-' '+'
111%left '*' '/'
112%left NEG /* negation--unary minus */
113%right '^' /* exponentiation */
114
115/* Grammar follows */
116%%
117input:
b7c49edf 118 line
2a8d363a 119| input line { ]AT_PARAM_IF([++*count; ++global_count;])[ }
bfb07874
AD
120;
121
122line:
c19988b7 123 '\n'
affac613 124| exp '\n' { ]AT_PARAM_IF([*result = global_result = $1], [USE ($1)])[; }
bfb07874
AD
125;
126
127exp:
128 NUM { $$ = $1; }
129| exp '=' exp
130 {
2a8d363a
AD
131 if ($1 != $3)
132 fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
133 $$ = $1;
bfb07874
AD
134 }
135| exp '+' exp { $$ = $1 + $3; }
136| exp '-' exp { $$ = $1 - $3; }
137| exp '*' exp { $$ = $1 * $3; }
138| exp '/' exp { $$ = $1 / $3; }
139| '-' exp %prec NEG { $$ = -$2; }
140| exp '^' exp { $$ = power ($1, $3); }
141| '(' exp ')' { $$ = $2; }
0b86fc41 142| '(' error ')' { $$ = 1111; }
8f3596a6
AD
143| '!' { $$ = 0; YYERROR; }
144| '-' error { $$ = 0; YYERROR; }
bfb07874
AD
145;
146%%
8f3596a6 147/* The input. */
a9739e7c 148static FILE *input;
bfb07874 149
8f7e3cf9 150]AT_SKEL_CC_IF(
8f3596a6 151[/* A C++ error reporting function. */
7548fed2 152void
aa08666d 153AT_NAME_PREFIX::parser::error (const location& l, const std::string& m)
7548fed2 154{
efeed023
AD
155 (void) l;
156 std::cerr << AT_LOCATION_IF([l << ": " << ])m << std::endl;
7548fed2
AD
157}
158
159int
caf37a36 160yyparse (AT_PARAM_IF([semantic_value *result, int *count]))
7548fed2 161{
aa08666d 162 AT_NAME_PREFIX::parser parser[]AT_PARAM_IF([ (result, count)]);
fa7b79c0
PE
163#if YYDEBUG
164 parser.set_debug_level (1);
165#endif
7548fed2
AD
166 return parser.parse ();
167}
168],
169[static void
ebc3737e 170yyerror (AT_YYERROR_ARG_LOC_IF([YYLTYPE *llocp, ])
caf37a36 171 AT_PARAM_IF([semantic_value *result, int *count, ])
7548fed2
AD
172 const char *s)
173{
174AT_PARAM_IF([(void) result; (void) count;])
175AT_YYERROR_SEES_LOC_IF([
176 fprintf (stderr, "%d.%d",
177 AT_LOC.first_line, AT_LOC.first_column);
178 if (AT_LOC.first_line != AT_LOC.last_line)
179 fprintf (stderr, "-%d.%d",
180 AT_LOC.last_line, AT_LOC.last_column - 1);
181 else if (AT_LOC.first_column != AT_LOC.last_column - 1)
182 fprintf (stderr, "-%d",
183 AT_LOC.last_column - 1);
184 fprintf (stderr, ": ");])
185 fprintf (stderr, "%s\n", s);
186}])[
187
b7c49edf 188
2a8d363a 189]AT_LOCATION_IF([
b7c49edf 190static YYLTYPE last_yylloc;
2a8d363a 191])[
bfb07874 192static int
a9739e7c 193get_char (]AT_LEX_FORMALS[)
bfb07874 194{
a9739e7c 195 int res = getc (input);
7548fed2 196 ]AT_USE_LEX_ARGS[;
2a8d363a 197]AT_LOCATION_IF([
7548fed2 198 last_yylloc = AT_LOC;
bfb07874
AD
199 if (res == '\n')
200 {
fb9712a9 201 AT_LOC.last_line++;
cd48d21d 202 AT_LOC.last_column = 1;
bfb07874
AD
203 }
204 else
fb9712a9 205 AT_LOC.last_column++;
2a8d363a 206])[
bfb07874
AD
207 return res;
208}
209
210
211static void
a9739e7c 212unget_char (]AT_LEX_PRE_FORMALS[ int c)
bfb07874 213{
7548fed2 214 ]AT_USE_LEX_ARGS[;
2a8d363a 215]AT_LOCATION_IF([
bfb07874 216 /* Wrong when C == `\n'. */
7548fed2 217 AT_LOC = last_yylloc;
2a8d363a 218])[
a9739e7c 219 ungetc (c, input);
bfb07874
AD
220}
221
222static int
7548fed2 223read_signed_integer (]AT_LEX_FORMALS[)
bfb07874 224{
a9739e7c 225 int c = get_char (]AT_LEX_ARGS[);
bfb07874
AD
226 int sign = 1;
227 int n = 0;
228
7548fed2 229 ]AT_USE_LEX_ARGS[;
bfb07874
AD
230 if (c == '-')
231 {
a9739e7c 232 c = get_char (]AT_LEX_ARGS[);
bfb07874
AD
233 sign = -1;
234 }
235
236 while (isdigit (c))
237 {
238 n = 10 * n + (c - '0');
a9739e7c 239 c = get_char (]AT_LEX_ARGS[);
bfb07874
AD
240 }
241
a9739e7c 242 unget_char (]AT_LEX_PRE_ARGS[ c);
bfb07874
AD
243
244 return sign * n;
245}
246
247
248
249/*---------------------------------------------------------------.
250| Lexical analyzer returns an integer on the stack and the token |
251| NUM, or the ASCII character read if not a number. Skips all |
252| blanks and tabs, returns 0 for EOF. |
253`---------------------------------------------------------------*/
254
255static int
7548fed2 256yylex (]AT_LEX_FORMALS[)
bfb07874 257{
c19988b7 258 static int init = 1;
bfb07874
AD
259 int c;
260
c19988b7
AD
261 if (init)
262 {
263 init = 0;
fb9712a9 264]AT_LOCATION_IF([
cd48d21d 265 AT_LOC.last_column = 1;
7548fed2 266 AT_LOC.last_line = 1;
fb9712a9 267])[
c19988b7
AD
268 }
269
fb9712a9
AD
270]AT_LOCATION_IF([
271 AT_LOC.first_column = AT_LOC.last_column;
7548fed2 272 AT_LOC.first_line = AT_LOC.last_line;
fb9712a9 273])[
bfb07874
AD
274
275 /* Skip white space. */
a9739e7c 276 while ((c = get_char (]AT_LEX_ARGS[)) == ' ' || c == '\t')
bfb07874 277 {
fb9712a9 278]AT_LOCATION_IF(
d02b25f9 279[ AT_LOC.first_column = AT_LOC.last_column;
7548fed2 280 AT_LOC.first_line = AT_LOC.last_line;
fb9712a9 281])[
bfb07874
AD
282 }
283
284 /* process numbers */
285 if (c == '.' || isdigit (c))
286 {
a9739e7c 287 unget_char (]AT_LEX_PRE_ARGS[ c);
7548fed2 288 ]AT_VAL[.ival = read_signed_integer (]AT_LEX_ARGS[);
bfb07874
AD
289 return NUM;
290 }
291
292 /* Return end-of-file. */
293 if (c == EOF)
6b7e85b9 294 return CALC_EOF;
bfb07874
AD
295
296 /* Return single chars. */
297 return c;
298}
299
300static int
301power (int base, int exponent)
302{
303 int res = 1;
304 if (exponent < 0)
6100a9aa 305 exit (3);
bfb07874
AD
306 for (/* Niente */; exponent; --exponent)
307 res *= base;
308 return res;
309}
310
7548fed2 311
bfb07874 312int
342b8b6e 313main (int argc, const char **argv)
bfb07874 314{
caf37a36 315 semantic_value result = 0;
e7cb57c0 316 int count = 0;
4e8c79eb 317 int status;
342b8b6e 318
419ab105
PE
319 /* This used to be alarm (10), but that isn't enough time for
320 a July 1995 vintage DEC Alphastation 200 4/100 system,
321 according to Nelson H. F. Beebe. 100 seconds is enough. */
322 alarm (100);
323
342b8b6e 324 if (argc == 2)
a9739e7c 325 input = fopen (argv[1], "r");
bfb07874 326 else
a9739e7c 327 input = stdin;
bfb07874 328
a9739e7c 329 if (!input)
bfb07874
AD
330 {
331 perror (argv[1]);
6100a9aa 332 return 3;
bfb07874
AD
333 }
334
8f7e3cf9 335]AT_SKEL_CC_IF([], [m4_bmatch([$4], [%debug],
d02b25f9 336[ yydebug = 1;])])[
c3d50342 337 status = yyparse (]AT_PARAM_IF([[&result, &count]])[);
eb095650 338 fclose (input);
63d0fb9c
PE
339 if (global_result != result)
340 abort ();
341 if (global_count != count)
342 abort ();
b0f98b10 343 return status;
bfb07874
AD
344}
345]])
346])# _AT_DATA_CALC_Y
347
348
349# AT_DATA_CALC_Y([BISON-OPTIONS])
350# -------------------------------
351# Produce `calc.y'.
342b8b6e 352m4_define([AT_DATA_CALC_Y],
9e32add8 353[_AT_DATA_CALC_Y($[1], $[2], $[3], [$1])
f50adbbd 354])
bfb07874
AD
355
356
357
d9963c85
PE
358# _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES])
359# --------------------------------------------------------
bfb07874 360# Run `calc' on INPUT and expect no STDOUT nor STDERR.
342b8b6e 361#
f50adbbd 362# If BISON-OPTIONS contains `%debug' but not `%glr-parser', then
d9963c85 363#
f50adbbd 364# NUM-STDERR-LINES is the number of expected lines on stderr.
d9963c85 365# Currently this is ignored, though, since the output format is fluctuating.
f50adbbd
AD
366#
367# We don't count GLR's traces yet, since its traces are somewhat
368# different from LALR's.
342b8b6e
AD
369m4_define([_AT_CHECK_CALC],
370[AT_DATA([[input]],
371[[$2
372]])
f50adbbd 373AT_PARSER_CHECK([./calc input], 0, [], [stderr])
342b8b6e
AD
374])
375
376
b0f98b10 377# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, EXIT-STATUS, INPUT,
d9963c85 378# [NUM-STDERR-LINES],
2a8d363a 379# [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
b0f98b10 380# ---------------------------------------------------------
6e649e65 381# Run `calc' on INPUT, and expect a `syntax error' message.
342b8b6e 382#
b7c49edf
AD
383# If INPUT starts with a slash, it is used as absolute input file name,
384# otherwise as contents.
385#
d9963c85
PE
386# NUM-STDERR-LINES is the number of expected lines on stderr.
387# Currently this is ignored, though, since the output format is fluctuating.
388#
9e32add8 389# If BISON-OPTIONS contains `%location', then make sure the ERROR-LOCATION
342b8b6e
AD
390# is correctly output on stderr.
391#
f50adbbd 392# If BISON-OPTIONS contains `%error-verbose', then make sure the
6e649e65 393# IF-YYERROR-VERBOSE message is properly output after `syntax error, '
342b8b6e
AD
394# on STDERR.
395#
f50adbbd
AD
396# If BISON-OPTIONS contains `%debug' but not `%glr', then NUM-STDERR-LINES
397# is the number of expected lines on stderr.
342b8b6e 398m4_define([_AT_CHECK_CALC_ERROR],
b0f98b10
AD
399[m4_bmatch([$3], [^/],
400 [AT_PARSER_CHECK([./calc $3], $2, [], [stderr])],
b7c49edf 401 [AT_DATA([[input]],
b0f98b10 402[[$3
342b8b6e 403]])
b0f98b10 404AT_PARSER_CHECK([./calc input], $2, [], [stderr])])
342b8b6e 405
51dec47b
AD
406# Normalize the observed and expected error messages, depending upon the
407# options.
408# 1. Remove the traces from observed.
9280d3ef
AD
409sed '/^Starting/d
410/^Entering/d
f50adbbd 411/^Stack/d
9280d3ef
AD
412/^Reading/d
413/^Reducing/d
31c10e38 414/^Return/d
9280d3ef
AD
415/^Shifting/d
416/^state/d
dd5f2af2 417/^Cleanup:/d
9280d3ef
AD
418/^Error:/d
419/^Next/d
31c10e38 420/^Now/d
9280d3ef 421/^Discarding/d
62b08cfc 422/ \$[[0-9$]]* = /d
9280d3ef 423/^yydestructor:/d' stderr >at-stderr
342b8b6e 424mv at-stderr stderr
51dec47b
AD
425# 2. Create the reference error message.
426AT_DATA([[expout]],
b0f98b10 427[$5
342b8b6e 428])
51dec47b 429# 3. If locations are not used, remove them.
2a8d363a 430AT_YYERROR_SEES_LOC_IF([],
51dec47b
AD
431[[sed 's/^[-0-9.]*: //' expout >at-expout
432mv at-expout expout]])
433# 4. If error-verbose is not used, strip the`, unexpected....' part.
f50adbbd 434m4_bmatch([$1], [%error-verbose], [],
6e649e65 435[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
51dec47b
AD
436mv at-expout expout]])
437# 5. Check
438AT_CHECK([cat stderr], 0, [expout])
342b8b6e 439])
bfb07874
AD
440
441
fb9712a9
AD
442# AT_CHECK_CALC([BISON-OPTIONS, [EXPECTED-TO-FAIL]])
443# --------------------------------------------------
bfb07874
AD
444# Start a testing chunk which compiles `calc' grammar with
445# BISON-OPTIONS, and performs several tests over the parser.
907e3bc8 446# However, if EXPECTED-TO-FAIL is nonempty, this test is expected to fail.
342b8b6e 447m4_define([AT_CHECK_CALC],
bfb07874
AD
448[# We use integers to avoid dependencies upon the precision of doubles.
449AT_SETUP([Calculator $1])
450
907e3bc8
PE
451m4_ifval([$2], [AT_CHECK([exit 77])])
452
67a25fed 453AT_BISON_OPTION_PUSHDEFS([$1])
2a8d363a 454
bfb07874
AD
455AT_DATA_CALC_Y([$1])
456
8f7e3cf9 457AT_SKEL_CC_IF(
da730230 458 [AT_BISON_CHECK([-o calc.cc calc.y])
07971983 459 AT_COMPILE_CXX([calc])],
da730230 460 [AT_BISON_CHECK([-o calc.c calc.y])
07971983 461 AT_COMPILE([calc])])
bfb07874
AD
462
463# Test the priorities.
464_AT_CHECK_CALC([$1],
465[1 + 2 * 3 = 7
4661 + 2 * -3 = -5
467
468-1^2 = -1
469(-1)^2 = 1
470
471---1 = -1
472
4731 - 2 - 3 = -4
4741 - (2 - 3) = 2
475
4762^2^3 = 256
e7cb57c0 477(2^2)^3 = 64],
d1ff7a7c 478 [842])
bfb07874 479
6e649e65 480# Some syntax errors.
d1ff7a7c 481_AT_CHECK_CALC_ERROR([$1], [1], [0 0], [15],
cd48d21d 482 [1.3: syntax error, unexpected number])
d1ff7a7c 483_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20],
cd48d21d 484 [1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
e757bb10 485_AT_CHECK_CALC_ERROR([$1], [1], [error], [5],
cd48d21d 486 [1.1: syntax error, unexpected $undefined])
d1ff7a7c 487_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [30],
cd48d21d 488 [1.7: syntax error, unexpected '='])
b0f98b10 489_AT_CHECK_CALC_ERROR([$1], [1],
bfb07874
AD
490 [
491+1],
d1ff7a7c 492 [20],
cd48d21d 493 [2.1: syntax error, unexpected '+'])
b7c49edf 494# Exercise error messages with EOF: work on an empty file.
cea1469d 495_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
cd48d21d 496 [1.1: syntax error, unexpected end of input])
51dec47b
AD
497
498# Exercise the error token: without it, we die at the first error,
0b86fc41
AD
499# hence be sure to
500#
501# - have several errors which exercise different shift/discardings
502# - (): nothing to pop, nothing to discard
503# - (1 + 1 + 1 +): a lot to pop, nothing to discard
504# - (* * *): nothing to pop, a lot to discard
505# - (1 + 2 * *): some to pop and discard
506#
507# - test the action associated to `error'
508#
742e4900
JD
509# - check the lookahead that triggers an error is not discarded
510# when we enter error recovery. Below, the lookahead causing the
0b86fc41
AD
511# first error is ")", which is needed to recover from the error and
512# produce the "0" that triggers the "0 != 1" error.
513#
514_AT_CHECK_CALC_ERROR([$1], [0],
515 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
d1ff7a7c 516 [250],
cd48d21d
AD
517[1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
5181.18: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
5191.23: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
5201.41: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
0b86fc41
AD
521calc: error: 4444 != 1])
522
523# The same, but this time exercising explicitly triggered syntax errors.
742e4900 524# POSIX says the lookahead causing the error should not be discarded.
d1ff7a7c 525_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (0 0) = 1], [102],
cd48d21d 526[1.10: syntax error, unexpected number
0b86fc41 527calc: error: 2222 != 1])
d1ff7a7c 528_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (0 0) = 1], [113],
cd48d21d
AD
529[1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
5301.12: syntax error, unexpected number
82c53be4 531calc: error: 2222 != 1])
67a25fed 532AT_BISON_OPTION_POPDEFS
2a8d363a 533
d803322e 534AT_CLEANUP
bfb07874
AD
535])# AT_CHECK_CALC
536
537
538
539
f50adbbd
AD
540# ------------------------ #
541# Simple LALR Calculator. #
542# ------------------------ #
543
8f7e3cf9 544AT_BANNER([[Simple LALR(1) Calculator.]])
f50adbbd
AD
545
546# AT_CHECK_CALC_LALR([BISON-OPTIONS])
547# -----------------------------------
548# Start a testing chunk which compiles `calc' grammar with
549# BISON-OPTIONS, and performs several tests over the parser.
550m4_define([AT_CHECK_CALC_LALR],
551[AT_CHECK_CALC($@)])
552
553AT_CHECK_CALC_LALR()
554
9e32add8 555AT_CHECK_CALC_LALR([%defines])
ae7453f2 556AT_CHECK_CALC_LALR([%locations])
02975b9a 557AT_CHECK_CALC_LALR([%name-prefix="calc"]) dnl test deprecated `='
9e32add8
AD
558AT_CHECK_CALC_LALR([%verbose])
559AT_CHECK_CALC_LALR([%yacc])
f50adbbd
AD
560AT_CHECK_CALC_LALR([%error-verbose])
561
d9df47b6
JD
562AT_CHECK_CALC_LALR([%define api.pure %locations])
563AT_CHECK_CALC_LALR([%define api.push_pull "both" %define api.pure %locations])
ae7453f2 564AT_CHECK_CALC_LALR([%error-verbose %locations])
f50adbbd 565
02975b9a 566AT_CHECK_CALC_LALR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc])
f50adbbd
AD
567
568AT_CHECK_CALC_LALR([%debug])
02975b9a 569AT_CHECK_CALC_LALR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
c19988b7 570
d9df47b6
JD
571AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
572AT_CHECK_CALC_LALR([%define api.push_pull "both" %define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
2a8d363a 573
d9df47b6 574AT_CHECK_CALC_LALR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
f50adbbd
AD
575
576
577# ----------------------- #
578# Simple GLR Calculator. #
579# ----------------------- #
580
581AT_BANNER([[Simple GLR Calculator.]])
582
583# AT_CHECK_CALC_GLR([BISON-OPTIONS])
584# ----------------------------------
585# Start a testing chunk which compiles `calc' grammar with
586# BISON-OPTIONS and %glr-parser, and performs several tests over the parser.
587m4_define([AT_CHECK_CALC_GLR],
ae7453f2 588[AT_CHECK_CALC([%glr-parser] $@)])
f50adbbd 589
bfb07874 590
f50adbbd 591AT_CHECK_CALC_GLR()
bfb07874 592
9e32add8 593AT_CHECK_CALC_GLR([%defines])
ae7453f2 594AT_CHECK_CALC_GLR([%locations])
02975b9a 595AT_CHECK_CALC_GLR([%name-prefix "calc"])
9e32add8
AD
596AT_CHECK_CALC_GLR([%verbose])
597AT_CHECK_CALC_GLR([%yacc])
f50adbbd 598AT_CHECK_CALC_GLR([%error-verbose])
bfb07874 599
d9df47b6 600AT_CHECK_CALC_GLR([%define api.pure %locations])
ae7453f2 601AT_CHECK_CALC_GLR([%error-verbose %locations])
bfb07874 602
02975b9a 603AT_CHECK_CALC_GLR([%error-verbose %locations %defines %name-prefix "calc" %verbose %yacc])
bfb07874 604
f50adbbd 605AT_CHECK_CALC_GLR([%debug])
02975b9a 606AT_CHECK_CALC_GLR([%error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
21964f43 607
d9df47b6 608AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
2a8d363a 609
d9df47b6 610AT_CHECK_CALC_GLR([%define api.pure %error-verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
7548fed2
AD
611
612
613# ----------------------------- #
614# Simple LALR1 C++ Calculator. #
615# ----------------------------- #
616
8f7e3cf9 617AT_BANNER([[Simple LALR(1) C++ Calculator.]])
7548fed2 618
0e021770
PE
619# First let's try using %skeleton
620AT_CHECK_CALC([%skeleton "lalr1.cc" %defines %locations])
621
7548fed2
AD
622# AT_CHECK_CALC_LALR1_CC([BISON-OPTIONS])
623# ---------------------------------------
624# Start a testing chunk which compiles `calc' grammar with
caf37a36 625# the C++ skeleton, and performs several tests over the parser.
7548fed2 626m4_define([AT_CHECK_CALC_LALR1_CC],
0e021770 627[AT_CHECK_CALC([%language "C++" %defines %locations] $@)])
8f7e3cf9
AD
628
629AT_CHECK_CALC_LALR1_CC([])
02975b9a 630AT_CHECK_CALC_LALR1_CC([%error-verbose %name-prefix "calc" %verbose %yacc])
7548fed2 631
02975b9a 632AT_CHECK_CALC_LALR1_CC([%error-verbose %debug %name-prefix "calc" %verbose %yacc])
7548fed2 633
02975b9a 634AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc])
0b86fc41 635
02975b9a 636AT_CHECK_CALC_LALR1_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
7548fed2 637
7548fed2 638
7548fed2 639
8f7e3cf9
AD
640# --------------------------- #
641# Simple GLR C++ Calculator. #
642# --------------------------- #
643
644AT_BANNER([[Simple GLR C++ Calculator.]])
645
0e021770
PE
646# Again, we try also using %skeleton.
647AT_CHECK_CALC([%skeleton "glr.cc" %defines %locations])
648
8f7e3cf9
AD
649# AT_CHECK_CALC_GLR_CC([BISON-OPTIONS])
650# -------------------------------------
651# Start a testing chunk which compiles `calc' grammar with
652# the GLR C++ skeleton, and performs several tests over the parser.
653m4_define([AT_CHECK_CALC_GLR_CC],
0e021770 654[AT_CHECK_CALC([%language "C++" %glr-parser %defines %locations] $@)])
8f7e3cf9 655
fa7b79c0 656AT_CHECK_CALC_GLR_CC([])
02975b9a 657AT_CHECK_CALC_GLR_CC([%error-verbose %name-prefix "calc" %verbose %yacc])
8f7e3cf9 658
fa7b79c0 659AT_CHECK_CALC_GLR_CC([%debug])
02975b9a 660AT_CHECK_CALC_GLR_CC([%error-verbose %debug %name-prefix "calc" %verbose %yacc])
7548fed2 661
02975b9a 662AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc])
7548fed2 663
02975b9a 664AT_CHECK_CALC_GLR_CC([%pure-parser %error-verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])