]> git.saurik.com Git - bison.git/blame_incremental - tests/calc.at
maint: post-release administrivia
[bison.git] / tests / calc.at
... / ...
CommitLineData
1# Simple calculator. -*- Autotest -*-
2
3# Copyright (C) 2000-2015 Free Software Foundation, Inc.
4
5# This program is free software: you can redistribute it and/or modify
6# it under the terms of the GNU General Public License as published by
7# the Free Software Foundation, either version 3 of the License, or
8# (at your option) any later version.
9#
10# This program is distributed in the hope that it will be useful,
11# but WITHOUT ANY WARRANTY; without even the implied warranty of
12# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13# GNU General Public License for more details.
14#
15# You should have received a copy of the GNU General Public License
16# along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18## ---------------------------------------------------- ##
19## Compile the grammar described in the documentation. ##
20## ---------------------------------------------------- ##
21
22
23# ------------------------- #
24# Helping Autotest macros. #
25# ------------------------- #
26
27
28# _AT_DATA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES])
29# -----------------------------------------------
30# Produce 'calc.y' and, if %defines was specified, 'calc-lex.c' or
31# 'calc-lex.cc'.
32#
33# Don't call this macro directly, because it contains some occurrences
34# of '$1' etc. which will be interpreted by m4. So you should call it
35# with $1, $2, and $3 as arguments, which is what AT_DATA_CALC_Y does.
36#
37# When %defines is not passed, generate a single self-contained file.
38# Otherwise, generate three: calc.y with the parser, calc-lex.c with
39# the scanner, and calc-main.c with "main()". This is in order to
40# stress the use of the generated parser header. To avoid code
41# duplication, AT_CALC_LEX and AT_CALC_MAIN contain the body of these
42# two later files.
43m4_define([_AT_DATA_CALC_Y],
44[m4_if([$1$2$3], $[1]$[2]$[3], [],
45 [m4_fatal([$0: Invalid arguments: $@])])dnl
46
47m4_pushdef([AT_CALC_MAIN],
48[#include <assert.h>
49#include <unistd.h>
50
51AT_SKEL_CC_IF([[
52/* A C++ ]AT_NAME_PREFIX[parse that simulates the C signature. */
53int
54]AT_NAME_PREFIX[parse (]AT_PARAM_IF([semantic_value *result, int *count]))[
55{
56 ]AT_NAME_PREFIX[::parser parser]AT_PARAM_IF([ (result, count)])[;
57#if ]AT_API_PREFIX[DEBUG
58 parser.set_debug_level (1);
59#endif
60 return parser.parse ();
61}
62]])[
63
64semantic_value global_result = 0;
65int global_count = 0;
66
67/* A C main function. */
68int
69main (int argc, const char **argv)
70{
71 semantic_value result = 0;
72 int count = 0;
73 int status;
74
75 /* This used to be alarm (10), but that isn't enough time for a July
76 1995 vintage DEC Alphastation 200 4/100 system, according to
77 Nelson H. F. Beebe. 100 seconds was enough for regular users,
78 but the Hydra build farm, which is heavily loaded needs more. */
79
80 alarm (200);
81
82 if (argc == 2)
83 input = fopen (argv[1], "r");
84 else
85 input = stdin;
86
87 if (!input)
88 {
89 perror (argv[1]);
90 return 3;
91 }
92
93]AT_SKEL_CC_IF([], [AT_DEBUG_IF([ ]AT_NAME_PREFIX[debug = 1;])])[
94 status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count]])[);
95 if (fclose (input))
96 perror ("fclose");
97 assert (global_result == result);
98 assert (global_count == count);
99 return status;
100}
101]])
102
103
104m4_pushdef([AT_CALC_LEX],
105[[#include <ctype.h>
106
107]AT_YYLEX_DECLARE_EXTERN[
108static int get_char (]AT_YYLEX_FORMALS[);
109static void unget_char (]AT_YYLEX_PRE_FORMALS[ int c);
110
111]AT_LOCATION_IF([
112static AT_YYLTYPE last_yylloc;
113])[
114static int
115get_char (]AT_YYLEX_FORMALS[)
116{
117 int res = getc (input);
118 ]AT_USE_LEX_ARGS[;
119]AT_LOCATION_IF([
120 last_yylloc = AT_LOC;
121 if (res == '\n')
122 {
123 AT_LOC_LAST_LINE++;
124 AT_LOC_LAST_COLUMN = 1;
125 }
126 else
127 AT_LOC_LAST_COLUMN++;
128])[
129 return res;
130}
131
132static void
133unget_char (]AT_YYLEX_PRE_FORMALS[ int c)
134{
135 ]AT_USE_LEX_ARGS[;
136]AT_LOCATION_IF([
137 /* Wrong when C == '\n'. */
138 AT_LOC = last_yylloc;
139])[
140 ungetc (c, input);
141}
142
143static int
144read_signed_integer (]AT_YYLEX_FORMALS[)
145{
146 int c = get_char (]AT_YYLEX_ARGS[);
147 int sign = 1;
148 int n = 0;
149
150 ]AT_USE_LEX_ARGS[;
151 if (c == '-')
152 {
153 c = get_char (]AT_YYLEX_ARGS[);
154 sign = -1;
155 }
156
157 while (isdigit (c))
158 {
159 n = 10 * n + (c - '0');
160 c = get_char (]AT_YYLEX_ARGS[);
161 }
162
163 unget_char (]AT_YYLEX_PRE_ARGS[ c);
164
165 return sign * n;
166}
167
168
169/*---------------------------------------------------------------.
170| Lexical analyzer returns an integer on the stack and the token |
171| NUM, or the ASCII character read if not a number. Skips all |
172| blanks and tabs, returns 0 for EOF. |
173`---------------------------------------------------------------*/
174
175]AT_YYLEX_PROTOTYPE[
176{
177 int c;
178 /* Skip current token, then white spaces. */
179 do
180 {
181]AT_LOCATION_IF(
182[ AT_LOC_FIRST_COLUMN = AT_LOC_LAST_COLUMN;
183 AT_LOC_FIRST_LINE = AT_LOC_LAST_LINE;
184])[
185 }
186 while ((c = get_char (]AT_YYLEX_ARGS[)) == ' ' || c == '\t');
187
188 /* process numbers */
189 if (c == '.' || isdigit (c))
190 {
191 unget_char (]AT_YYLEX_PRE_ARGS[ c);
192 ]AT_VAL[.ival = read_signed_integer (]AT_YYLEX_ARGS[);
193 return ]AT_TOKEN_PREFIX[NUM;
194 }
195
196 /* Return end-of-file. */
197 if (c == EOF)
198 return ]AT_TOKEN_PREFIX[CALC_EOF;
199
200 /* Return single chars. */
201 return c;
202}
203]])
204
205AT_DATA_GRAMMAR([calc.y],
206[[/* Infix notation calculator--calc */
207]$4
208AT_SKEL_CC_IF(
209[%define global_tokens_and_yystype])[
210%code requires
211{
212]AT_LOCATION_TYPE_IF([[
213# include <iostream>
214 struct Point
215 {
216 int l;
217 int c;
218 };
219
220 struct Span
221 {
222 Point first;
223 Point last;
224 };
225
226# define YYLLOC_DEFAULT(Current, Rhs, N) \
227 do \
228 if (N) \
229 { \
230 (Current).first = YYRHSLOC (Rhs, 1).first; \
231 (Current).last = YYRHSLOC (Rhs, N).last; \
232 } \
233 else \
234 { \
235 (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
236 } \
237 while (false)
238
239]])[
240 /* Exercise pre-prologue dependency to %union. */
241 typedef int semantic_value;
242}
243
244/* Exercise %union. */
245%union
246{
247 semantic_value ival;
248};
249%printer { ]AT_SKEL_CC_IF([[yyoutput << $$]],
250 [[fprintf (yyoutput, "%d", $$)]])[; } <ival>;
251
252%code provides
253{
254 #include <stdio.h>
255 /* The input. */
256 extern FILE *input;
257 extern semantic_value global_result;
258 extern int global_count;
259}
260
261%code
262{
263#include <assert.h>
264#include <string.h>
265#define USE(Var)
266
267FILE *input;
268static int power (int base, int exponent);
269
270]AT_YYERROR_DECLARE[
271]AT_YYLEX_DECLARE_EXTERN[
272}
273
274]AT_SKEL_CC_IF([AT_LOCATION_TYPE_IF([[
275%initial-action
276{
277 @$.first.l = @$.first.c = 1;
278 @$.last = @$.first;
279}]])])[
280
281/* Bison Declarations */
282%token CALC_EOF 0 "end of input"
283%token <ival> NUM "number"
284%type <ival> exp
285
286%nonassoc '=' /* comparison */
287%left '-' '+'
288%left '*' '/'
289%precedence NEG /* negation--unary minus */
290%right '^' /* exponentiation */
291
292/* Grammar follows */
293%%
294input:
295 line
296| input line { ]AT_PARAM_IF([++*count; ++global_count;])[ }
297;
298
299line:
300 '\n'
301| exp '\n' { ]AT_PARAM_IF([*result = global_result = $1], [USE ($1)])[; }
302;
303
304exp:
305 NUM { $$ = $1; }
306| exp '=' exp
307 {
308 if ($1 != $3)
309 fprintf (stderr, "calc: error: %d != %d\n", $1, $3);
310 $$ = $1;
311 }
312| exp '+' exp { $$ = $1 + $3; }
313| exp '-' exp { $$ = $1 - $3; }
314| exp '*' exp { $$ = $1 * $3; }
315| exp '/' exp { $$ = $1 / $3; }
316| '-' exp %prec NEG { $$ = -$2; }
317| exp '^' exp { $$ = power ($1, $3); }
318| '(' exp ')' { $$ = $2; }
319| '(' error ')' { $$ = 1111; yyerrok; }
320| '!' { $$ = 0; YYERROR; }
321| '-' error { $$ = 0; YYERROR; }
322;
323%%
324
325static int
326power (int base, int exponent)
327{
328 int res = 1;
329 assert (0 <= exponent);
330 for (/* Niente */; exponent; --exponent)
331 res *= base;
332 return res;
333}
334
335]AT_SKEL_CC_IF(
336[AT_LOCATION_TYPE_IF([[
337 std::ostream&
338 operator<< (std::ostream& o, const Span& s)
339 {
340 o << s.first.l << '.' << s.first.c;
341 if (s.first.l != s.last.l)
342 o << '-' << s.last.l << '.' << s.last.c - 1;
343 else if (s.first.c != s.last.c - 1)
344 o << '-' << s.last.c - 1;
345 return o;
346 }
347]])])[
348]AT_YYERROR_DEFINE[
349]AT_DEFINES_IF([],
350[AT_CALC_LEX
351AT_CALC_MAIN])])
352
353AT_DEFINES_IF([AT_DATA_SOURCE([[calc-lex.c]AT_SKEL_CC_IF([[c]])],
354[[#include "calc.h]AT_SKEL_CC_IF([[h]])["
355
356]AT_CALC_LEX])
357AT_DATA_SOURCE([[calc-main.c]AT_SKEL_CC_IF([[c]])],
358[[#include "calc.h]AT_SKEL_CC_IF([[h]])["
359
360]AT_CALC_MAIN])
361])
362m4_popdef([AT_CALC_MAIN])
363m4_popdef([AT_CALC_LEX])
364])# _AT_DATA_CALC_Y
365
366
367# AT_DATA_CALC_Y([BISON-OPTIONS])
368# -------------------------------
369# Produce 'calc.y' and, if %defines was specified, 'calc-lex.c' or
370# 'calc-lex.cc'.
371m4_define([AT_DATA_CALC_Y],
372[_AT_DATA_CALC_Y($[1], $[2], $[3], [$1])
373])
374
375
376
377# _AT_CHECK_CALC(BISON-OPTIONS, INPUT, [NUM-STDERR-LINES])
378# --------------------------------------------------------
379# Run 'calc' on INPUT and expect no STDOUT nor STDERR.
380#
381# If BISON-OPTIONS contains '%debug' but not '%glr-parser', then
382#
383# NUM-STDERR-LINES is the number of expected lines on stderr.
384# Currently this is ignored, though, since the output format is fluctuating.
385#
386# We don't count GLR's traces yet, since its traces are somewhat
387# different from LALR's.
388m4_define([_AT_CHECK_CALC],
389[AT_DATA([[input]],
390[[$2
391]])
392AT_PARSER_CHECK([./calc input], 0, [], [stderr])
393])
394
395
396# _AT_CHECK_CALC_ERROR(BISON-OPTIONS, EXIT-STATUS, INPUT,
397# [NUM-STDERR-LINES],
398# [VERBOSE-AND-LOCATED-ERROR-MESSAGE])
399# ---------------------------------------------------------
400# Run 'calc' on INPUT, and expect a 'syntax error' message.
401#
402# If INPUT starts with a slash, it is used as absolute input file name,
403# otherwise as contents.
404#
405# NUM-STDERR-LINES is the number of expected lines on stderr.
406# Currently this is ignored, though, since the output format is fluctuating.
407#
408# If BISON-OPTIONS contains '%location', then make sure the ERROR-LOCATION
409# is correctly output on stderr.
410#
411# If BISON-OPTIONS contains '%define parse.error verbose', then make sure the
412# IF-YYERROR-VERBOSE message is properly output after 'syntax error, '
413# on STDERR.
414#
415# If BISON-OPTIONS contains '%debug' but not '%glr', then NUM-STDERR-LINES
416# is the number of expected lines on stderr.
417m4_define([_AT_CHECK_CALC_ERROR],
418[m4_bmatch([$3], [^/],
419 [AT_PARSER_CHECK([./calc $3], $2, [], [stderr])],
420 [AT_DATA([[input]],
421[[$3
422]])
423AT_PARSER_CHECK([./calc input], $2, [], [stderr])])
424
425# Normalize the observed and expected error messages, depending upon the
426# options.
427# 1. Remove the traces from observed.
428sed '/^Starting/d
429/^Entering/d
430/^Stack/d
431/^Reading/d
432/^Reducing/d
433/^Return/d
434/^Shifting/d
435/^state/d
436/^Cleanup:/d
437/^Error:/d
438/^Next/d
439/^Now/d
440/^Discarding/d
441/ \$[[0-9$]]* = /d
442/^yydestructor:/d' stderr >at-stderr
443mv at-stderr stderr
444# 2. Create the reference error message.
445AT_DATA([[expout]],
446[$5
447])
448# 3. If locations are not used, remove them.
449AT_YYERROR_SEES_LOC_IF([],
450[[sed 's/^[-0-9.]*: //' expout >at-expout
451mv at-expout expout]])
452# 4. If error-verbose is not used, strip the', unexpected....' part.
453m4_bmatch([$1], [%define parse.error verbose], [],
454[[sed 's/syntax error, .*$/syntax error/' expout >at-expout
455mv at-expout expout]])
456# 5. Check
457AT_CHECK([cat stderr], 0, [expout])
458])
459
460
461# AT_CHECK_SPACES([FILES])
462# ------------------------
463# Make sure we did not introduce bad spaces. Checked here because all
464# the skeletons are (or should be) exercized here.
465m4_define([AT_CHECK_SPACES],
466[AT_CHECK([$PERL -ne '
467 chomp;
468 print "$ARGV:$.: {$_}\n"
469 if (# No starting/ending empty lines.
470 (eof || $. == 1) && /^\s*$/
471 # No trailing space.
472 || /\s$/
473 # No tabs.
474 || /\t/
475 )' $1
476])dnl
477])
478
479
480# AT_CHECK_CALC([BISON-OPTIONS])
481# ------------------------------
482# Start a testing chunk which compiles 'calc' grammar with
483# BISON-OPTIONS, and performs several tests over the parser.
484m4_define([AT_CHECK_CALC],
485[m4_ifval([$2], [m4_fatal([$0: expected a single argument])])
486
487# We use integers to avoid dependencies upon the precision of doubles.
488AT_SETUP([Calculator $1])
489
490AT_BISON_OPTION_PUSHDEFS([$1])
491
492AT_DATA_CALC_Y([$1])
493AT_FULL_COMPILE([calc], AT_DEFINES_IF([[lex], [main]]))
494AT_CHECK_SPACES(m4_join([ ],
495 [calc.AT_SKEL_CC_IF([cc], [c])],
496 [AT_DEFINES_IF([calc.AT_SKEL_CC_IF([hh], [h])])]))
497
498# Test the priorities.
499_AT_CHECK_CALC([$1],
500[1 + 2 * 3 = 7
5011 + 2 * -3 = -5
502
503-1^2 = -1
504(-1)^2 = 1
505
506---1 = -1
507
5081 - 2 - 3 = -4
5091 - (2 - 3) = 2
510
5112^2^3 = 256
512(2^2)^3 = 64],
513 [842])
514
515# Some syntax errors.
516_AT_CHECK_CALC_ERROR([$1], [1], [1 2], [15],
517 [1.3: syntax error, unexpected number])
518_AT_CHECK_CALC_ERROR([$1], [1], [1//2], [20],
519 [1.3: syntax error, unexpected '/', expecting number or '-' or '(' or '!'])
520_AT_CHECK_CALC_ERROR([$1], [1], [error], [5],
521 [1.1: syntax error, unexpected $undefined])
522_AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3], [30],
523 [1.7: syntax error, unexpected '='])
524_AT_CHECK_CALC_ERROR([$1], [1],
525 [
526+1],
527 [20],
528 [2.1: syntax error, unexpected '+'])
529# Exercise error messages with EOF: work on an empty file.
530_AT_CHECK_CALC_ERROR([$1], [1], [/dev/null], [4],
531 [1.1: syntax error, unexpected end of input])
532
533# Exercise the error token: without it, we die at the first error,
534# hence be sure to
535#
536# - have several errors which exercise different shift/discardings
537# - (): nothing to pop, nothing to discard
538# - (1 + 1 + 1 +): a lot to pop, nothing to discard
539# - (* * *): nothing to pop, a lot to discard
540# - (1 + 2 * *): some to pop and discard
541#
542# - test the action associated to 'error'
543#
544# - check the lookahead that triggers an error is not discarded
545# when we enter error recovery. Below, the lookahead causing the
546# first error is ")", which is needed to recover from the error and
547# produce the "0" that triggers the "0 != 1" error.
548#
549_AT_CHECK_CALC_ERROR([$1], [0],
550 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
551 [250],
552[1.2: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
5531.18: syntax error, unexpected ')', expecting number or '-' or '(' or '!'
5541.23: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
5551.41: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
556calc: error: 4444 != 1])
557
558# The same, but this time exercising explicitly triggered syntax errors.
559# POSIX says the lookahead causing the error should not be discarded.
560_AT_CHECK_CALC_ERROR([$1], [0], [(!) + (1 2) = 1], [102],
561[1.10: syntax error, unexpected number
562calc: error: 2222 != 1])
563_AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1], [113],
564[1.4: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
5651.12: syntax error, unexpected number
566calc: error: 2222 != 1])
567
568# Check that yyerrok works properly: second error is not reported,
569# third and fourth are. Parse status is succesfull.
570_AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)], [113],
571[1.2: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
5721.10: syntax error, unexpected '*', expecting number or '-' or '(' or '!'
5731.16: syntax error, unexpected '*', expecting number or '-' or '(' or '!'])
574
575AT_BISON_OPTION_POPDEFS
576
577AT_CLEANUP
578])# AT_CHECK_CALC
579
580
581
582
583# ------------------------ #
584# Simple LALR Calculator. #
585# ------------------------ #
586
587AT_BANNER([[Simple LALR(1) Calculator.]])
588
589# AT_CHECK_CALC_LALR([BISON-OPTIONS])
590# -----------------------------------
591# Start a testing chunk which compiles 'calc' grammar with
592# BISON-OPTIONS, and performs several tests over the parser.
593m4_define([AT_CHECK_CALC_LALR],
594[AT_CHECK_CALC($@)])
595
596AT_CHECK_CALC_LALR()
597
598AT_CHECK_CALC_LALR([%defines])
599AT_CHECK_CALC_LALR([%locations])
600
601AT_CHECK_CALC_LALR([%name-prefix "calc"])
602AT_CHECK_CALC_LALR([%verbose])
603AT_CHECK_CALC_LALR([%yacc])
604AT_CHECK_CALC_LALR([%define parse.error verbose])
605
606AT_CHECK_CALC_LALR([%define api.pure full %locations])
607AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %locations])
608AT_CHECK_CALC_LALR([%define parse.error verbose %locations])
609
610AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %define api.prefix {calc} %verbose %yacc])
611AT_CHECK_CALC_LALR([%define parse.error verbose %locations %defines %name-prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
612
613AT_CHECK_CALC_LALR([%debug])
614AT_CHECK_CALC_LALR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
615AT_CHECK_CALC_LALR([%define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc])
616
617AT_CHECK_CALC_LALR([%define api.pure full %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
618AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc])
619
620AT_CHECK_CALC_LALR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
621
622
623# ----------------------- #
624# Simple GLR Calculator. #
625# ----------------------- #
626
627AT_BANNER([[Simple GLR Calculator.]])
628
629# AT_CHECK_CALC_GLR([BISON-OPTIONS])
630# ----------------------------------
631# Start a testing chunk which compiles 'calc' grammar with
632# BISON-OPTIONS and %glr-parser, and performs several tests over the parser.
633m4_define([AT_CHECK_CALC_GLR],
634[AT_CHECK_CALC([%glr-parser] $@)])
635
636
637AT_CHECK_CALC_GLR()
638
639AT_CHECK_CALC_GLR([%defines])
640AT_CHECK_CALC_GLR([%locations])
641AT_CHECK_CALC_GLR([%name-prefix "calc"])
642AT_CHECK_CALC_GLR([%define api.prefix {calc}])
643AT_CHECK_CALC_GLR([%verbose])
644AT_CHECK_CALC_GLR([%yacc])
645AT_CHECK_CALC_GLR([%define parse.error verbose])
646
647AT_CHECK_CALC_GLR([%define api.pure %locations])
648AT_CHECK_CALC_GLR([%define parse.error verbose %locations])
649
650AT_CHECK_CALC_GLR([%define parse.error verbose %locations %defines %name-prefix "calc" %verbose %yacc])
651
652AT_CHECK_CALC_GLR([%debug])
653AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
654AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %defines %define api.prefix {calc} %define api.token.prefix {TOK_} %verbose %yacc])
655
656AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc])
657
658AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
659AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
660
661
662# ----------------------------- #
663# Simple LALR1 C++ Calculator. #
664# ----------------------------- #
665
666AT_BANNER([[Simple LALR(1) C++ Calculator.]])
667
668# First let's try using %skeleton
669AT_CHECK_CALC([%skeleton "lalr1.cc" %defines])
670
671# AT_CHECK_CALC_LALR1_CC([BISON-OPTIONS])
672# ---------------------------------------
673# Start a testing chunk which compiles 'calc' grammar with
674# the C++ skeleton, and performs several tests over the parser.
675m4_define([AT_CHECK_CALC_LALR1_CC],
676[AT_CHECK_CALC([%language "C++"] $@)])
677
678AT_CHECK_CALC_LALR1_CC([])
679AT_CHECK_CALC_LALR1_CC([%locations])
680AT_CHECK_CALC_LALR1_CC([%locations %define api.location.type {Span}])
681AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %name-prefix "calc" %verbose %yacc])
682
683AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %define api.prefix {calc} %verbose %yacc])
684AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
685
686AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc])
687AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %define api.prefix {calc} %define api.token.prefix {TOK_} %verbose %yacc])
688
689AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
690
691AT_CHECK_CALC_LALR1_CC([%define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
692AT_CHECK_CALC_LALR1_CC([%defines %locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
693
694
695
696# --------------------------- #
697# Simple GLR C++ Calculator. #
698# --------------------------- #
699
700AT_BANNER([[Simple GLR C++ Calculator.]])
701
702# Again, we try also using %skeleton.
703AT_CHECK_CALC([%skeleton "glr.cc"])
704
705# AT_CHECK_CALC_GLR_CC([BISON-OPTIONS])
706# -------------------------------------
707# Start a testing chunk which compiles 'calc' grammar with
708# the GLR C++ skeleton, and performs several tests over the parser.
709m4_define([AT_CHECK_CALC_GLR_CC],
710[AT_CHECK_CALC([%language "C++" %glr-parser] $@)])
711
712AT_CHECK_CALC_GLR_CC([])
713AT_CHECK_CALC_GLR_CC([%locations])
714AT_CHECK_CALC_GLR_CC([%locations %define api.location.type {Span}])
715AT_CHECK_CALC_GLR_CC([%defines %define parse.error verbose %name-prefix "calc" %verbose %yacc])
716AT_CHECK_CALC_GLR_CC([%define parse.error verbose %define api.prefix {calc} %verbose %yacc])
717
718AT_CHECK_CALC_GLR_CC([%debug])
719
720AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %verbose %yacc])
721AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
722
723AT_CHECK_CALC_GLR_CC([%locations %defines %define parse.error verbose %debug %name-prefix "calc" %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])
724AT_CHECK_CALC_GLR_CC([%locations %defines %define parse.error verbose %debug %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result} %parse-param {int *count}])