# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA
+
+## ---------------- ##
+## Default values. ##
+## ---------------- ##
+
+# Stack parameters.
+m4_define_default([b4_stack_depth_max], [10000])
+m4_define_default([b4_stack_depth_init], [200])
+
+# Location type.
+m4_define_default([b4_location_type], [yyltype])
+
+# Accumule in b4_lex_param all the yylex arguments.
+# Yes, this is quite ugly...
+m4_define([b4_lex_param],
+m4_dquote(b4_pure_if([[[[YYSTYPE *]], [[yylvalp]]][]dnl
+b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl
+m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
+
+m4_define_default([b4_parse_param])
+
+
+## ----------------- ##
+## Semantic Values. ##
+## ----------------- ##
+
+
# b4_lhs_value([TYPE])
# --------------------
# Expansion of $<TYPE>$.
## 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 @$.
-## -------------- ##
-## %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. ##
## ------------------- ##
int last_line;
int last_column;])[
} yyltype;
-# define YYLTYPE ]b4_ltype[
+# define YYLTYPE ]b4_location_type[
# define YYLTYPE_IS_TRIVIAL 1
#endif
# define yyfalse 0
#endif
+#if defined (__STDC__) || defined (__cplusplus)
+ typedef signed char yysigned_char;
+#else
+ typedef short yysigned_char;
+#endif
+
/*-----------------.
| GCC extensions. |
`-----------------*/
/* YYFINAL -- State number of the termination state. */
#define YYFINAL ]b4_final_state_number[
+/* YYLAST -- Last index in YYTABLE. */
#define YYLAST ]b4_last[
/* YYNTOKENS -- Number of terminals. */
#endif
/* YYLEX -- calling `yylex' with the right arguments. */
+#define YYLEX ]b4_c_function_call([yylex], [int], b4_lex_param)[
]b4_pure_if(
[
-#ifdef YYLEX_PARAM
-# define YYLEX yylex (yylvalp, b4_location_if([yyllocp, ])YYLEX_PARAM)
-#else
-# define YYLEX yylex (yylvalp[]b4_location_if([, yyllocp]))
-#endif],
-[#define YYLEX yylex ()])
-
-b4_pure_if(
-[
#undef yynerrs
#define yynerrs (yystack->yyerrcnt)
#undef yychar
/* YYINITDEPTH -- initial size of the parser's stacks. */
#ifndef YYINITDEPTH
-# define YYINITDEPTH ]b4_initdepth[
+# define YYINITDEPTH ]b4_stack_depth_init[
#endif
/* YYMAXDEPTH -- maximum size the stacks can grow to (effective only
#endif
#ifndef YYMAXDEPTH
-# define YYMAXDEPTH ]b4_maxdepth[
+# define YYMAXDEPTH ]b4_stack_depth_max[
#endif
/* Minimum number of free items on the stack allowed after an
static inline bool
yyisShiftAction (int yyaction)
{
- return yyaction > 0;
+ return 0 < yyaction;
}
static inline bool
static void
yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate,
- yyGLRState* yyrhs, yyRuleNum yyrule)
+ yyGLRState* rhs, yyRuleNum yyrule)
{
yySemanticOption* yynewItem;
yynewItem = &yystack->yynextFree->yyoption;
yystack->yyspaceLeft -= 1;
yystack->yynextFree += 1;
yynewItem->yyisState = yyfalse;
- yynewItem->yystate = yyrhs;
+ yynewItem->yystate = rhs;
yynewItem->yyrule = yyrule;
yynewItem->yynext = yystate->yysemantics.yyfirstVal;
yystate->yysemantics.yyfirstVal = yynewItem;
size_t yysize, yynewSize;
size_t yyn;
yysize = yystack->yynextFree - yystack->yyitems;
- if (yysize >= YYMAXDEPTH)
+ if (YYMAXDEPTH <= yysize)
yyFail (yystack, "parsing stack overflow (%d items)", yysize);
yynewSize = 2*yysize;
- if (yynewSize > YYMAXDEPTH)
+ if (YYMAXDEPTH < yynewSize)
yynewSize = YYMAXDEPTH;
yyinitGLRStack (&yynewStack, yynewSize);
for (yyp0 = yystack->yyitems, yyp1 = yynewStack.yyitems, yyn = yysize;
- yyn > 0;
+ 0 < yyn;
yyn -= 1, yyp0 += 1, yyp1 += 1)
{
*yyp1 = *yyp0;
* the (unresolved) semantic value of RHS under the action for RULE. */
static inline void
yyglrShiftDefer (yyGLRStack* yystack, int yyk, yyStateNum yylrState,
- size_t yyposn, yyGLRState* yyrhs, yyRuleNum yyrule)
+ size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule)
{
yyGLRStackItem* yynewItem;
yystack->yytops.yystates[yyk] = &yynewItem->yystate;
yystack->yynextFree += 1;
yystack->yyspaceLeft -= 1;
- yyaddDeferredAction (yystack, &yynewItem->yystate, yyrhs, yyrule);
+ yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule);
}
/** Pop the symbols consumed by reduction #RULE from the top of stack
if (yystack->yysplitPoint == NULL)
{
/* Standard special case: single stack. */
- yyGLRStackItem* yyrhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
+ yyGLRStackItem* rhs = (yyGLRStackItem*) yystack->yytops.yystates[yyk];
assert (yyk == 0);
yystack->yynextFree -= yynrhs;
yystack->yyspaceLeft += yynrhs;
}
else
{
- *yyvalp = yyrhs[1-yynrhs].yystate.yysemantics.yysval;
- *yylocp = yyrhs[1-yynrhs].yystate.yyloc;
+ *yyvalp = rhs[1-yynrhs].yystate.yysemantics.yysval;
+ *yylocp = rhs[1-yynrhs].yystate.yyloc;
}
- return yyuserAction (yyrule, yynrhs, yyrhs, yyvalp, yylocp, yystack);
+ return yyuserAction (yyrule, yynrhs, rhs, yyvalp, yylocp, yystack);
}
else
{
int yyi;
yyGLRState* yys;
yyGLRStackItem yyrhsVals[YYMAXRHS];
- for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; yyi >= 0;
+ for (yyi = yynrhs-1, yys = yystack->yytops.yystates[yyk]; 0 <= yyi;
yyi -= 1, yys = yys->yypred)
{
assert (yys->yypred != NULL);
YYDPRINTF ((stderr, "Reducing stack %d by rule %d (line %d),",
yyk, yyrule - 1, yyrline[yyrule]));
/* Print the symbols being reduced, and their result. */
- for (yyi = yyprhs[yyrule]; yyrhs[yyi] >= 0; yyi++)
+ for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++)
YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
YYFPRINTF (stderr, " -> %s\n", yytokenName (yyr1[yyrule]));
}
yyStateNum yynewLRState;
for (yys = yystack->yytops.yystates[yyk], yyn = yyrhsLength (yyrule);
- yyn > 0; yyn -= 1)
+ 0 < yyn; yyn -= 1)
{
yys = yys->yypred;
assert (yys != NULL);
return 0;
if (p0 < p1)
return 3;
- if (p0 > p1)
+ if (p1 < p0)
return 2;
return 0;
}
yyresolveStates (yyGLRState* yys, int yyn, yyGLRStack* yystack)
{
YYRESULTTAG yyflag;
- if (yyn > 0)
+ if (0 < yyn)
{
assert (yys->yypred != NULL);
yyflag = yyresolveStates (yys->yypred, yyn-1, yystack);
yynrhs = yyrhsLength (yyopt->yyrule);
YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack));
- for (yyi = yynrhs-1, yys = yyopt->yystate; yyi >= 0;
+ for (yyi = yynrhs-1, yys = yyopt->yystate; 0 <= yyi;
yyi -= 1, yys = yys->yypred)
{
assert (yys->yypred != NULL);
}
#if YYDEBUG
-static yyGLRState YYLEFTMOST_STATE = { 0, 0, -1, NULL, 0, { NULL } };
+static yyGLRState YYLEFTMOST_STATE =
+ {
+ 0, 0, -1, NULL, 0, { NULL },
+ /* yyloc. */
+ {
+#if YYLTYPE_IS_TRIVIAL
+]b4_location_if([ 0, 0, 0, 0])[
+#endif
+ }
+ };
static void yyreportTree (yySemanticOption* yyx, int yyindent)
{
yyGLRState* yys;
yyGLRState* yystates[YYMAXRHS];
- for (yyi = yynrhs, yys = yyx->yystate; yyi > 0; yyi -= 1, yys = yys->yypred)
+ for (yyi = yynrhs, yys = yyx->yystate; 0 < yyi; yyi -= 1, yys = yys->yypred)
yystates[yyi] = yys;
if (yys == NULL)
yystates[0] = &YYLEFTMOST_STATE;
else
yystates[0] = yys;
- if (yys->yyposn+1 > yyx->yystate->yyposn)
+ if (yyx->yystate->yyposn < yys->yyposn + 1)
YYFPRINTF (stderr, "%*s%s -> <Rule %d, empty>\n",
yyindent, "", yytokenName (yylhsNonterm (yyx->yyrule)),
yyx->yyrule);
yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
yycount += 1, yyprefix = " or ";
yymsg = yyp = (char*) malloc (yysize);
- yyp += sprintf (yyp, "parse error, unexpected %s",
- yytokenName (*yytokenp));
+ sprintf (yyp, "parse error, unexpected %s",
+ yytokenName (*yytokenp));
+ yyp += strlen (yyp);
if (yycount < 5)
{
yyprefix = ", expecting ";
for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size; yyx += 1)
if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR)
{
- yyp += sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));
+ sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx));
+ yyp += strlen (yyp);
yyprefix = " or ";
}
}
while (yytrue)
{
- /* For efficiency, we have two loops, of which the first of which
- * is specialized to deterministic operation (single stack, no
- * potential ambiguity). */
+ /* For efficiency, we have two loops, the first of which is
+ specialized to deterministic operation (single stack, no
+ potential ambiguity). */
/* Standard mode */
while (yytrue)
yytoken = YYEMPTY;
yyposn += 1;
yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);
- if (yystack.yyerrState > 0)
+ if (0 < yystack.yyerrState)
yystack.yyerrState -= 1;
YYDPRINTF ((stderr, "Entering state %d\n",
yystack.yytops.yystates[0]->yylrState));