1 # Simple calculator. -*- Autotest -*-
3 # Copyright (C) 2000-2015, 2018-2020 Free Software Foundation, Inc.
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.
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.
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/>.
18 ## ---------------------------------------------------- ##
19 ## Compile the grammar described in the documentation. ##
20 ## ---------------------------------------------------- ##
23 m4_pushdef([AT_CALC_MAIN], [AT_LANG_DISPATCH([$0], $@)])
24 m4_pushdef([AT_CALC_YYLEX], [AT_LANG_DISPATCH([$0], $@)])
31 # _AT_DATA_CALC_Y($1, $2, $3, [BISON-DIRECTIVES])
32 # -----------------------------------------------
33 # Produce 'calc.y' and, if %header was specified, 'calc-lex.c' or
36 # Don't call this macro directly, because it contains some occurrences
37 # of '$1' etc. which will be interpreted by m4. So you should call it
38 # with $1, $2, and $3 as arguments, which is what AT_DATA_CALC_Y does.
40 # When %header is not passed, generate a single self-contained file.
41 # Otherwise, generate three: calc.y with the parser, calc-lex.c with
42 # the scanner, and calc-main.c with "main()". This is in order to
43 # stress the use of the generated parser header. To avoid code
44 # duplication, AT_CALC_YYLEX and AT_CALC_MAIN contain the body of these
46 m4_pushdef([_AT_DATA_CALC_Y],
47 [m4_if([$1$2$3], $[1]$[2]$[3], [],
48 [m4_fatal([$0: Invalid arguments: $@])])dnl
49 AT_LANG_DISPATCH([$0], $@)])
58 m4_define([AT_CALC_MAIN(c)],
60 #include <stdlib.h> /* exit */
61 #include <string.h> /* strcmp */
67 /* A C++ ]AT_NAME_PREFIX[parse that simulates the C signature. */
69 ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([semantic_value *result, int *count, int *nerrs]))[
71 ]AT_NAME_PREFIX[::parser parser]AT_PARAM_IF([ (result, count, nerrs)])[;
72 #if ]AT_API_PREFIX[DEBUG
73 parser.set_debug_level (1);
75 return parser.parse ();
80 /* Value of the last computation. */
81 semantic_value global_result = 0;
82 /* Total number of computations. */
84 /* Total number of errors. */
88 # define EX_NOINPUT 66
92 open_file (const char *file)
94 FILE *res = (file && *file && strcmp (file, "-")) ? fopen (file, "r") : stdin;
103 /* A C main function. */
105 main (int argc, const char **argv)
107 semantic_value result = 0;
112 /* This used to be alarm (10), but that isn't enough time for a July
113 1995 vintage DEC Alphastation 200 4/100 system, according to
114 Nelson H. F. Beebe. 100 seconds was enough for regular users,
115 but the Hydra build farm, which is heavily loaded needs more. */
119 ]AT_CXX_IF([], [AT_DEBUG_IF([ ]AT_NAME_PREFIX[debug = 1;])])[
123 for (i = 1; i < argc; ++i)
126 if (!strcmp (argv[i], "--exp") && i+1 < argc)
128 input = open_file (argv[i+1]);
130 ]AT_NAME_PREFIX[parse_exp_t res = ]AT_NAME_PREFIX[parse_exp ();
131 printf ("exp => %d (status: %d, errors: %d)\n",
132 res.yystatus == 0 ? res.yyvalue : 0, res.yystatus, res.yynerrs);
133 status = res.yystatus;
136 else if (!strcmp (argv[i], "--num") && i+1 < argc)
138 input = open_file (argv[i+1]);
140 ]AT_NAME_PREFIX[parse_NUM_t res = ]AT_NAME_PREFIX[parse_NUM ();
141 printf ("NUM => %d (status: %d, errors: %d)\n",
142 res.yystatus == 0 ? res.yyvalue : 0, res.yystatus, res.yynerrs);
143 status = res.yystatus;
148 input = open_file (argv[i]);
149 status = ]AT_NAME_PREFIX[parse (]AT_PARAM_IF([[&result, &count, &nerrs]])[);
151 if (input != stdin && fclose (input))
156 assert (global_result == result); (void) result;
157 assert (global_count == count); (void) count;
158 assert (global_nerrs == nerrs); (void) nerrs;
159 printf ("final: %d %d %d\n", global_result, global_count, global_nerrs);]])[
166 m4_define([AT_CALC_YYLEX(c)],
169 ]AT_YYLEX_DECLARE_EXTERN[
172 static AT_YYLTYPE last_yylloc;
175 get_char (]AT_YYLEX_FORMALS[)
177 int res = getc (input);
180 last_yylloc = AT_LOC;
184 AT_LOC_LAST_COLUMN = 1;
187 AT_LOC_LAST_COLUMN++;
193 unget_char (]AT_YYLEX_PRE_FORMALS[ int c)
197 /* Wrong when C == '\n'. */
198 AT_LOC = last_yylloc;
204 read_integer (]AT_YYLEX_FORMALS[)
206 int c = get_char (]AT_YYLEX_ARGS[);
212 res = 10 * res + (c - '0');
213 c = get_char (]AT_YYLEX_ARGS[);
216 unget_char (]AT_YYLEX_PRE_ARGS[ c);
222 /*---------------------------------------------------------------.
223 | Lexical analyzer returns an integer on the stack and the token |
224 | NUM, or the ASCII character read if not a number. Skips all |
225 | blanks and tabs, returns 0 for EOF. |
226 `---------------------------------------------------------------*/
231 /* Skip white spaces. */
235 AT_LOC_FIRST_COLUMN = AT_LOC_LAST_COLUMN;
236 AT_LOC_FIRST_LINE = AT_LOC_LAST_LINE;
239 while ((c = get_char (]AT_YYLEX_ARGS[)) == ' '
241 || (ignore_eol && c == '\n'));
243 /* Process numbers. */
246 unget_char (]AT_YYLEX_PRE_ARGS[ c);
247 ]AT_VAL[.]AT_VALUE_UNION_IF([NUM], [ival])[ = read_integer (]AT_YYLEX_ARGS[);
248 return ]AT_TOKEN([NUM])[;
251 /* Return end-of-file. */
253 return ]AT_TOKEN([CALC_EOF])[;
255 /* An explicit error raised by the scanner. */
258 fprintf (stderr, "%d.%d: ",
259 AT_LOC_FIRST_LINE, AT_LOC_FIRST_COLUMN);])[
260 fputs ("syntax error: invalid character: '#'\n", stderr);
261 return ]AT_TOKEN(AT_API_PREFIX[][error])[;
264 /* Return single chars. */
270 m4_define([_AT_DATA_CALC_Y(c)],
271 [AT_DATA_GRAMMAR([calc.y],
272 [[/* Infix notation calculator--calc */
276 ]AT_LOCATION_TYPE_SPAN_IF([[
289 # define YYLLOC_DEFAULT(Current, Rhs, N) \
293 (Current).first = YYRHSLOC (Rhs, 1).first; \
294 (Current).last = YYRHSLOC (Rhs, N).last; \
298 (Current).first = (Current).last = YYRHSLOC (Rhs, 0).last; \
304 void location_print (FILE *o, Span s);
305 #define LOCATION_PRINT location_print
309 /* Exercise pre-prologue dependency to %union. */
310 typedef int semantic_value;
313 ]AT_VALUE_UNION_IF([],
314 [[/* Exercise %union. */
319 %printer { ]AT_CXX_IF([[yyo << $$]],
320 [[fprintf (yyo, "%d", $$)]])[; } <]AT_VALUE_UNION_IF([int], [ival])[>;
327 /* Whether \n is a blank. */
328 extern int ignore_eol;
329 extern semantic_value global_result;
330 extern int global_count;
331 extern int global_nerrs;
342 static int power (int base, int exponent);
345 ]AT_YYLEX_DECLARE_EXTERN[
347 ]AT_TOKEN_TRANSLATE_IF([[
353 if (strcmp (cp, "end of input") == 0)
354 return "end of file";
355 else if (strcmp (cp, "number") == 0)
363 ]AT_LOCATION_TYPE_SPAN_IF([[
366 @$.first.l = @$.first.c = 1;
370 /* Bison Declarations */
371 %token CALC_EOF 0 ]AT_TOKEN_TRANSLATE_IF([_("end of file")], ["end of input"])[
372 %token <]AT_VALUE_UNION_IF([int], [ival])[> NUM "number"
373 %type <]AT_VALUE_UNION_IF([int], [ival])[> exp
375 %nonassoc '=' /* comparison */
378 %precedence NEG /* negation--unary minus */
379 %right '^' /* exponentiation */
381 /* Grammar follows */
385 | input line { ]AT_PARAM_IF([++*count; ++global_count;])[ }
390 | exp '\n' { ]AT_PARAM_IF([*result = global_result = $1;], [USE ($1);])[ }
397 if ($1 != $3)]AT_LANG_CASE(
401 snprintf (buf, sizeof buf, "error: %d != %d", $1, $3);]AT_YYERROR_ARG_LOC_IF([[
402 yyerror (&@$, ]AT_PARAM_IF([result, count, nerrs, ])[buf);]], [[
404 YYLTYPE old_yylloc = yylloc;
406 yyerror (]AT_PARAM_IF([result, count, nerrs, ])[buf);
414 snprintf (buf, sizeof buf, "error: %d != %d", $1, $3);
415 ]AT_GLR_IF([[yyparser.]])[error (]AT_LOCATION_IF([[@$, ]])[buf);
419 | exp '+' exp { $$ = $1 + $3; }
420 | exp '-' exp { $$ = $1 - $3; }
421 | exp '*' exp { $$ = $1 * $3; }
424 if ($3 == 0)]AT_LANG_CASE(
426 {]AT_YYERROR_ARG_LOC_IF([[
427 yyerror (&@3, ]AT_PARAM_IF([result, count, nerrs, ])["error: null divisor");]], [[
429 YYLTYPE old_yylloc = yylloc;
431 yyerr][or (]AT_PARAM_IF([result, count, nerrs, ])["error: null divisor");
438 ]AT_GLR_IF([[yyparser.]])[err][or (]AT_LOCATION_IF([[@3, ]])["error: null divisor");
443 | '-' exp %prec NEG { $$ = -$2; }
444 | exp '^' exp { $$ = power ($1, $3); }
445 | '(' exp ')' { $$ = $2; }
446 | '(' error ')' { $$ = 1111; yyerrok; }
447 | '-' error { $$ = 0; YYERROR; }
448 | '!' '!' { $$ = 0; YYERROR; }
449 | '!' '+' { $$ = 0; YYACCEPT; }
450 | '!' '-' { $$ = 0; YYABORT; }
455 power (int base, int exponent)
458 assert (0 <= exponent);
459 for (/* Niente */; exponent; --exponent)
464 ]AT_LOCATION_TYPE_SPAN_IF([AT_CXX_IF([[
469 operator<< (std::ostream& o, const Span& s)
471 o << s.first.l << '.' << s.first.c;
472 if (s.first.l != s.last.l)
473 o << '-' << s.last.l << '.' << s.last.c - 1;
474 else if (s.first.c != s.last.c - 1)
475 o << '-' << s.last.c - 1;
481 location_print (FILE *o, Span s)
483 fprintf (o, "%d.%d", s.first.l, s.first.c);
484 if (s.first.l != s.last.l)
485 fprintf (o, "-%d.%d", s.last.l, s.last.c - 1);
486 else if (s.first.c != s.last.c - 1)
487 fprintf (o, "-%d", s.last.c - 1);
495 AT_HEADER_IF([AT_DATA_SOURCE([[calc-lex.]AT_LANG_EXT],
496 [[#include "calc.]AT_LANG_HDR["
499 AT_DATA_SOURCE([[calc-main.]AT_LANG_EXT],
500 [[#include "calc.]AT_LANG_HDR["
504 ])# _AT_DATA_CALC_Y(c)
512 m4_copy([AT_CALC_MAIN(c)], [AT_CALC_MAIN(c++)])
513 m4_copy([AT_CALC_YYLEX(c)], [AT_CALC_YYLEX(c++)])
514 m4_copy([_AT_DATA_CALC_Y(c)], [_AT_DATA_CALC_Y(c++)])
522 m4_define([AT_CALC_MAIN(d)],
523 [[int main (string[] args)
525 semantic_value result = 0;
528 File input = args.length == 2 ? File (args[1], "r") : stdin;
529 auto l = calcLexer (input);
530 auto p = new YYParser (l);]AT_DEBUG_IF([[
531 p.setDebugLevel (1);]])[
536 m4_define([AT_CALC_YYLEX(d)],
537 [[import std.range.primitives;
540 auto calcLexer(R)(R range)
541 if (isInputRange!R && is (ElementType!R : dchar))
543 return new CalcLexer!R(range);
546 auto calcLexer (File f)
548 import std.algorithm : map, joiner;
549 import std.utf : byDchar;
551 return f.byChunk(1024) // avoid making a syscall roundtrip per char
552 .map!(chunk => cast(char[]) chunk) // because byChunk returns ubyte[]
553 .joiner // combine chunks into a single virtual range of char
554 .calcLexer; // forward to other overload
557 class CalcLexer(R) : Lexer
558 if (isInputRange!R && is (ElementType!R : dchar))
568 Value value_;]AT_LOCATION_IF([[
574 import std.uni : isNumber;
575 while (input.front.isNumber)
577 res = res * 10 + (input.front - '0');]AT_LOCATION_IF([[
578 location.end.column += 1;]])[
586 location.begin = location.end;]])[
588 import std.uni : isWhite, isNumber;
590 // Skip initial spaces
591 while (!input.empty && input.front != '\n' && isWhite (input.front))
593 input.popFront;]AT_LOCATION_IF([[
594 location.begin.column += 1;
595 location.end.column += 1;]])[
600 return Symbol(TokenKind.]AT_TOKEN_PREFIX[EOF]AT_LOCATION_IF([[, location]])[);
603 if (input.front.isNumber)
605 value_.ival = parseInt;
606 return Symbol(TokenKind.]AT_TOKEN_PREFIX[NUM, value_.ival]AT_LOCATION_IF([[, location]])[);
609 // Individual characters
610 auto c = input.front;]AT_LOCATION_IF([[
613 location.end.line += 1;
614 location.end.column = 1;
617 location.end.column += 1;]])[
620 // An explicit error raised by the scanner. */
623 stderr.writeln (]AT_LOCATION_IF([location, ": ", ])["syntax error: invalid character: '#'");
624 return Symbol(TokenKind.]AT_TOKEN_PREFIX[YYerror]AT_LOCATION_IF([[, location]])[);
629 case '+': return Symbol(TokenKind.]AT_TOKEN_PREFIX[PLUS]AT_LOCATION_IF([[, location]])[);
630 case '-': return Symbol(TokenKind.]AT_TOKEN_PREFIX[MINUS]AT_LOCATION_IF([[, location]])[);
631 case '*': return Symbol(TokenKind.]AT_TOKEN_PREFIX[STAR]AT_LOCATION_IF([[, location]])[);
632 case '/': return Symbol(TokenKind.]AT_TOKEN_PREFIX[SLASH]AT_LOCATION_IF([[, location]])[);
633 case '(': return Symbol(TokenKind.]AT_TOKEN_PREFIX[LPAR]AT_LOCATION_IF([[, location]])[);
634 case ')': return Symbol(TokenKind.]AT_TOKEN_PREFIX[RPAR]AT_LOCATION_IF([[, location]])[);
635 case '\n': return Symbol(TokenKind.]AT_TOKEN_PREFIX[EOL]AT_LOCATION_IF([[, location]])[);
636 case '=': return Symbol(TokenKind.]AT_TOKEN_PREFIX[EQUAL]AT_LOCATION_IF([[, location]])[);
637 case '^': return Symbol(TokenKind.]AT_TOKEN_PREFIX[POW]AT_LOCATION_IF([[, location]])[);
638 case '!': return Symbol(TokenKind.]AT_TOKEN_PREFIX[NOT]AT_LOCATION_IF([[, location]])[);
639 default: return Symbol(TokenKind.]AT_TOKEN_PREFIX[YYUNDEF]AT_LOCATION_IF([[, location]])[);
645 m4_define([_AT_DATA_CALC_Y(d)],
646 [AT_DATA_GRAMMAR([calc.y],
647 [[/* Infix notation calculator--calc */
650 alias semantic_value = int;
652 /* Exercise %union. */
657 %printer { yyo.write($$); } <ival>;
660 ]AT_TOKEN_TRANSLATE_IF([[
661 static string _(string s)
666 return "end of file";
676 /* Bison Declarations */
677 %token EOF 0 ]AT_TOKEN_TRANSLATE_IF([_("end of file")], ["end of input"])[
678 %token <ival> NUM "number"
692 %nonassoc "=" /* comparison */
695 %precedence NEG /* negation--unary minus */
696 %right "^" /* exponentiation */
698 /* Grammar follows */
702 | input line { ]AT_PARAM_IF([++*count; ++global_count;])[ }
707 | exp EOL { ]AT_PARAM_IF([*result = global_result = $1;])[ }
715 yyerror (]AT_LOCATION_IF([[@$, ]])[format ("error: %d != %d", $1, $3));
718 | exp "+" exp { $$ = $1 + $3; }
719 | exp "-" exp { $$ = $1 - $3; }
720 | exp "*" exp { $$ = $1 * $3; }
724 yyerror (]AT_LOCATION_IF([[@3, ]])["error: null divisor");
728 | "-" exp %prec NEG { $$ = -$2; }
729 | exp "^" exp { $$ = power ($1, $3); }
730 | "(" exp ")" { $$ = $2; }
731 | "(" error ")" { $$ = 1111; yyerrok(); }
732 | "-" error { $$ = 0; return YYERROR; }
733 | "!" "!" { $$ = 0; return YYERROR; }
734 | "!" "+" { $$ = 0; return YYACCEPT; }
735 | "!" "-" { $$ = 0; return YYABORT; }
740 power (int base, int exponent)
743 assert (0 <= exponent);
744 for (/* Niente */; exponent; --exponent)
751 ])# _AT_DATA_CALC_Y(d)
759 m4_define([AT_CALC_MAIN(java)],
760 [[public static void main (String[] args) throws IOException
762 Calc p = new Calc (System.in);]], [[
763 CalcLexer l = new CalcLexer (System.in);
764 Calc p = new Calc (l);]])AT_DEBUG_IF([[
765 p.setDebugLevel (1);]])[
766 boolean success = p.parse ();
772 m4_define([AT_CALC_YYLEX(java)],
773 [AT_LEXPARAM_IF([[%code lexer {]],
774 [[%code epilogue { class CalcLexer implements Calc.Lexer {]])[
775 StreamTokenizer st;]AT_LOCATION_IF([[
776 PositionReader reader;]])[
778 public ]AT_LEXPARAM_IF([[YYLexer]], [[CalcLexer]])[ (InputStream is)
780 reader = new PositionReader (new InputStreamReader (is));
781 st = new StreamTokenizer (reader);]], [[
782 st = new StreamTokenizer (new InputStreamReader (is));]])[
784 st.eolIsSignificant (true);
785 st.wordChars ('0', '9');
789 Position start = new Position (1, 0);
790 Position end = new Position (1, 0);
792 public Position getStartPos () {
793 return new Position (start);
796 public Position getEndPos () {
797 return new Position (end);
805 public Object getLVal () {
809 public int yylex() throws IOException {;]AT_LOCATION_IF([[
810 start.set(reader.getPosition());]])[
811 int tkind = st.nextToken();]AT_LOCATION_IF([[
812 end.set(reader.getPosition());]])[
815 case StreamTokenizer.TT_EOF:
817 case StreamTokenizer.TT_EOL:;]AT_LOCATION_IF([[
821 case StreamTokenizer.TT_WORD:
822 yylval = Integer.parseInt(st.sval);]AT_LOCATION_IF([[
823 end.set(reader.getPreviousPosition());]])[
828 System.err.println(]AT_LOCATION_IF([[start + ": " + ]])["syntax error: invalid character: '#'");
834 ]AT_LEXPARAM_IF([], [[}]])[
838 m4_define([_AT_DATA_CALC_Y(java)],
839 [AT_DATA_GRAMMAR([Calc.y],
840 [[/* Infix notation calculator--calc */
841 %define api.prefix {Calc}
842 %define api.parser.class {Calc}
847 %code imports {]AT_LOCATION_IF([[
848 import java.io.BufferedReader;]])[
849 import java.io.IOException;
850 import java.io.InputStream;
851 import java.io.InputStreamReader;
852 import java.io.Reader;
853 import java.io.StreamTokenizer;
859 ]AT_TOKEN_TRANSLATE_IF([[
860 static String i18n(String s)
862 if (s.equals ("end of input"))
863 return "end of file";
864 else if (s.equals ("number"))
872 /* Bison Declarations */
873 %token CALC_EOF 0 ]AT_TOKEN_TRANSLATE_IF([_("end of file")], ["end of input"])[
874 %token <Integer> NUM "number"
877 %nonassoc '=' /* comparison */
880 %precedence NEG /* negation--unary minus */
881 %right '^' /* exponentiation */
883 /* Grammar follows */
899 if ($1.intValue () != $3.intValue ())
900 yyerror (]AT_LOCATION_IF([[@$, ]])["error: " + $1 + " != " + $3);
902 | exp '+' exp { $$ = $1 + $3; }
903 | exp '-' exp { $$ = $1 - $3; }
904 | exp '*' exp { $$ = $1 * $3; }
907 if ($3.intValue () == 0)
908 yyerror (]AT_LOCATION_IF([[@3, ]])["error: null divisor");
912 | '-' exp %prec NEG { $$ = -$2; }
913 | exp '^' exp { $$ = (int) Math.pow ($1, $3); }
914 | '(' exp ')' { $$ = $2; }
915 | '(' error ')' { $$ = 1111; }
916 | '-' error { $$ = 0; return YYERROR; }
917 | '!' '!' { $$ = 0; return YYERROR; }
918 | '!' '+' { $$ = 0; return YYACCEPT; }
919 | '!' '-' { $$ = 0; return YYABORT; }
924 ]AT_JAVA_POSITION_DEFINE])[
926 ])# _AT_DATA_JAVA_CALC_Y
931 ## ------------------ ##
932 ## Calculator tests. ##
933 ## ------------------ ##
936 # AT_DATA_CALC_Y([BISON-OPTIONS])
937 # -------------------------------
938 # Produce 'calc.y' and, if %header was specified, 'calc-lex.c' or
940 m4_define([AT_DATA_CALC_Y],
941 [_AT_DATA_CALC_Y($[1], $[2], $[3], [$1])
945 # _AT_CHECK_CALC(CALC-OPTIONS, INPUT, [STDOUT], [NUM-STDERR-LINES])
946 # -----------------------------------------------------------------
947 # Run 'calc' on INPUT and expect no STDOUT nor STDERR.
949 # If BISON-OPTIONS contains '%debug' but not '%glr-parser', then
950 # NUM-STDERR-LINES is the number of expected lines on stderr.
951 # Currently this is ignored, though, since the output format is fluctuating.
953 # We don't count GLR's traces yet, since its traces are somewhat
954 # different from LALR's. Likewise for D.
956 # The push traces are the same, except for "Return for a new token", don't
958 m4_define([_AT_CHECK_CALC],
963 sed -e 's/^/ | /' <input
965 [AT_JAVA_PARSER_CHECK([Calc $1 < input], 0, [m4_ifvaln(m4_quote($3), [$3])], [stderr])],
966 [AT_PARSER_CHECK([calc $1 input], 0, [m4_ifvaln(m4_quote($3), [$3])], [stderr])])
967 AT_LANG_MATCH([c\|c++\|java],
969 [AT_CHECK([grep -c -v -E 'Return for a new token:|LAC:' stderr],
971 [m4_n([AT_DEBUG_IF([$4], [0])])])])])
975 # _AT_CHECK_CALC_ERROR($1 = BISON-OPTIONS, $2 = EXIT-STATUS, $3 = INPUT,
977 # $5 = [NUM-STDERR-LINES],
978 # $6 = [CUSTOM-ERROR-MESSAGE])
979 # $7 = [CALC-OPTIONS])
980 # ----------------------------------------------------------------------
981 # Run 'calc' on INPUT, and expect a 'syntax error' message.
983 # If INPUT starts with a slash, it is used as absolute input file name,
984 # otherwise as contents.
986 # NUM-STDERR-LINES is the number of expected lines on stderr.
987 # If BISON-OPTIONS contains '%debug' but not '%glr', then NUM-STDERR-LINES
988 # is the number of expected lines on stderr.
990 # CUSTOM-ERROR-MESSAGE is the expected error message when parse.error
991 # is 'custom' and locations are enabled. Other expected formats are
993 m4_define([_AT_CHECK_CALC_ERROR],
994 [m4_bmatch([$3], [^/],
996 [AT_JAVA_PARSER_CHECK([Calc $7 < $3], $2, [m4_ifvaln(m4_quote($4), [$4])], [stderr])],
997 [AT_PARSER_CHECK([calc $7 $3], $2, [m4_ifvaln(m4_quote($4), [$4])], [stderr])])],
1002 sed -e 's/^/ | /' <input
1004 [AT_JAVA_PARSER_CHECK([Calc $7 < input], $2, [m4_ifvaln(m4_quote($4), [$4])], [stderr])],
1005 [AT_PARSER_CHECK([calc $7 input], $2, [m4_ifvaln(m4_quote($4), [$4])], [stderr])])
1008 # Normalize the observed and expected error messages, depending upon the
1010 # 1. Remove the traces from observed.
1031 # 2. Create the reference error message.
1035 # 3. If locations are not used, remove them.
1036 AT_YYERROR_SEES_LOC_IF([],
1037 [[sed 's/^[-0-9.]*: //' expout >at-expout
1038 mv at-expout expout]])
1040 # 4. If parse.error is not custom, turn the expected message to
1041 # the traditional one.
1042 AT_ERROR_CUSTOM_IF([], [
1043 AT_PERL_REQUIRE([[-pi -e 'use strict;
1044 s{syntax error on token \[(.*?)\] \(expected: (.*)\)}
1047 my @exps = $][2 =~ /\[(.*?)\]/g;]AT_D_IF([[
1048 # In the case of D, there are no single quotes around the symbols.
1049 $unexp =~ s/'"'(.)'"'/$][1/g;
1050 s/'"'(.)'"'/$][1/g for @exps;]])[
1051 ($][#exps && $][#exps < 4)
1052 ? "syntax error, unexpected $unexp, expecting @{[join(\" or \", @exps)]}"
1053 : "syntax error, unexpected $unexp";
1058 # 5. If parse.error is simple, strip the', unexpected....' part.
1060 [[sed 's/syntax error, .*$/syntax error/' expout >at-expout
1061 mv at-expout expout]])
1063 # 6. Actually check.
1064 AT_CHECK([cat stderr], 0, [expout])
1068 # AT_CHECK_SPACES([FILES])
1069 # ------------------------
1070 # Make sure we did not introduce bad spaces. Checked here because all
1071 # the skeletons are (or should be) exercised here.
1072 m4_define([AT_CHECK_SPACES],
1073 [AT_PERL_CHECK([-ne '
1075 print "$ARGV:$.: {$_}\n"
1076 if (# No starting/ending empty lines.
1077 (eof || $. == 1) && /^\s*$/
1078 # No trailing space.
1087 # AT_CHECK_JAVA_GREP(FILE, [LINE], [COUNT=1])
1088 # -------------------------------------------
1089 # Check that FILE contains exactly COUNT lines matching ^LINE$
1090 # with grep. Unquoted so that COUNT can be a shell expression.
1091 m4_define([AT_CHECK_JAVA_GREP],
1092 [AT_CHECK_UNQUOTED([grep -c '^$2$' $1], [ignore], [m4_default([$3], [1])
1096 # AT_CHECK_CALC([BISON-OPTIONS], [COMPILER-OPTIONS])
1097 # --------------------------------------------------
1098 # Start a testing chunk which compiles 'calc' grammar with
1099 # BISON-OPTIONS, and performs several tests over the parser.
1100 m4_define([AT_CHECK_CALC],
1101 [m4_ifval([$3], [m4_fatal([$0: expected at most two arguments])])
1103 # We use integers to avoid dependencies upon the precision of doubles.
1104 AT_SETUP([Calculator $1 $2])
1106 AT_BISON_OPTION_PUSHDEFS([$1])
1108 AT_DATA_CALC_Y([$1])
1109 AT_FULL_COMPILE(AT_JAVA_IF([[Calc]], [[calc]]), AT_HEADER_IF([[lex], [main]], [[], []]), [$2], [-Wno-deprecated])
1112 [# No direct calls to malloc/free.
1113 AT_CHECK([[$EGREP '(malloc|free) *\(' calc.[ch] | $EGREP -v 'INFRINGES ON USER NAME SPACE']],
1116 AT_PUSH_IF([AT_JAVA_IF(
1117 [# Verify that this is a push parser.
1118 AT_CHECK_JAVA_GREP([[Calc.java]],
1119 [[.*public void push_parse_initialize ().*]])])])
1121 AT_CHECK_SPACES([AT_JAVA_IF([Calc], [calc]).AT_LANG_EXT AT_HEADER_IF([AT_JAVA_IF([Calc], [calc]).AT_LANG_HDR])])
1123 # Test the precedences.
1124 # The Java traces do not show the clean up sequence at the end,
1125 # since it does not support %destructor.
1140 [AT_PARAM_IF([final: 64 12 0])],
1141 [AT_JAVA_IF([1014], [1017])])
1143 # Some syntax errors.
1144 _AT_CHECK_CALC_ERROR([$1], [1], [1 2],
1145 [AT_PARAM_IF([final: 0 0 1])],
1147 [AT_JAVA_IF([1.3-1.4], [1.3])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] ['\n'])]])
1148 _AT_CHECK_CALC_ERROR([$1], [1], [1//2],
1149 [AT_PARAM_IF([final: 0 0 1])],
1151 [AT_JAVA_IF([1.3-1.4], [1.3])[: syntax error on token ['/'] (expected: [number] ['-'] ['('] ['!'])]])
1152 _AT_CHECK_CALC_ERROR([$1], [1], [error],
1153 [AT_PARAM_IF([final: 0 0 1])],
1155 [AT_JAVA_IF([1.1-1.2], [1.1])[: syntax error on token [invalid token] (expected: [number] ['-'] ['\n'] ['('] ['!'])]])
1156 _AT_CHECK_CALC_ERROR([$1], [1], [1 = 2 = 3],
1157 [AT_PARAM_IF([final: 0 0 1])],
1160 [AT_JAVA_IF([1.7-1.8], [1.7])[: syntax error on token ['='] (expected: ['-'] ['+'] ['*'] ['/'] ['^'] ['\n'])]],
1161 [AT_JAVA_IF([1.7-1.8], [1.7])[: syntax error on token ['='] (expected: ['-'] ['+'] ['*'] ['/'] ['^'])]])])
1162 _AT_CHECK_CALC_ERROR([$1], [1],
1165 [AT_PARAM_IF([final: 0 0 1])],
1167 [AT_JAVA_IF([2.1-2.2], [2.1])[: syntax error on token ['+'] (expected: ]AT_TOKEN_TRANSLATE_IF([[[end of file]]], [[[end of input]]])[ [number] ['-'] ['\n'] ['('] ['!'])]])
1168 # Exercise error messages with EOF: work on an empty file.
1169 _AT_CHECK_CALC_ERROR([$1], [1], [/dev/null],
1170 [AT_PARAM_IF([final: 0 0 1])],
1172 [[1.1: syntax error on token ]AT_TOKEN_TRANSLATE_IF([[[end of file]]], [[[end of input]]])[ (expected: [number] ['-'] ['\n'] ['('] ['!'])]])
1174 # Exercise the error token: without it, we die at the first error,
1177 # - have several errors which exercise different shift/discardings
1178 # - (): nothing to pop, nothing to discard
1179 # - (1 + 1 + 1 +): a lot to pop, nothing to discard
1180 # - (* * *): nothing to pop, a lot to discard
1181 # - (1 + 2 * *): some to pop and discard
1183 # - test the action associated to 'error'
1185 # - check the lookahead that triggers an error is not discarded
1186 # when we enter error recovery. Below, the lookahead causing the
1187 # first error is ")", which is needed to recover from the error and
1188 # produce the "0" that triggers the "0 != 1" error.
1190 _AT_CHECK_CALC_ERROR([$1], [0],
1191 [() + (1 + 1 + 1 +) + (* * *) + (1 * 2 * *) = 1],
1192 [AT_PARAM_IF([final: 4444 0 5])],
1194 [AT_JAVA_IF([1.2-1.3], [1.2])[: syntax error on token [')'] (expected: [number] ['-'] ['('] ['!'])
1195 ]AT_JAVA_IF([1.18-1.19], [1.18])[: syntax error on token [')'] (expected: [number] ['-'] ['('] ['!'])
1196 ]AT_JAVA_IF([1.23-1.24], [1.23])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
1197 ]AT_JAVA_IF([1.41-1.42], [1.41])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
1198 ]AT_JAVA_IF([1.1-1.47], [1.1-46])[: error: 4444 != 1]])
1200 # The same, but this time exercising explicitly triggered syntax errors.
1201 # POSIX says the lookahead causing the error should not be discarded.
1202 _AT_CHECK_CALC_ERROR([$1], [0], [(!!) + (1 2) = 1],
1203 [AT_PARAM_IF([final: 2222 0 2])],
1205 [AT_JAVA_IF([1.11-1.12], [1.11])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
1206 ]AT_JAVA_IF([1.1-1.17], [1.1-16])[: error: 2222 != 1]])
1208 _AT_CHECK_CALC_ERROR([$1], [0], [(- *) + (1 2) = 1],
1209 [AT_PARAM_IF([final: 2222 0 3])],
1211 [AT_JAVA_IF([1.4-1.5], [1.4])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
1212 ]AT_JAVA_IF([1.12-1.13], [1.12])[: syntax error on token [number] (expected: ['='] ['-'] ['+'] ['*'] ['/'] ['^'] [')'])
1213 ]AT_JAVA_IF([1.1-1.18], [1.1-17])[: error: 2222 != 1]])
1215 # Check that yyerrok works properly: second error is not reported,
1216 # third and fourth are. Parse status is successful.
1217 _AT_CHECK_CALC_ERROR([$1], [0], [(* *) + (*) + (*)],
1218 [AT_PARAM_IF([final: 3333 0 3])],
1220 [AT_JAVA_IF([1.2-1.3], [1.2])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
1221 ]AT_JAVA_IF([1.10-1.11], [1.10])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])
1222 ]AT_JAVA_IF([1.16-1.17], [1.16])[: syntax error on token ['*'] (expected: [number] ['-'] ['('] ['!'])]])
1227 # !+ => YYACCEPT, !- => YYABORT, !! => YYERROR.
1230 # Java lacks the traces at the end for cleaning the stack
1232 # -Cleanup: popping token '+' (1.1: )
1233 # -Cleanup: popping nterm exp (1.1: 7)
1234 _AT_CHECK_CALC([], [1 + 2 * 3 + !+ ++],
1235 [AT_PARAM_IF([final: 0 0 0])],
1236 [AT_JAVA_IF([77], [80])])
1238 _AT_CHECK_CALC_ERROR([$1], [1], [1 + 2 * 3 + !- ++],
1239 [AT_PARAM_IF([final: 0 0 0])],
1245 # Check that returning YYerror from the scanner properly enters
1246 # error-recovery without issuing a second error message.
1248 _AT_CHECK_CALC_ERROR([$1], [0], [(#) + (#) = 2222],
1249 [AT_PARAM_IF([final: 2222 0 0])],
1251 [[1.2: syntax error: invalid character: '#'
1252 1.8: syntax error: invalid character: '#']])
1254 _AT_CHECK_CALC_ERROR([$1], [0], [(1 + #) = 1111],
1255 [AT_PARAM_IF([final: 1111 0 0])],
1257 [[1.6: syntax error: invalid character: '#']])
1259 _AT_CHECK_CALC_ERROR([$1], [0], [(# + 1) = 1111],
1260 [AT_PARAM_IF([final: 1111 0 0])],
1262 [[1.2: syntax error: invalid character: '#']])
1264 _AT_CHECK_CALC_ERROR([$1], [0], [(1 + # + 1) = 1111],
1265 [AT_PARAM_IF([final: 1111 0 0])],
1267 [[1.6: syntax error: invalid character: '#']])
1269 _AT_CHECK_CALC_ERROR([$1], [0], [(1 + 1) / (1 - 1)],
1270 [AT_PARAM_IF([final: 2 0 1])],
1272 [AT_JAVA_IF([1.11-1.18], [1.11-17])[: error: null divisor]])
1274 # Multiple start symbols.
1276 _AT_CHECK_CALC([--num], [[123]],
1277 [[NUM => 123 (status: 0, errors: 0)]],
1278 [AT_JAVA_IF([1014], [1017])])
1279 _AT_CHECK_CALC_ERROR([$1], [1], [1 + 2 * 3],
1280 [NUM => 0 (status: 1, errors: 1)],
1282 [[1.3: syntax error, unexpected '+', expecting end of file]],
1285 _AT_CHECK_CALC([--exp], [[1 + 2 * 3]],
1286 [[exp => 7 (status: 0, errors: 0)]],
1287 [AT_JAVA_IF([1014], [1017])])
1291 AT_BISON_OPTION_POPDEFS
1299 # ----------------- #
1300 # LALR Calculator. #
1301 # ----------------- #
1303 AT_BANNER([[LALR(1) Calculator.]])
1305 # AT_CHECK_CALC_LALR([BISON-OPTIONS])
1306 # -----------------------------------
1307 # Start a testing chunk which compiles 'calc' grammar with
1308 # BISON-OPTIONS, and performs several tests over the parser.
1309 m4_define([AT_CHECK_CALC_LALR],
1310 [AT_CHECK_CALC($@)])
1312 AT_CHECK_CALC_LALR([%define parse.trace])
1314 AT_CHECK_CALC_LALR([%header])
1315 AT_CHECK_CALC_LALR([%debug %locations])
1316 AT_CHECK_CALC_LALR([%locations %define api.location.type {Span}])
1318 AT_CHECK_CALC_LALR([%name-prefix "calc"])
1319 AT_CHECK_CALC_LALR([%verbose])
1320 AT_CHECK_CALC_LALR([%yacc])
1321 AT_CHECK_CALC_LALR([%define parse.error detailed])
1322 AT_CHECK_CALC_LALR([%define parse.error verbose])
1324 AT_CHECK_CALC_LALR([%define api.pure full %locations])
1325 AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %locations])
1326 AT_CHECK_CALC_LALR([%define parse.error detailed %locations])
1328 AT_CHECK_CALC_LALR([%define parse.error detailed %locations %header %define api.prefix {calc} %verbose %yacc])
1329 AT_CHECK_CALC_LALR([%define parse.error detailed %locations %header %name-prefix "calc" %define api.token.prefix {TOK_} %verbose %yacc])
1331 AT_CHECK_CALC_LALR([%debug])
1332 AT_CHECK_CALC_LALR([%define parse.error detailed %debug %locations %header %name-prefix "calc" %verbose %yacc])
1333 AT_CHECK_CALC_LALR([%define parse.error detailed %debug %locations %header %define api.prefix {calc} %verbose %yacc])
1335 AT_CHECK_CALC_LALR([%define api.pure full %define parse.error detailed %debug %locations %header %name-prefix "calc" %verbose %yacc])
1336 AT_CHECK_CALC_LALR([%define api.push-pull both %define api.pure full %define parse.error detailed %debug %locations %header %define api.prefix {calc} %verbose %yacc])
1338 AT_CHECK_CALC_LALR([%define api.pure %define parse.error detailed %debug %locations %header %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1340 AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error detailed %debug %locations %header %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1341 AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error verbose %debug %locations %header %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1342 AT_CHECK_CALC_LALR([%no-lines %define api.pure %define parse.error verbose %debug %locations %defines %define api.prefix {calc} %verbose %yacc %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1344 # parse.error custom.
1345 AT_CHECK_CALC_LALR([%define parse.error custom])
1346 AT_CHECK_CALC_LALR([%define parse.error custom %locations %define api.prefix {calc}])
1347 AT_CHECK_CALC_LALR([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1348 AT_CHECK_CALC_LALR([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs} %define api.push-pull both %define api.pure full])
1349 AT_CHECK_CALC_LALR([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs} %define api.push-pull both %define api.pure full %define parse.lac full])
1352 AT_CHECK_CALC_LALR([%start input exp NUM %define api.value.type union])
1353 AT_CHECK_CALC_LALR([%start input exp NUM %define api.value.type union %locations %define parse.error detailed])
1356 # ---------------- #
1358 # ---------------- #
1360 AT_BANNER([[GLR Calculator.]])
1362 m4_define([AT_CHECK_CALC_GLR],
1363 [AT_CHECK_CALC([%glr-parser] $@)])
1367 AT_CHECK_CALC_GLR([%header])
1368 AT_CHECK_CALC_GLR([%locations])
1369 AT_CHECK_CALC_GLR([%locations %define api.location.type {Span}])
1370 AT_CHECK_CALC_GLR([%name-prefix "calc"])
1371 AT_CHECK_CALC_GLR([%define api.prefix {calc}])
1372 AT_CHECK_CALC_GLR([%verbose])
1373 AT_CHECK_CALC_GLR([%define parse.error verbose])
1375 AT_CHECK_CALC_GLR([%define api.pure %locations])
1376 AT_CHECK_CALC_GLR([%define parse.error verbose %locations])
1378 AT_CHECK_CALC_GLR([%define parse.error custom %locations %header %name-prefix "calc" %verbose])
1379 AT_CHECK_CALC_GLR([%define parse.error detailed %locations %header %name-prefix "calc" %verbose])
1380 AT_CHECK_CALC_GLR([%define parse.error verbose %locations %header %name-prefix "calc" %verbose])
1382 AT_CHECK_CALC_GLR([%debug])
1383 AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %header %name-prefix "calc" %verbose])
1384 AT_CHECK_CALC_GLR([%define parse.error verbose %debug %locations %header %define api.prefix {calc} %define api.token.prefix {TOK_} %verbose])
1386 AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %header %name-prefix "calc" %verbose])
1388 AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %header %name-prefix "calc" %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1389 AT_CHECK_CALC_GLR([%define api.pure %define parse.error verbose %debug %locations %header %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1391 AT_CHECK_CALC_GLR([%no-lines %define api.pure %define parse.error verbose %debug %locations %header %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1394 # ---------------------- #
1395 # LALR1 C++ Calculator. #
1396 # ---------------------- #
1398 AT_BANNER([[LALR(1) C++ Calculator.]])
1400 # First let's try using %skeleton
1401 AT_CHECK_CALC([%skeleton "lalr1.cc" %header])
1403 m4_define([AT_CHECK_CALC_LALR1_CC],
1404 [AT_CHECK_CALC([%language "C++" $1], [$2])])
1406 AT_CHECK_CALC_LALR1_CC([])
1407 AT_CHECK_CALC_LALR1_CC([%locations])
1408 AT_CHECK_CALC_LALR1_CC([%locations], [$NO_EXCEPTIONS_CXXFLAGS])
1409 AT_CHECK_CALC_LALR1_CC([%locations %define api.location.type {Span}])
1410 AT_CHECK_CALC_LALR1_CC([%header %locations %define parse.error verbose %name-prefix "calc" %verbose])
1412 AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %define api.prefix {calc} %verbose])
1413 AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %name-prefix "calc" %verbose])
1415 AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %define api.prefix {calc} %verbose])
1416 AT_CHECK_CALC_LALR1_CC([%locations %define parse.error verbose %debug %define api.prefix {calc} %define api.token.prefix {TOK_} %verbose])
1418 AT_CHECK_CALC_LALR1_CC([%header %locations %define parse.error verbose %debug %name-prefix "calc" %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1420 AT_CHECK_CALC_LALR1_CC([%define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1421 AT_CHECK_CALC_LALR1_CC([%header %locations %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1423 AT_CHECK_CALC_LALR1_CC([%header %locations %define api.location.file none])
1424 AT_CHECK_CALC_LALR1_CC([%header %locations %define api.location.file "my-location.hh"])
1426 AT_CHECK_CALC_LALR1_CC([%no-lines %header %locations %define api.location.file "my-location.hh"])
1428 AT_CHECK_CALC_LALR1_CC([%locations %define parse.lac full %define parse.error verbose])
1429 AT_CHECK_CALC_LALR1_CC([%locations %define parse.lac full %define parse.error detailed])
1430 AT_CHECK_CALC_LALR1_CC([%locations %define parse.lac full %define parse.error detailed %define parse.trace])
1432 AT_CHECK_CALC_LALR1_CC([%define parse.error custom])
1433 AT_CHECK_CALC_LALR1_CC([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1434 AT_CHECK_CALC_LALR1_CC([%define parse.error custom %locations %define api.prefix {calc} %parse-param {semantic_value *result}{int *count}{int *nerrs} %define parse.lac full])
1436 # -------------------- #
1437 # GLR C++ Calculator. #
1438 # -------------------- #
1440 AT_BANNER([[GLR C++ Calculator.]])
1442 # Again, we try also using %skeleton.
1443 AT_CHECK_CALC([%skeleton "glr.cc"])
1444 AT_CHECK_CALC([%skeleton "glr2.cc"])
1446 m4_define([AT_CHECK_CALC_GLR_CC],
1447 [AT_CHECK_CALC([%language "C++" %glr-parser] $@) # glr.cc
1448 AT_CHECK_CALC([%skeleton "glr2.cc"] $@)
1451 AT_CHECK_CALC_GLR_CC([])
1452 AT_CHECK_CALC_GLR_CC([%locations])
1453 AT_CHECK_CALC_GLR_CC([%locations %define api.location.type {Span}])
1454 AT_CHECK_CALC_GLR_CC([%header %define parse.error verbose %name-prefix "calc" %verbose])
1455 AT_CHECK_CALC_GLR_CC([%define parse.error verbose %define api.prefix {calc} %verbose])
1457 AT_CHECK_CALC_GLR_CC([%debug])
1459 AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %verbose])
1460 AT_CHECK_CALC_GLR_CC([%define parse.error verbose %debug %name-prefix "calc" %define api.token.prefix {TOK_} %verbose])
1462 AT_CHECK_CALC_GLR_CC([%locations %header %define parse.error verbose %debug %name-prefix "calc" %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1463 AT_CHECK_CALC_GLR_CC([%locations %header %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1465 AT_CHECK_CALC_GLR_CC([%no-lines %locations %header %define parse.error verbose %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1468 # -------------------- #
1469 # LALR1 D Calculator. #
1470 # -------------------- #
1472 AT_BANNER([[LALR(1) D Calculator.]])
1474 # First let's try using %skeleton
1475 AT_CHECK_CALC([%skeleton "lalr1.d"])
1477 m4_define([AT_CHECK_CALC_LALR1_D],
1478 [AT_CHECK_CALC([%language "D" $1], [$2])])
1480 AT_CHECK_CALC_LALR1_D([])
1481 AT_CHECK_CALC_LALR1_D([%locations])
1482 #AT_CHECK_CALC_LALR1_D([%locations %define api.location.type {Span}])
1483 AT_CHECK_CALC_LALR1_D([%define parse.error detailed %define api.prefix {calc} %verbose])
1485 AT_CHECK_CALC_LALR1_D([%debug])
1487 AT_CHECK_CALC_LALR1_D([%define parse.error custom])
1488 AT_CHECK_CALC_LALR1_D([%locations %define parse.error custom])
1489 AT_CHECK_CALC_LALR1_D([%locations %define parse.error detailed])
1490 AT_CHECK_CALC_LALR1_D([%locations %define parse.error simple])
1491 AT_CHECK_CALC_LALR1_D([%define parse.error detailed %debug %verbose])
1492 AT_CHECK_CALC_LALR1_D([%define parse.error detailed %debug %define api.symbol.prefix {SYMB_} %define api.token.prefix {TOK_} %verbose])
1494 AT_CHECK_CALC_LALR1_D([%locations %define parse.lac full %define parse.error detailed])
1495 AT_CHECK_CALC_LALR1_D([%locations %define parse.lac full %define parse.error custom])
1496 AT_CHECK_CALC_LALR1_D([%locations %define parse.lac full %define parse.error detailed %define parse.trace])
1498 #AT_CHECK_CALC_LALR1_D([%locations %define parse.error detailed %debug %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1499 #AT_CHECK_CALC_LALR1_D([%locations %define parse.error detailed %debug %define api.prefix {calc} %verbose %parse-param {semantic_value *result}{int *count}{int *nerrs}])
1502 # ----------------------- #
1503 # LALR1 Java Calculator. #
1504 # ----------------------- #
1506 AT_BANNER([[LALR(1) Java Calculator.]])
1508 m4_define([AT_CHECK_CALC_LALR1_JAVA],
1509 [AT_CHECK_CALC([%language "Java" $1], [$2])])
1511 AT_CHECK_CALC_LALR1_JAVA
1512 AT_CHECK_CALC_LALR1_JAVA([%define parse.error custom])
1513 AT_CHECK_CALC_LALR1_JAVA([%define parse.error detailed])
1514 AT_CHECK_CALC_LALR1_JAVA([%define parse.error verbose])
1515 AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error custom])
1516 AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error detailed])
1517 AT_CHECK_CALC_LALR1_JAVA([%locations %define parse.error verbose])
1518 AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error verbose])
1519 AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error verbose %locations %lex-param {InputStream is}])
1521 AT_CHECK_CALC_LALR1_JAVA([%define api.push-pull both])
1522 AT_CHECK_CALC_LALR1_JAVA([%define api.push-pull both %define parse.error detailed %locations])
1523 AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error custom %locations %lex-param {InputStream is} %define api.push-pull both])
1524 AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error verbose %locations %lex-param {InputStream is} %define api.push-pull both])
1527 AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error custom %locations %define parse.lac full])
1528 AT_CHECK_CALC_LALR1_JAVA([%define parse.trace %define parse.error custom %locations %define api.push-pull both %define parse.lac full])
1531 m4_popdef([AT_CALC_MAIN])
1532 m4_popdef([AT_CALC_YYLEX])