[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
+# b4_yyerror_args
+# ---------------
+# Arguments passed to yyerror: user args plus yylloc.
+m4_define([b4_yyerror_args],
+[b4_pure_if([b4_location_if([yylocp, ])])dnl
+m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
+
+
+# b4_lyyerror_args
+# ----------------
+# Same as above, but on the lookahead, hence yyllocp instead of yylocp.
+m4_define([b4_lyyerror_args],
+[b4_pure_if([b4_location_if([yyllocp, ])])dnl
+m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
+
+
# b4_pure_args
# ------------
-# Arguments passed to yyerror: user args plus yylloc.
+# Arguments needed by yyerror: user args plus yylloc.
m4_define([b4_pure_args],
[b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args])
# 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. */
#ifndef YYSTYPE
]m4_ifdef([b4_stype],
-[#line b4_stype_line "b4_filename"
+[b4_syncline([b4_stype_line], [b4_filename])
typedef union b4_stype yystype;
/* Line __line__ of __file__. */
-#line __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__. */
-#line __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)
+
/* 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) {}
+
#endif /* !YYDEBUG */
/* YYINITDEPTH -- initial size of the parser's stacks. */
va_start (yyap, yyformat);
yystack->yyerrflag = 1;
vsprintf (yymsg, yyformat, yyap);
- yyerror (yymsg]b4_pure_args[);
+ yyerror (]b4_yyerror_args[yymsg);
}
longjmp (yystack->yyexception_buffer, 1);
}
/** 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
# undef YYBACKUP
# define YYBACKUP(Token, Value) \
do { \
- yyerror ("syntax error: cannot back up"]b4_pure_args[); \
+ yyerror (]b4_yyerror_args["syntax error: cannot back up"); \
YYERROR; \
} while (0)
}
return yyok;
-# undef yyval
# undef yyerrok
# undef YYABORT
# undef YYACCEPT
# undef yyclearin
# undef YYRECOVERING
/* Line __line__ of __file__. */
-#line __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)
return yyr1[yyrule];
}
+#define yyis_pact_ninf(yystate) \
+ ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1,
+ 0,
+ ((yystate) == YYPACT_NINF))[
+
/** True iff LR state STATE has only a default reduction (regardless
* of token). */
static inline bool
yyisDefaultedState (yyStateNum yystate)
{
- return yypact[yystate] == YYPACT_NINF;
+ return yyis_pact_ninf (yypact[yystate]);
}
/** The default reduction for STATE, assuming it has one. */
return yydefact[yystate];
}
+#define yyis_table_ninf(yyindex) \
+ ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1,
+ 0,
+ ((yyindex) == YYTABLE_NINF))[
+
/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN.
* Result R means
* R < 0: Reduce on rule -R.
*yyaction = -yydefact[yystate];
*yyconflicts = yyconfl;
}
- else if (yytable[yyindex] != YYTABLE_NINF)
+ else if (! yyis_table_ninf (yyindex))
{
*yyaction = yytable[yyindex];
*yyconflicts = yyconfl + yyconflp[yyindex];
{
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
- *yytokenp = YYTRANSLATE(yychar);
+ *yytokenp = YYTRANSLATE (yychar);
YYDPRINTF ((stderr, "Next token is %s\n",
yytokenName (*yytokenp)));
}
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)
{
yyprefix = " or ";
}
}
- yyerror (yymsg]b4_lpure_args[);
+ yyerror (]b4_lyyerror_args[yymsg);
free (yymsg);
}
else
#endif
- yyerror ("parse error"]b4_lpure_args[);
+ yyerror (]b4_lyyerror_args["parse error");
yynerrs += 1;
}
}
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];
+ YYDPRINTF ((stderr, "Error: popping "));
+ YYDSYMPRINT ((stderr,
+ yystos[yys->yylrState],
+ &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[));
+ YYDPRINTF ((stderr, "\n"));
+ 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)));
+ {
+ YYDPRINTF ((stderr, "Discarding token %s\n",
+ yytokenName (*yytokenp)));
+ 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)));
yyj = yypact[yystack->yytops.yystates[0]->yylrState];
- if (yyj == YYPACT_NINF)
+ if (yyis_pact_ninf (yyj))
/* Something's not right; we shouldn't be here. */
yyFail (yystack][]b4_lpure_args[, NULL);
yyj += *yytokenp;
if (yydefact[yystack->yytops.yystates[0]->yylrState] != 0)
return;
}
- else if (yytable[yyj] != 0 && yytable[yyj] != YYTABLE_NINF)
+ else if (yytable[yyj] != 0 && ! yyis_table_ninf (yytable[yyj]))
return;
}
/* 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] + YYTERROR;
- if (yyj != YYPACT_NINF + YYTERROR && yyj >= 0 && yyj <= YYLAST &&
- yycheck[yyj] == YYTERROR && yyisShiftAction (yytable[yyj]))
+ yyGLRState *yys = yystack->yytops.yystates[0];
+ yyj = yypact[yys->yylrState];
+ if (! yyis_pact_ninf (yyj))
{
- yyglrShift (yystack, 0, yytable[yyj],
- yystack->yytops.yystates[0]->yyposn,
- *yylvalp, yyllocp]b4_user_args[);
- break;
+ yyj += YYTERROR;
+ if (0 <= yyj && yyj <= YYLAST && yycheck[yyj] == YYTERROR
+ && yyisShiftAction (yytable[yyj]))
+ {
+ YYDPRINTF ((stderr, "Shifting error token, "));
+ yyglrShift (yystack, 0, yytable[yyj],
+ yys->yyposn, *yylvalp, yyllocp]b4_user_args[);
+ break;
+ }
}
- yystack->yytops.yystates[0] = yystack->yytops.yystates[0]->yypred;
+ YYDPRINTF ((stderr, "Error: popping "));
+ YYDSYMPRINT ((stderr,
+ yystos[yys->yylrState],
+ &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[));
+ YYDPRINTF ((stderr, "\n"));
+ yydestruct (yystos[yys->yylrState],
+ &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+ yystack->yytops.yystates[0] = yys->yypred;
yystack->yynextFree -= 1;
yystack->yyspaceLeft += 1;
}
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)
#ifndef YYSTYPE
m4_ifdef([b4_stype],
-[#line b4_stype_line "b4_filename"
+[b4_syncline([b4_stype_line], [b4_filename])
typedef union b4_stype yystype;
/* Line __line__ of __file__. */
-#line __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 */
])