# 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. ##
## ------------------- ##
typedef struct yyltype
{
]b4_location_if([
- int yyfirst_line;
- int yyfirst_column;
- int yylast_line;
- int yylast_column;])[
+ int first_line;
+ int first_column;
+ 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[
-#define YYFLAG ]b4_flag[
+/* YYLAST -- Last index in YYTABLE. */
#define YYLAST ]b4_last[
/* YYNTOKENS -- Number of terminals. */
/* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
- number is the opposite. If zero, do what YYDEFACT says. */
+ number is the opposite. If zero, do what YYDEFACT says.
+ If YYTABLE_NINF, parse error. */
#define YYTABLE_NINF ]b4_table_ninf[
static const ]b4_int_type_for([b4_table])[ yytable[] =
{
]b4_table[
};
-/* YYCONFLP[YYPACT[STATE-NUM]] -- pointer into yyconfl of start of list
- of conflicting reductions corresponding to action entry for state
- STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
- is terminated by a rule number of 0. */
+/* YYCONFLP[YYPACT[STATE-NUM]] -- Pointer into YYCONFL of start of
+ list of conflicting reductions corresponding to action entry for
+ state STATE-NUM in yytable. 0 means no conflicts. The list in
+ yyconfl is terminated by a rule number of 0. */
static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
{
]b4_conflict_list_heads[
};
-/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
- by 0, pointed into by YYCONFLP. */
+/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated by
+ 0, pointed into by YYCONFLP. */
]dnl Do not use b4_int_type_for here, since there are places where
dnl pointers onto yyconfl are taken, which type is "short *".
dnl We probably ought to introduce a type for confl.
#ifndef YYLLOC_DEFAULT
# define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \
- yyCurrent.yyfirst_line = YYRHSLOC(yyRhs,1).yyfirst_line; \
- yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \
- yyCurrent.yylast_line = YYRHSLOC(yyRhs,YYN).yylast_line; \
- yyCurrent.yylast_column = YYRHSLOC(yyRhs,YYN).yylast_column;
+ yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \
+ yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \
+ yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \
+ yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column;
#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
return yydefact[yystate];
}
-/** Set *ACTION to the action to take in STATE on seeing TOKEN.
+/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
* Result R means
* R < 0: Reduce on rule -R.
* R = 0: Error.
int* yyaction, const short** yyconflicts)
{
int yyindex = yypact[yystate] + yytoken;
- if (yyindex < 0 || yyindex > YYLAST || yycheck[yyindex] != yytoken)
+ if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken)
{
*yyaction = -yydefact[yystate];
*yyconflicts = yyconfl;
}
- else
+ else if (yytable[yyindex] != YYTABLE_NINF)
{
*yyaction = yytable[yyindex];
*yyconflicts = yyconfl + yyconflp[yyindex];
}
+ else
+ {
+ *yyaction = 0;
+ *yyconflicts = yyconfl + yyconflp[yyindex];
+ }
}
static inline yyStateNum
{
int yyr;
yyr = yypgoto[yylhs - YYNTOKENS] + yystate;
- if (yyr >= 0 && yyr <= YYLAST && yycheck[yyr] == yystate)
+ if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate)
return yytable[yyr];
else
return yydefgoto[yylhs - YYNTOKENS];
static inline bool
yyisShiftAction (int yyaction)
{
- return yyaction > 0;
+ return 0 < yyaction;
}
static inline bool
yyisErrorAction (int yyaction)
{
- return yyaction == 0 || yyaction == YYPACT_NINF;
+ return yyaction == 0;
}
/* GLRStates */
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);
YYSTYPE yysval;
YYLTYPE yyloc;
+#if YYDEBUG
+ if (yydebug)
+ {
+ int yyi;
+ 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]; 0 <= yyrhs[yyi]; yyi++)
+ YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi]));
+ YYFPRINTF (stderr, " -> %s\n", yytokenName (yyr1[yyrule]));
+ }
+#endif
YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc));
yyglrShift (yystack, yyk,
yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState,
yylhsNonterm (yyrule)),
yyposn, yysval, &yyloc);
- YYDPRINTF ((stderr, "Reduced stack %d by rule #%d. Now in state %d.\n",
- yyk, yyrule-1, yystack->yytops.yystates[yyk]->yylrState));
+ YYDPRINTF ((stderr, "Stack %d entering state %d\n",
+ yyk, yystack->yytops.yystates[yyk]->yylrState));
}
else
{
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, NULL, -1, 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);
{
if (*yytokenp == YYEMPTY)
{
+ YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
*yytokenp = YYTRANSLATE(yychar);
- YYDPRINTF ((stderr, "Read token %s\n", yytokenName (*yytokenp)));
+ YYDPRINTF ((stderr, "Next token is %s\n",
+ yytokenName (*yytokenp)));
}
yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
if (yyisShiftAction (yyaction))
{
- YYDPRINTF ((stderr, "Shifted token %s on stack %d, ",
+ YYDPRINTF ((stderr, "Shifting token %s on stack %d, ",
yytokenName (*yytokenp), yyk));
yyglrShift (yystack, yyk, yyaction, yyposn+1, *yylvalp, yyllocp);
YYDPRINTF ((stderr, "which is now in state #%d\n",
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)
+ 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 ";
}
}
}
}
-/* Recover from a syntax error on STACK, assuming that TOKENP,
+/* Recover from a syntax error on YYSTACK, assuming that YYTOKENP,
YYLVALP, and YYLLOCP point to the syntactic category, semantic
- value, and location of the lookahead.
- NOTE: This uses the panic-mode recovery algorithm described in the
- Bison documentation, which differs from what is in bison.simple.
- Specifically, this routine performs no reductions before shifting
- the error token. */
+ value, and location of the lookahead. */
static void
yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp)
{
if (yystack->yyerrState == 0)
yystack->yyerrState = 3;
else if (yystack->yyerrState == 3)
- {
- /* We just shifted the error token and (perhaps) took some
- reductions. Skip tokens until we can proceed. */
- do {
+ /* We just shifted the error token and (perhaps) took some
+ reductions. Skip tokens until we can proceed. */
+ while (yytrue)
+ {
if (*yytokenp == YYEOF)
yyFail (yystack, NULL);
if (*yytokenp != YYEMPTY)
YYDPRINTF ((stderr, "Discarding token %s\n",
yytokenName (*yytokenp)));
+ YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
*yytokenp = YYTRANSLATE (yychar);
- YYDPRINTF ((stderr, "Read token %s\n", yytokenName (*yytokenp)));
+ YYDPRINTF ((stderr, "Next token is %s\n", yytokenName (*yytokenp)));
yyj = yypact[yystack->yytops.yystates[0]->yylrState];
if (yyj == YYPACT_NINF)
- /* Something's not right; we shouldn't be here */
+ /* Something's not right; we shouldn't be here. */
yyFail (yystack, NULL);
yyj += *yytokenp;
- if (yyj < 0 || yyj > YYLAST || yycheck[yyj] != *yytokenp)
+ if (yyj < 0 || YYLAST < yyj || yycheck[yyj] != *yytokenp)
{
if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)
return;
}
else if (yytable[yyj] != 0 && yytable[yyj] != YYTABLE_NINF)
return;
- } while (yytrue);
- }
+ }
- /* Reduce to one stack */
+ /* Reduce to one stack. */
for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1)
if (yystack->yytops.yystates[yyk] != NULL)
break;
yyinitGLRStack (&yystack, YYINITDEPTH);
yystack.yytokenp = &yytoken;
+ YYDPRINTF ((stderr, "Starting parse\n"));
+
if (setjmp (yystack.yyexception_buffer) != 0)
goto yyDone;
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)
{
if (yytoken == YYEMPTY)
{
+ YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
yytoken = YYTRANSLATE (yychar);
- YYDPRINTF ((stderr, "Read token %s\n",
+ YYDPRINTF ((stderr, "Next token is %s\n",
yytokenName (yytoken)));
}
yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
break;
if (yyisShiftAction (yyaction))
{
- YYDPRINTF ((stderr, "Shifted token %s. ",
+ YYDPRINTF ((stderr, "Shifting token %s, ",
yytokenName (yytoken)));
if (yytoken != YYEOF)
yytoken = YYEMPTY;
yyposn += 1;
yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp);
- if (yystack.yyerrState > 0)
+ if (0 < yystack.yyerrState)
yystack.yyerrState -= 1;
- YYDPRINTF ((stderr, "Now in state #%d\n",
+ YYDPRINTF ((stderr, "Entering state %d\n",
yystack.yytops.yystates[0]->yylrState));
}
else if (yyisErrorAction (yyaction))
[#ifndef YYLTYPE
typedef struct yyltype
{
- int yyfirst_line;
- int yyfirst_column;
- int yylast_line;
- int yylast_column;
+ int first_line;
+ int first_column;
+ int last_line;
+ int last_column;
} yyltype;
# define YYLTYPE yyltype
#endif