# Expansion of $<TYPE>NUM, where the current rule has RULE-LENGTH
# symbols on RHS.
m4_define([b4_rhs_value],
-[yyvsp@<:@m4_eval([$2 - $1])@:>@.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3])])
+[yyvsp@{m4_eval([$2 - $1])@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3])])
# Expansion of @NUM, where the current rule has RULE-LENGTH symbols
# on RHS.
m4_define([b4_rhs_location],
-[yyvsp@<:@m4_eval([$2 - $1])@:>@.yystate.yyloc])
-
-
-
-## ------------------- ##
-## Output file names. ##
-## ------------------- ##
-
-m4_define_default([b4_input_suffix], [.y])
-
-m4_define_default([b4_output_parser_suffix],
-[m4_translit(b4_input_suffix, [yY], [cC])])
-
-m4_define_default([b4_output_parser_name],
-[b4_output_prefix[]b4_output_infix[]b4_output_parser_suffix[]])
-
-
-m4_define_default([b4_output_header_suffix],
-[m4_translit(b4_input_suffix, [yY], [hH])])
-
-m4_define_default([b4_output_header_name],
-[b4_output_prefix[]b4_output_infix[]b4_output_header_suffix[]])
-
-m4_define_default([b4_header_guard],
- [m4_bpatsubst(m4_toupper([BISON_]b4_output_header_name),
- [[^ABCDEFGHIJKLMNOPQRSTUVWXYZ]], [_])])
+[yyvsp@{m4_eval([$2 - $1])@}.yystate.yyloc])
# We do want M4 expansion after # for CPP macros.
m4_changecom()
m4_divert(0)dnl
-#output "b4_output_parser_name"
+@output @output_parser_name@
b4_copyright([Skeleton parser for GLR parsing with Bison], [2002])
[
/* This is the parser code for GLR (Generalized LR) parser. */
[b4_syncline([b4_stype_line], [b4_filename])
typedef union b4_stype yystype;
/* Line __line__ of __file__. */
-b4_syncline([__oline__], [__ofile__])],
+b4_syncline([@oline@], [@ofile@])],
[typedef int yystype;])[
# define YYSTYPE yystype
# define YYSTYPE_IS_TRIVIAL 1
/* Default (constant) values used for initialization for null
right-hand sides. Unlike the standard bison.simple template,
- here we set the default values of the $$ and $@ to zeroed-out
+ here we set the default values of $$ and $@@ to zeroed-out
values. Since the default value of these quantities is undefined,
this behavior is technically correct. */
static YYSTYPE yyval_default;
]b4_post_prologue[
]/* Line __line__ of __file__. */
-b4_syncline([__oline__], [__ofile__])
+b4_syncline([@oline@], [@ofile@])
[
#if ! defined (__cplusplus)
typedef char bool;
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
#endif
-#if ! defined (__GNUC__)
-# define inline
-#endif
-
/* YYFINAL -- State number of the termination state. */
#define YYFINAL ]b4_final_state_number[
/* YYLAST -- Last index in YYTABLE. */
#define YYUNDEFTOK ]b4_undef_token_number[
#define YYMAXUTOK ]b4_user_token_number_max[
-#define YYTRANSLATE(YYX) \
- ((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
+#define YYTRANSLATE(YYX) \
+ ((YYX <= 0) ? YYEOF : \
+ (unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
]b4_check[
};
+/* YYSTOS[STATE-NUM] -- The (internal number of the) accessing
+ symbol of state STATE-NUM. */
+static const ]b4_int_type_for([b4_stos])[ yystos[] =
+{
+ ]b4_stos[
+};
+
\f
/* Prevent warning if -Wmissing-prototypes. */
]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
if (yydebug) \
YYFPRINTF Args; \
} while (0)
+
+]b4_yysymprint_generate([b4_c_ansi_function_def])[
+
+# define YYDSYMPRINT(Args) \
+do { \
+ if (yydebug) \
+ yysymprint Args; \
+} while (0)
+
+# define YYDSYMPRINTF(Title, Token, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title); \
+ yysymprint (stderr, \
+ Token, Value]b4_location_if([, Location])[); \
+ YYFPRINTF (stderr, "\n"); \
+ } \
+} while (0)
+
/* Nonzero means print parse trace. It is left uninitialized so that
multiple parsers can coexist. */
int yydebug;
+
#else /* !YYDEBUG */
+
/* Avoid empty `if' bodies. */
-# define YYDPRINTF(Args) {}
+# define YYDPRINTF(Args) {}
+# define YYDSYMPRINT(Args) {}
+# define YYDSYMPRINTF(Title, Token, Value, Location) {}
+
#endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
/** Perform user action for rule number YYN, with RHS length YYRHSLEN,
* and top stack item YYVSP. YYLVALP points to place to put semantic
* value ($$), and yylocp points to place for location information
- * (@$). Returns yyok for normal return, yyaccept for YYACCEPT,
+ * (@@$). Returns yyok for normal return, yyaccept for YYACCEPT,
* yyerr for YYERROR, yyabort for YYABORT. */
static YYRESULTTAG
yyuserAction (yyRuleNum yyn, int yyrhslen, yyGLRStackItem* yyvsp,
*yyvalp = yyvsp[1-yyrhslen].yystate.yysemantics.yysval;
*yylocp = yyvsp[1-yyrhslen].yystate.yyloc;
}
-# undef yyval
-# define yyval (*yyvalp)
# undef yyerrok
# define yyerrok (yystack->yyerrState = 0)
# undef YYACCEPT
}
return yyok;
-# undef yyval
# undef yyerrok
# undef YYABORT
# undef YYACCEPT
# undef yyclearin
# undef YYRECOVERING
/* Line __line__ of __file__. */
-b4_syncline([__oline__], [__ofile__])
+b4_syncline([@oline@], [@ofile@])
}
\f
[
/* Bison grammar-table manipulation. */
+]b4_yydestruct_generate([b4_c_ansi_function_def])[
+
/** Number of symbols composing the right hand side of rule #RULE. */
static inline int
yyrhsLength (yyRuleNum yyrule)
* have been previously resolved. Set *VALP to the resulting value,
* and *LOCP to the computed location (if any). Return value is as
* for userAction. */
-static inline int
+static inline YYRESULTTAG
yydoAction (yyGLRStack* yystack, int yyk, yyRuleNum yyrule,
YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
{
yy_reduce_print (size_t yyk, yyRuleNum yyrule)
{
int yyi;
- YYDPRINTF ((stderr, "Reducing stack %d by rule %d (line %d),",
+ 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]));
+ YYFPRINTF (stderr, "-> %s\n", yytokenName (yyr1[yyrule]));
}
#endif
yymarkStackDeleted (yystack, yyk);
YYDPRINTF ((stderr, "Merging stack %d into stack %d.\n",
yyk, yyi));
- return 0;
+ return yyok;
}
yyp = yyp->yypred;
}
yystack->yytops.yystates[yyk] = yys;
yyglrShiftDefer (yystack, yyk, yynewLRState, yyposn, yys0, yyrule]b4_pure_args[);
}
- return 0;
+ return yyok;
}
static int
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
- *yytokenp = YYTRANSLATE(yychar);
- YYDPRINTF ((stderr, "Next token is %s\n",
- yytokenName (*yytokenp)));
+ *yytokenp = YYTRANSLATE (yychar);
+ YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp);
}
yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
yysize += strlen (yytokenName (yyx)) + strlen (yyprefix),
yycount += 1, yyprefix = " or ";
yymsg = yyp = (char*) malloc (yysize);
- sprintf (yyp, "parse error, unexpected %s",
- yytokenName (*yytokenp));
+ sprintf (yyp, "parse error, unexpected %s", yytokenName (*yytokenp));
yyp += strlen (yyp);
if (yycount < 5)
{
while (yytrue)
{
if (*yytokenp == YYEOF)
- yyFail (yystack][]b4_lpure_args[, NULL);
+ {
+ /* Now pop stack until we find a state that shifts the
+ error token. */
+ while (yystack->yytops.yystates[0] != NULL)
+ {
+ yyGLRState *yys = yystack->yytops.yystates[0];
+ YYDSYMPRINTF ("Error: popping",
+ yystos[yys->yylrState],
+ &yys->yysemantics.yysval, &yys->yyloc);
+ yydestruct (yystos[yys->yylrState],
+ &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+ yystack->yytops.yystates[0] = yys->yypred;
+ yystack->yynextFree -= 1;
+ yystack->yyspaceLeft += 1;
+ }
+ yyFail (yystack][]b4_lpure_args[, NULL);
+ }
if (*yytokenp != YYEMPTY)
- YYDPRINTF ((stderr, "Discarding token %s\n",
- yytokenName (*yytokenp)));
+ {
+ YYDSYMPRINTF ("Error: discarding", *yytokenp, yylvalp, yyllocp);
+ yydestruct (*yytokenp, yylvalp]b4_location_if([, yyllocp])[);
+ }
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
*yytokenp = YYTRANSLATE (yychar);
- YYDPRINTF ((stderr, "Next token is %s\n", yytokenName (*yytokenp)));
+ YYDSYMPRINTF ("Next token is", *yytokenp, yylvalp, yyllocp);
yyj = yypact[yystack->yytops.yystates[0]->yylrState];
if (yyis_pact_ninf (yyj))
/* Something's not right; we shouldn't be here. */
/* Now pop stack until we find a state that shifts the error token. */
while (yystack->yytops.yystates[0] != NULL)
{
- yyj = yypact[yystack->yytops.yystates[0]->yylrState];
+ yyGLRState *yys = yystack->yytops.yystates[0];
+ yyj = yypact[yys->yylrState];
if (! yyis_pact_ninf (yyj))
{
yyj += YYTERROR;
if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
&& yyisShiftAction (yytable[yyj]))
{
+ YYDPRINTF ((stderr, "Shifting error token, "));
yyglrShift (yystack, 0, yytable[yyj],
- yystack->yytops.yystates[0]->yyposn,
- *yylvalp, yyllocp]b4_user_args[);
+ yys->yyposn, *yylvalp, yyllocp]b4_user_args[);
+ YYDPRINTF ((stderr, "Entering state %d\n",
+ yystack->yytops.yystates[0]->yylrState));
break;
}
}
- yystack->yytops.yystates[0] = yystack->yytops.yystates[0]->yypred;
+ YYDSYMPRINTF ("Error: popping",
+ yystos[yys->yylrState],
+ &yys->yysemantics.yysval, &yys->yyloc);
+ yydestruct (yystos[yys->yylrState],
+ &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+ yystack->yytops.yystates[0] = yys->yypred;
yystack->yynextFree -= 1;
yystack->yyspaceLeft += 1;
}
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
yytoken = YYTRANSLATE (yychar);
- YYDPRINTF ((stderr, "Next token is %s\n",
- yytokenName (yytoken)));
+ YYDSYMPRINTF ("Next token is", yytoken, yylvalp, yyllocp);
}
yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
if (*yyconflicts != 0)
yy_yypstack (yys->yypred);
fprintf (stderr, " -> ");
}
- fprintf (stderr, "%d@%lu", yys->yylrState, (unsigned long) yys->yyposn);
+ fprintf (stderr, "%d@@%lu", yys->yylrState, (unsigned long) yys->yyposn);
}
static void
b4_epilogue
m4_if(b4_defines_flag, 0, [],
-[#output "b4_output_header_name"
+[@output @output_header_name@
b4_copyright([Skeleton parser for GLR parsing with Bison], [2002])
-#ifndef b4_header_guard
-# define b4_header_guard
b4_token_defines(b4_tokens)
[b4_syncline([b4_stype_line], [b4_filename])
typedef union b4_stype yystype;
/* Line __line__ of __file__. */
-b4_syncline([__oline__], [__ofile__])],
+b4_syncline([@oline@], [@ofile@])],
[typedef int yystype;])
# define YYSTYPE yystype
+# define YYSTYPE_IS_TRIVIAL 1
#endif
b4_pure_if([],
m4_if(b4_pure, [0],
[extern YYLTYPE b4_prefix[]lloc;])
])
-#endif /* not b4_header_guard */
])