m4_define([b4_sint_type],
[m4_if(m4_eval([$1 <= 127]), [1], [signed char],
m4_eval([$1 <= 32767]), [1], [signed short],
- m4_eval([$1 <= 2147483647]), [1], [signed int],
- [m4_fatal([no signed int type for $1])])])
+ [signed int])])
# b4_uint_type(MAX)
m4_define([b4_uint_type],
[m4_if(m4_eval([$1 <= 255]), [1], [unsigned char],
m4_eval([$1 <= 65535]), [1], [unsigned short],
- m4_eval([$1 <= 4294967295]), [1], [unsigned int],
- [m4_fatal([no unsigned int type for $1])])])
+ [unsigned int])])
# b4_lhs_value([TYPE])
[yyvsp@<:@m4_eval([$2 - $1])@:>@m4_ifval([$3], [.$3])])
+
+## ----------- ##
+## Locations. ##
+## ----------- ##
+
+# b4_location_if(IF-TRUE, IF-FALSE)
+# ---------------------------------
+# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
+m4_define([b4_location_if],
+[m4_if(b4_locations_flag, [1],
+ [$1],
+ [$2])])
+
+
# b4_lhs_location()
# -----------------
# Expansion of @$.
[yylsp@<:@m4_eval([$2 - $1])@:>@])
+
+## -------------- ##
+## %pure-parser. ##
+## -------------- ##
+
+# b4_pure_if(IF-TRUE, IF-FALSE)
+# -----------------------------
+# Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
+m4_define([b4_pure_if],
+[m4_if(b4_pure, [1],
+ [$1],
+ [$2])])
+
+
+## ------------------- ##
+## Output file names. ##
+## ------------------- ##
+
m4_define_default([b4_input_suffix], [.y])
m4_define_default([b4_output_parser_suffix],
[[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])
+## ------------------------- ##
+## Assigning token numbers. ##
+## ------------------------- ##
+
# b4_token_define(TOKEN-NAME, TOKEN-NUMBER)
# -----------------------------------------
# Output the definition of this token as #define.
#define yychar b4_prefix[]char
#define yydebug b4_prefix[]debug
#define yynerrs b4_prefix[]nerrs
-#if YYLSP_NEEDED
-# define yylloc b4_prefix[]lloc
-#endif
-])
+b4_location_if([#define yylloc b4_prefix[]lloc])])
/* Copy the first part of user declarations. */
b4_pre_prologue
+b4_token_defines(b4_tokens)
+
/* Enabling traces. */
#ifndef YYDEBUG
# define YYDEBUG b4_debug
#endif
#ifndef YYSTYPE
-m4_ifdef([b4_stype_line],
+m4_ifdef([b4_stype],
[#line b4_stype_line "b4_filename"
-])dnl
-typedef b4_stype yystype;
+typedef union b4_stype yystype;
+/* Line __line__ of __file__. */
+#line __oline__ "__ofile__"],
+[typedef int yystype;])
# define YYSTYPE yystype
# define YYSTYPE_IS_TRIVIAL 1
#endif
{
short yyss;
YYSTYPE yyvs;
-# if YYLSP_NEEDED
- YYLTYPE yyls;
-# endif
+ b4_location_if([ YYLTYPE yyls;
+])dnl
};
/* The size of the maximum gap between one aligned stack and the next. */
/* The size of an array large to enough to hold all stacks, each with
N elements. */
-# if YYLSP_NEEDED
-# define YYSTACK_BYTES(N) \
+b4_location_if(
+[# define YYSTACK_BYTES(N) \
((N) * (sizeof (short) + sizeof (YYSTYPE) + sizeof (YYLTYPE)) \
- + 2 * YYSTACK_GAP_MAX)
-# else
-# define YYSTACK_BYTES(N) \
+ + 2 * YYSTACK_GAP_MAX)],
+[# define YYSTACK_BYTES(N) \
((N) * (sizeof (short) + sizeof (YYSTYPE)) \
- + YYSTACK_GAP_MAX)
-# endif
+ + YYSTACK_GAP_MAX)])
/* Copy COUNT objects from FROM to TO. The source and destination do
not overlap. */
#endif
-b4_token_defines(b4_tokens)
-
/* YYFINAL -- State number of the termination state. */
#define YYFINAL b4_final
#define YYFLAG b4_flag
#define YYUNDEFTOK b4_undef_token_number
#define YYMAXUTOK b4_user_token_number_max
-typedef b4_uint_type(b4_token_number_max) yy_token_number_type;
#define YYTRANSLATE(X) \
((unsigned)(X) <= YYMAXUTOK ? yytranslate[[X]] : YYUNDEFTOK)
/* YYTRANSLATE[[YYLEX]] -- Bison symbol number corresponding to YYLEX. */
-static const yy_token_number_type yytranslate[[]] =
+static const b4_uint_type(b4_translate_max) yytranslate[[]] =
{
b4_translate
};
#if YYDEBUG
/* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
-static const short yyprhs[[]] =
+static const b4_uint_type(b4_prhs_max) yyprhs[[]] =
{
b4_prhs
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-typedef b4_sint_type(b4_rhs_number_max) yyrhs_t;
-static const yyrhs_t yyrhs[[]] =
+static const b4_sint_type(b4_rhs_max) yyrhs[[]] =
{
b4_rhs
};
/* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
-static const short yyrline[[]] =
+static const b4_uint_type(b4_rline_max) yyrline[[]] =
{
b4_rline
};
#endif
-#if (YYDEBUG) || YYERROR_VERBOSE
+#if YYDEBUG || YYERROR_VERBOSE
/* YYTNME[[SYMBOL-NUM]] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[[]] =
};
#endif
-/* YYTOKNUM[[YYN]] -- Index in YYTNAME corresponding to YYLEX. */
+/* YYTOKNUM[[YYLEX-NUM]] -- Internal token number corresponding to
+ token YYLEX-NUM. */
static const short yytoknum[[]] =
{
b4_toknum
};
/* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
-static const yy_token_number_type yyr1[[]] =
+static const b4_uint_type(b4_r1_max) yyr1[[]] =
{
b4_r1
};
/* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
-static const short yyr2[[]] =
+static const b4_uint_type(b4_r2_max) yyr2[[]] =
{
b4_r2
};
-/* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
- doesn't specify something else to do. Zero means the default is an
- error. */
+/* YYDEFACT[[STATE-NAME]] -- Default rule to reduce with in state
+ STATE-NUM when YYTABLE doesn't specify something else to do. Zero
+ means the default is an error. */
static const short yydefact[[]] =
{
b4_defact
b4_check
};
+/* YYSTOS[[STATE-NUM]] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const b4_uint_type(b4_stos_max) yystos[[]] =
+{
+ b4_stos
+};
#if ! defined (YYSIZE_T) && defined (__SIZE_TYPE__)
# define YYSIZE_T __SIZE_TYPE__
/* YYLEX -- calling `yylex' with the right arguments. */
-#if YYPURE
-# if YYLSP_NEEDED
-# ifdef YYLEX_PARAM
-# define YYLEX yylex (&yylval, &yylloc, YYLEX_PARAM)
-# else
-# define YYLEX yylex (&yylval, &yylloc)
-# endif
-# else /* !YYLSP_NEEDED */
-# ifdef YYLEX_PARAM
-# define YYLEX yylex (&yylval, YYLEX_PARAM)
-# else
-# define YYLEX yylex (&yylval)
-# endif
-# endif /* !YYLSP_NEEDED */
-#else /* !YYPURE */
-# define YYLEX yylex ()
-#endif /* !YYPURE */
+b4_pure_if(
+[#ifdef YYLEX_PARAM
+# define YYLEX yylex (&yylval, b4_location_if([&yylloc, ])YYLEX_PARAM)
+#else
+# define YYLEX yylex (&yylval, b4_location_if([&yylloc, ]))
+#endif],
+[#define YYLEX yylex ()])
/* Enable debugging if requested. */
#if YYDEBUG
# endif
#endif
-/* YY_DECL_VARIABLES -- depending whether we use a pure parser,
- variables are global, or local to YYPARSE. */
-
-#define YY_DECL_NON_LSP_VARIABLES \
-/* The lookahead symbol. */ \
-int yychar; \
- \
-/* The semantic value of the lookahead symbol. */ \
-YYSTYPE yylval; \
- \
-/* Number of parse errors so far. */ \
-int yynerrs;
-
-#if YYLSP_NEEDED
-# define YY_DECL_VARIABLES \
-YY_DECL_NON_LSP_VARIABLES \
- \
-/* Location data for the lookahead symbol. */ \
-YYLTYPE yylloc;
-#else
-# define YY_DECL_VARIABLES \
-YY_DECL_NON_LSP_VARIABLES
+#if defined (__STDC__) || defined (__cplusplus)
+static void yydestructor (int yytype,
+ YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
+# if YYDEBUG
+static void yysymprint (FILE* out, int yytype,
+ YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]));
+# endif
#endif
-/* If nonreentrant, generate the variables here. */
+m4_divert_push([KILL])# ======================== M4 code.
+# b4_declare_parser_variables
+# ---------------------------
+# Declare the variables that are global, or local to YYPARSE if
+# pure-parser
+m4_define([b4_declare_parser_variables],
+[/* The lookahead symbol. */
+int yychar;
+
+/* The semantic value of the lookahead symbol. */
+YYSTYPE yylval;
+
+/* Number of parse errors so far. */
+int yynerrs;b4_location_if([
+/* Location data for the lookahead symbol. */
+YYLTYPE yylloc;])
+])
+m4_divert_pop([KILL])dnl# ====================== End of M4 code.
-#if !YYPURE
-YY_DECL_VARIABLES
-#endif /* !YYPURE */
+b4_pure_if([],
+ [b4_declare_parser_variables])
int
yyparse (YYPARSE_PARAM_ARG)
YYPARSE_PARAM_DECL
{[
- /* If reentrant, generate the variables here. */
-#if YYPURE
- YY_DECL_VARIABLES
-#endif /* !YYPURE */
-
+ ]b4_pure_if([b4_declare_parser_variables])[
register int yystate;
register int yyn;
int yyresult;
YYSTYPE *yyvs = yyvsa;
register YYSTYPE *yyvsp;
-#if YYLSP_NEEDED
- /* The location stack. */
+]b4_location_if(
+[[ /* The location stack. */
YYLTYPE yylsa[YYINITDEPTH];
YYLTYPE *yyls = yylsa;
- YYLTYPE *yylsp;
-#endif
+ YYLTYPE *yylsp;]])[
-#if YYLSP_NEEDED
-# define YYPOPSTACK (yyvsp--, yyssp--, yylsp--)
-#else
-# define YYPOPSTACK (yyvsp--, yyssp--)
-#endif
+#define YYPOPSTACK (yyvsp--, yyssp--]b4_location_if([, yylsp--])[)
YYSIZE_T yystacksize = YYINITDEPTH;
/* The variables used to return semantic value and location from the
action routines. */
YYSTYPE yyval;
-#if YYLSP_NEEDED
- YYLTYPE yyloc;
-#endif
+]b4_location_if([ YYLTYPE yyloc;])[
/* When reducing, the number of symbols on the RHS of the reduced
rule. */
yyssp = yyss;
yyvsp = yyvs;
-#if YYLSP_NEEDED
- yylsp = yyls;
-#endif
+]b4_location_if([ yylsp = yyls;])[
goto yysetstate;
/*------------------------------------------------------------.
memory. */
YYSTYPE *yyvs1 = yyvs;
short *yyss1 = yyss;
+]b4_location_if([ YYLTYPE *yyls1 = yyls;])[
/* Each stack pointer address is followed by the size of the
- data in use in that stack, in bytes. */
-# if YYLSP_NEEDED
- YYLTYPE *yyls1 = yyls;
- /* This used to be a conditional around just the two extra args,
- but that might be undefined if yyoverflow is a macro. */
+ data in use in that stack, in bytes. This used to be a
+ conditional around just the two extra args, but that might
+ be undefined if yyoverflow is a macro. */
yyoverflow ("parser stack overflow",
&yyss1, yysize * sizeof (*yyssp),
&yyvs1, yysize * sizeof (*yyvsp),
- &yyls1, yysize * sizeof (*yylsp),
+]b4_location_if([ &yyls1, yysize * sizeof (*yylsp),])[
&yystacksize);
- yyls = yyls1;
-# else
- yyoverflow ("parser stack overflow",
- &yyss1, yysize * sizeof (*yyssp),
- &yyvs1, yysize * sizeof (*yyvsp),
- &yystacksize);
-# endif
+]b4_location_if([ yyls = yyls1;])[
yyss = yyss1;
yyvs = yyvs1;
}
goto yyoverflowlab;
YYSTACK_RELOCATE (yyss);
YYSTACK_RELOCATE (yyvs);
-# if YYLSP_NEEDED
- YYSTACK_RELOCATE (yyls);
-# endif
+]b4_location_if([ YYSTACK_RELOCATE (yyls);])[
# undef YYSTACK_RELOCATE
if (yyss1 != yyssa)
YYSTACK_FREE (yyss1);
yyssp = yyss + yysize - 1;
yyvsp = yyvs + yysize - 1;
-#if YYLSP_NEEDED
- yylsp = yyls + yysize - 1;
-#endif
+]b4_location_if([ yylsp = yyls + yysize - 1;])[
YYDPRINTF ((stderr, "Stack size increased to %lu\n",
(unsigned long int) yystacksize));
which are defined only if `YYDEBUG' is set. */
if (yydebug)
{
- YYFPRINTF (stderr, "Next token is %d (%s",
- yychar, yytname[yychar1]);
- /* Give the individual parser a way to print the precise
- meaning of a token, for further debugging info. */
-# ifdef YYPRINT
- YYPRINT (stderr, yychar, yylval);
-# endif
- YYFPRINTF (stderr, ")\n");
+ YYFPRINTF (stderr, "Next token is ");
+ yysymprint (stderr, yychar1, yylval]b4_location_if([, yyloc])[);
+ YYFPRINTF (stderr, "\n");
}
#endif
}
yychar = YYEMPTY;
*++yyvsp = yylval;
-#if YYLSP_NEEDED
- *++yylsp = yylloc;
-#endif
+]b4_location_if([ *++yylsp = yylloc;])[
/* Count tokens shifted since error; after three, turn off error
status. */
GCC warning that YYVAL may be used uninitialized. */
yyval = yyvsp[1-yylen];
-#if YYLSP_NEEDED
- /* Default location. */
- YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);
-#endif
+]b4_location_if(
+[ /* Default location. */
+ YYLLOC_DEFAULT (yyloc, (yylsp - yylen), yylen);])[
#if YYDEBUG
/* We have to keep this `#if YYDEBUG', since we use variables which
\f
[ yyvsp -= yylen;
yyssp -= yylen;
-#if YYLSP_NEEDED
- yylsp -= yylen;
-#endif
+]b4_location_if([ yylsp -= yylen;])[
#if YYDEBUG
if (yydebug)
#endif
*++yyvsp = yyval;
-#if YYLSP_NEEDED
- *++yylsp = yyloc;
-#endif
+]b4_location_if([ *++yylsp = yyloc;])[
/* Now `shift' the result of the reduction. Determine what state
that goes to, based on the state we popped back to and the rule
/* Return failure if at end of input. */
if (yychar == YYEOF)
- YYABORT;
+ {
+ /* Pop the error token. */
+ YYPOPSTACK;
+ /* Pop the rest of the stack. */
+ while (yyssp > yyss)
+ {
+#if YYDEBUG
+ if (yydebug)
+ {
+ YYFPRINTF (stderr, "Error: popping ");
+ yysymprint (stderr,
+ yystos[*yyssp],
+ *yyvsp]b4_location_if([, *yylsp])[);
+ YYFPRINTF (stderr, "\n");
+ }
+#endif
+ yydestructor (yystos[*yyssp], *yyvsp]b4_location_if([, *yylsp])[);
+ YYPOPSTACK;
+ }
+ YYABORT;
+ }
+
YYDPRINTF ((stderr, "Discarding token %d (%s).\n",
yychar, yytname[yychar1]));
+ yydestructor (yychar1, yylval]b4_location_if([, yylloc])[);
yychar = YYEMPTY;
}
yyerrstatus = 3; /* Each real token shifted decrements this. */
- goto yyerrhandle;
-
+ for (;;)
+ {
+ yyn = yypact[yystate];
+ if (yyn != YYFLAG)
+ {
+ yyn += YYTERROR;
+ if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
+ {
+ yyn = yytable[yyn];
+ if (0 < yyn)
+ break;
+ }
+ }
-/*-------------------------------------------------------------------.
-| yyerrdefault -- current state does not do anything special for the |
-| error token. |
-`-------------------------------------------------------------------*/
-yyerrdefault:
-#if 0
- /* This is wrong; only states that explicitly want error tokens
- should shift them. */
+ /* Pop the current state because it cannot handle the error token. */
+ if (yyssp == yyss)
+ YYABORT;
- /* If its default is to accept any token, ok. Otherwise pop it. */
- yyn = yydefact[yystate];
- if (yyn)
- goto yydefault;
+#if YYDEBUG
+ if (yydebug)
+ {
+ YYFPRINTF (stderr, "Error: popping ");
+ yysymprint (stderr,
+ yystos[*yyssp],
+ *yyvsp]b4_location_if([, *yylsp])[);
+ YYFPRINTF (stderr, "\n");
+ }
#endif
-
-/*---------------------------------------------------------------.
-| yyerrpop -- pop the current state because it cannot handle the |
-| error token. |
-`---------------------------------------------------------------*/
-yyerrpop:
- if (yyssp == yyss)
- YYABORT;
- yyvsp--;
- yystate = *--yyssp;
-#if YYLSP_NEEDED
- yylsp--;
-#endif
+ yydestructor (yystos[yystate], *yyvsp]b4_location_if([, *yylsp])[);
+ yyvsp--;
+ yystate = *--yyssp;
+]b4_location_if([ yylsp--;])[
#if YYDEBUG
- if (yydebug)
- {
- short *yyssp1 = yyss - 1;
- YYFPRINTF (stderr, "Error: state stack now");
- while (yyssp1 != yyssp)
- YYFPRINTF (stderr, " %d", *++yyssp1);
- YYFPRINTF (stderr, "\n");
- }
+ if (yydebug)
+ {
+ short *yyssp1 = yyss - 1;
+ YYFPRINTF (stderr, "Error: state stack now");
+ while (yyssp1 != yyssp)
+ YYFPRINTF (stderr, " %d", *++yyssp1);
+ YYFPRINTF (stderr, "\n");
+ }
#endif
-
-/*--------------.
-| yyerrhandle. |
-`--------------*/
-yyerrhandle:
- yyn = yypact[yystate];
- if (yyn == YYFLAG)
- goto yyerrdefault;
-
- yyn += YYTERROR;
- if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
- goto yyerrdefault;
-
- yyn = yytable[yyn];
- if (yyn < 0)
- {
- if (yyn == YYFLAG)
- goto yyerrpop;
- yyn = -yyn;
- goto yyreduce;
}
- else if (yyn == 0)
- goto yyerrpop;
if (yyn == YYFINAL)
YYACCEPT;
YYDPRINTF ((stderr, "Shifting error token, "));
*++yyvsp = yylval;
-#if YYLSP_NEEDED
- *++yylsp = yylloc;
-#endif
+]b4_location_if([ *++yylsp = yylloc;])[
yystate = yyn;
goto yynewstate;
yyresult = 1;
goto yyreturn;
-/*---------------------------------------------.
-| yyoverflowab -- parser overflow comes here. |
-`---------------------------------------------*/
+#ifndef yyoverflow
+/*----------------------------------------------.
+| yyoverflowlab -- parser overflow comes here. |
+`----------------------------------------------*/
yyoverflowlab:
yyerror ("parser stack overflow");
yyresult = 2;
/* Fall through. */
+#endif
yyreturn:
#ifndef yyoverflow
return yyresult;
]}
+
+/*-----------------------------------------------.
+| Release the memory associated to this symbol. |
+`-----------------------------------------------*/
+
+m4_divert_push([KILL])# M4 code.
+# b4_symbol_destructor(SYMBOL-NUMBER, DESTRUCTOR, TYPE-NAME)
+# ----------------------------------------------------------
+m4_define([b4_symbol_destructor],
+[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
+m4_pushdef([b4_at_dollar], [yylocation])dnl
+ case $4: /* $3 */
+#line $2 "$1"
+ $5;
+#line __oline__ "__ofile__"
+ break;
+m4_popdef([b4_at_dollar])dnl
+m4_popdef([b4_dollar_dollar])])
+
+m4_divert_pop([KILL])dnl# End of M4 code.
+static void
+yydestructor (int yytype,
+ YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]))
+{
+ switch (yytype)
+ {
+m4_map([b4_symbol_destructor], m4_defn([b4_symbol_destructors]))dnl
+ default:
+ break;
+ }
+}
+
+
+#if YYDEBUG
+/*---------------------------.
+| Print this symbol on OUT. |
+`---------------------------*/
+
+m4_divert_push([KILL])# M4 code.
+# b4_symbol_printer(SYMBOL-NUMBER, PRINTER, TYPE-NAME)
+# ----------------------------------------------------------
+m4_define([b4_symbol_printer],
+[m4_pushdef([b4_dollar_dollar], [yyvalue.$6])dnl
+m4_pushdef([b4_at_dollar], [yylocation])dnl
+ case $4: /* $3 */
+#line $2 "$1"
+ $5;
+#line __oline__ "__ofile__"
+ break;
+m4_popdef([b4_at_dollar])dnl
+m4_popdef([b4_dollar_dollar])])
+
+m4_divert_pop([KILL])dnl# End of M4 code.
+static void
+yysymprint (FILE* out, int yytype,
+ YYSTYPE yyvalue[]b4_location_if([, YYLTYPE yylocation]))
+{
+ if (yytype < YYNTOKENS)
+ YYFPRINTF (out, "token %d (%s ", yytoknum[[yytype]], yytname[[yytype]]);
+ else
+ YYFPRINTF (out, "nterm %s (", yytname[[yytype]]);
+# ifdef YYPRINT
+ YYPRINT (out, yytype, yyvalue);
+# else
+ switch (yytype)
+ {
+m4_map([b4_symbol_printer], m4_defn([b4_symbol_printers]))dnl
+ default:
+ break;
+ }
+# endif /* !defined YYPRINT. */
+ YYFPRINTF (out, ")");
+}
+#endif /* YYDEBUG. */
+
b4_epilogue
m4_if(b4_defines_flag, 0, [],
[#output "b4_output_header_name"
b4_token_defines(b4_tokens)
#ifndef YYSTYPE
-m4_ifdef([b4_stype_line],
+m4_ifdef([b4_stype],
[#line b4_stype_line "b4_filename"
-])dnl
-typedef b4_stype
-yystype;
+typedef union b4_stype yystype;
+/* Line __line__ of __file__. */
+#line __oline__ "__ofile__"],
+[typedef int yystype;])
# define YYSTYPE yystype
#endif
-m4_if(b4_pure, [0],
+b4_pure_if([],
[extern YYSTYPE b4_prefix[]lval;])
-m4_if(b4_locations_flag, [0], [],
+b4_location_if(
[#ifndef YYLTYPE
typedef struct yyltype
{