+# AT_YYLEX_PROTOTYPE
+# AT_YYLEX_DECLARE_EXTERN
+# AT_YYLEX_DECLARE
+# AT_YYLEX_DEFINE([INPUT], [ACTION])
+# ----------------------------------
+# INPUT can be empty, or in double quotes, or a list (in braces).
+# ACTION may compute yylval for instance, using "res" as token type,
+# and "toknum" as the number of calls to yylex (starting at 0).
+m4_define([AT_YYLEX_PROTOTYPE],
+[int AT_NAME_PREFIX[]lex (]AT_YYLEX_FORMALS[)[]dnl
+])
+
+m4_define([AT_YYLEX_DECLARE_EXTERN],
+[AT_YYLEX_PROTOTYPE;dnl
+])
+
+m4_define([AT_YYLEX_DECLARE],
+[static AT_YYLEX_DECLARE_EXTERN[]dnl
+])
+
+m4_define([AT_YYLEX_DEFINE],
+[[#include <assert.h>
+static
+]AT_YYLEX_PROTOTYPE[
+{
+ ]m4_bmatch([$1], [^\(".*"\)?$],
+ [[static char const input[] = ]m4_default([$1], [""])],
+ [[static int const input[] = ]$1])[;
+ static size_t toknum = 0;
+ int res;
+ ]AT_USE_LEX_ARGS[;
+ assert (toknum < sizeof input / sizeof input[0]);
+ res = input[toknum++];
+ ]$2[;]AT_LOCATION_IF([[
+ ]AT_LOC_FIRST_LINE[ = ]AT_LOC_LAST_LINE[ = 1;
+ ]AT_LOC_FIRST_COLUMN[ = ]AT_LOC_LAST_COLUMN[ = toknum;]])[
+ return res;
+}]dnl
+])
+
+# AT_YYERROR_FORMALS
+# AT_YYERROR_PROTOTYPE
+# AT_YYERROR_DECLARE_EXTERN
+# AT_YYERROR_DECLARE
+# AT_YYERROR_DEFINE
+# -------------------------
+# Must be called inside a AT_BISON_OPTION_PUSHDEFS/POPDEFS pair.
+m4_define([AT_YYERROR_FORMALS], [AT_LANG_DISPATCH([$0], $@)])
+m4_define([AT_YYERROR_PROTOTYPE],[AT_LANG_DISPATCH([$0], $@)])
+m4_define([AT_YYERROR_DECLARE_EXTERN], [AT_LANG_DISPATCH([$0], $@)])
+m4_define([AT_YYERROR_DECLARE], [AT_LANG_DISPATCH([$0], $@)])
+m4_define([AT_YYERROR_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
+
+# AT_MAIN_DEFINE
+# --------------
+m4_define([AT_MAIN_DEFINE], [AT_LANG_DISPATCH([$0], $@)])
+
+
+
+## --- ##
+## C. ##
+## --- ##
+
+m4_define([AT_YYERROR_FORMALS(c)],
+[AT_YYERROR_ARG_LOC_IF([AT_YYLTYPE const * const llocp, ])AT_PARSE_PARAMS[const char *msg]])
+
+m4_define([AT_YYERROR_PROTOTYPE(c)],
+[[void ]AT_NAME_PREFIX[error (]AT_YYERROR_FORMALS[)]])
+
+m4_define([AT_YYERROR_DECLARE_EXTERN(c)],
+[AT_YYERROR_PROTOTYPE;])
+
+m4_define([AT_YYERROR_DECLARE(c)],
+[#include <stdio.h>
+]AT_LOCATION_IF([[
+#if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
+static unsigned location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp);
+# ifndef LOCATION_PRINT
+# define LOCATION_PRINT(File, Loc) location_print (File, &(Loc))
+# endif
+#endif
+]])[
+static AT_YYERROR_DECLARE_EXTERN])
+
+
+m4_define([AT_YYERROR_DEFINE(c)],
+[[
+]AT_LOCATION_IF([[
+# if defined ]AT_YYLTYPE[_IS_TRIVIAL && ]AT_YYLTYPE[_IS_TRIVIAL
+/* Print *YYLOCP on YYO. */
+__attribute__((__unused__))
+static unsigned
+location_print (FILE *yyo, ]AT_YYLTYPE[ const * const yylocp)
+{
+ unsigned res = 0;
+ int end_col = 0 != yylocp->last_column ? yylocp->last_column - 1 : 0;
+ if (0 <= yylocp->first_line)
+ {
+ res += fprintf (yyo, "%d", yylocp->first_line);
+ if (0 <= yylocp->first_column)
+ res += fprintf (yyo, ".%d", yylocp->first_column);
+ }
+ if (0 <= yylocp->last_line)
+ {
+ if (yylocp->first_line < yylocp->last_line)
+ {
+ res += fprintf (yyo, "-%d", yylocp->last_line);
+ if (0 <= end_col)
+ res += fprintf (yyo, ".%d", end_col);
+ }
+ else if (0 <= end_col && yylocp->first_column < end_col)
+ res += fprintf (yyo, "-%d", end_col);
+ }
+ return res;
+}
+#endif
+]])[
+/* A C error reporting function. */
+static
+]AT_YYERROR_PROTOTYPE[
+{]m4_bpatsubst(m4_defn([AT_PARSE_PARAMS]),
+ [[^,]+[^A-Za-z_0-9]\([A-Za-z_][A-Za-z_0-9]*\), *], [
+ YYUSE(\1);])dnl
+AT_YYERROR_SEES_LOC_IF([[
+ LOCATION_PRINT (stderr, ]AT_LOC[);
+ fprintf (stderr, ": ");]])[
+ fprintf (stderr, "%s\n", msg);
+}]])
+
+
+m4_define([AT_MAIN_DEFINE(c)],
+[[#include <stdlib.h> /* getenv. */
+#include <string.h> /* strcmp. */
+int
+main (int argc, char const* argv[])
+{]AT_DEBUG_IF([[
+ if (getenv("YYDEBUG")
+ || (argc == 2
+ && (!strcmp (argv[1], "-d") || !strcmp (argv[1], "--debug"))))
+ yydebug |= 1;]], [[
+ (void) argc;
+ (void) argv;]])[
+ return ]AT_NAME_PREFIX[parse ();
+}]])
+
+
+## ----- ##
+## C++. ##
+## ----- ##
+
+# No need to declare, it's part of the class interface.
+m4_define([AT_YYERROR_DECLARE(c++)], [])
+m4_define([AT_YYERROR_DECLARE_EXTERN(c++)], [])
+
+m4_define([AT_YYERROR_DEFINE(c++)],
+[[/* A C++ error reporting function. */
+void
+]AT_NAME_PREFIX[::parser::error (]AT_LOCATION_IF([[const location_type& l, ]])[const std::string& m)
+{
+ std::cerr << ]AT_LOCATION_IF([l << ": " << ])[m << std::endl;
+}]])
+
+
+m4_define([AT_MAIN_DEFINE(c++)],
+[[#include <cstdlib> // getenv.
+#include <cstring> // strcmp.
+int
+main (int argc, char const* argv[])
+{
+ ]AT_NAME_PREFIX[::parser p;]AT_DEBUG_IF([[
+ if (getenv("YYDEBUG")
+ || (argc == 2
+ && (!strcmp (argv[1], "-d") || !strcmp (argv[1], "--debug"))))
+ p.set_debug_level (true);]], [[
+ (void) argc;
+ (void) argv;]])[
+ return p.parse ();
+}]])
+
+
+
+## ------ ##
+## Java. ##
+## ------ ##
+
+m4_define([AT_YYERROR_DEFINE(java)],
+[AT_LOCATION_IF([[public void yyerror (Calc.Location l, String s)
+{
+ if (l == null)
+ System.err.println (s);
+ else
+ System.err.println (l + ": " + s);
+ }
+]], [[
+ public void yyerror (String s)
+ {
+ System.err.println (s);
+ }
+]])])
+
+m4_define([AT_MAIN_DEFINE(java)],
+[[class input
+{
+ public static void main (String args[]) throws IOException
+ {
+ YYParser p = new YYParser ();
+ p.parse ();
+ }
+}]])
+
+
+
+## --------------- ##
+## Running Bison. ##
+## --------------- ##
+