#define yynerrs b4_prefix[]nerrs
#define yylloc b4_prefix[]lloc])
-b4_token_defines(b4_tokens)
+b4_token_enums(b4_tokens)
/* Copy the first part of user declarations. */
b4_pre_prologue[
# define YYERROR_VERBOSE ]b4_error_verbose[
#endif
+/* Enabling the token table. */
+#ifndef YYTOKEN_TABLE
+# define YYTOKEN_TABLE ]b4_token_table[
+#endif
+
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
]m4_ifdef([b4_stype],
-[b4_syncline([b4_stype_line], [b4_filename])
+[b4_syncline([b4_stype_line], [b4_file_name])
typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
/* Line __line__ of glr.c. */
b4_syncline([@oline@], [@ofile@])],
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
-#include <setjmp.h>
#ifndef YY_
# if YYENABLE_NLS
#define yytrue 1
#define yyfalse 0
+#ifndef YYSETJMP
+# include <setjmp.h>
+# define YYJMP_BUF jmp_buf
+# define YYSETJMP(env) setjmp (env)
+# define YYLONGJMP(env, val) longjmp (env, val)
+#endif
+
/*-----------------.
| GCC extensions. |
`-----------------*/
#ifndef __attribute__
/* This feature is available in gcc versions 2.5 and later. */
-# if !defined (__GNUC__) || __GNUC__ < 2 || \
-(__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+# if (!defined (__GNUC__) || __GNUC__ < 2 \
+ || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__)
# define __attribute__(Spec) /* empty */
-# else
-]b4_location_if([# define YYOPTIONAL_LOC(Name) Name],[
-# if defined (__cplusplus)
-# define YYOPTIONAL_LOC(Name) /* empty */
-# else
-# define YYOPTIONAL_LOC(Name) Name ATTRIBUTE_UNUSED
-# endif])[
# endif
#endif
+]b4_location_if([#define YYOPTIONAL_LOC(Name) Name],[
+#ifdef __cplusplus
+# define YYOPTIONAL_LOC(Name) /* empty */
+#else
+# define YYOPTIONAL_LOC(Name) Name __attribute__ ((__unused__))
+#endif])[
+
#ifndef YYASSERT
# define YYASSERT(condition) ((void) ((condition) || (abort (), 0)))
#endif
-#ifndef ATTRIBUTE_UNUSED
-# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
-#endif
-
/* YYFINAL -- State number of the termination state. */
#define YYFINAL ]b4_final_state_number[
/* YYLAST -- Last index in YYTABLE. */
};
#endif
-#if (YYDEBUG) || YYERROR_VERBOSE
+#if YYDEBUG || YYERROR_VERBOSE || YYTOKEN_TABLE
/* YYTNAME[SYMBOL-NUM] -- String name of the symbol SYMBOL-NUM.
First, the terminals, then, starting at YYNTOKENS, nonterminals. */
static const char *const yytname[] =
YYFPRINTF (stderr, "%s ", Title); \
yysymprint (stderr, \
Type, Value]b4_location_if([, Location])[); \
+ YYFPRINTF (stderr, "\n"); \
} \
} while (0)
int yyrawchar;
])[
yySymbol* yytokenp;
- jmp_buf yyexception_buffer;
+ YYJMP_BUF yyexception_buffer;
yyGLRStackItem* yyitems;
yyGLRStackItem* yynextFree;
size_t yyspaceLeft;
static void yyexpandGLRStack (yyGLRStack* yystack);
+static void yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg)
+ __attribute__ ((__noreturn__));
static void
yyFail (yyGLRStack* yystack]b4_pure_formals[, const char* yymsg)
{
if (yymsg != NULL)
yyerror (]b4_yyerror_args[yymsg);
- longjmp (yystack->yyexception_buffer, 1);
+ YYLONGJMP (yystack->yyexception_buffer, 1);
}
+static void yyMemoryExhausted (yyGLRStack* yystack)
+ __attribute__ ((__noreturn__));
static void
yyMemoryExhausted (yyGLRStack* yystack)
{
- longjmp (yystack->yyexception_buffer, 2);
+ YYLONGJMP (yystack->yyexception_buffer, 2);
}
#if YYDEBUG || YYERROR_VERBOSE
* at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred
* containing the pointer to the next state in the chain. Assumes
* YYLOW1 < YYLOW0. */
-static void yyfillin (yyGLRStackItem *, int, int) ATTRIBUTE_UNUSED;
+static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__));
static void
yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1)
{
YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1.
For convenience, always return YYLOW1. */
static inline int yyfill (yyGLRStackItem *, int *, int, yybool)
- ATTRIBUTE_UNUSED;
+ __attribute__ ((__unused__));
static inline int
yyfill (yyGLRStackItem *yyvsp, int *yylow, int yylow1, yybool yynormal)
{
yyGLRStack* yystack
]b4_user_formals[)
{
- yybool yynormal ATTRIBUTE_UNUSED = (yystack->yysplitPoint == NULL);
+ yybool yynormal __attribute__ ((__unused__)) =
+ (yystack->yysplitPoint == NULL);
int yylow;
# undef yyerrok
]b4_yydestruct_generate([b4_c_ansi_function_def])[
-/** Number of symbols composing the right hand side of rule #RULE. */
+/** Number of symbols composing the right hand side of rule #RULE. */
static inline int
yyrhsLength (yyRuleNum yyrule)
{
return yyr2[yyrule];
}
+static void
+yydestroyGLRState (char const *yymsg, yyGLRState *yys)
+{
+ if (yys->yyresolved)
+ yydestruct (yymsg, yystos[yys->yylrState],
+ &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+ else
+ {
+#if YYDEBUG
+ if (yydebug)
+ {
+ YYFPRINTF (stderr, "%s unresolved ", yymsg);
+ yysymprint (stderr, yystos[yys->yylrState],
+ &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+ YYFPRINTF (stderr, "\n");
+ }
+#endif
+
+ if (yys->yysemantics.yyfirstVal)
+ {
+ yySemanticOption *yyoption = yys->yysemantics.yyfirstVal;
+ yyGLRState *yyrh;
+ int yyn;
+ for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
+ yyn > 0;
+ yyrh = yyrh->yypred, yyn -= 1)
+ yydestroyGLRState (yymsg, yyrh);
+ }
+ }
+}
+
/** Left-hand-side symbol for rule #RULE. */
static inline yySymbol
yylhsNonterm (yyRuleNum yyrule)
yystack->yyerrState = 0;
yynerrs = 0;
yystack->yyspaceLeft = yysize;
- yystack->yynextFree = yystack->yyitems =
+ yystack->yyitems =
(yyGLRStackItem*) YYMALLOC (yysize * sizeof yystack->yynextFree[0]);
+ if (!yystack->yyitems)
+ return yyfalse;
+ yystack->yynextFree = yystack->yyitems;
yystack->yysplitPoint = NULL;
yystack->yylastDeleted = NULL;
- return yyinitStateSet (&yystack->yytops) && yystack->yyitems;
+ return yyinitStateSet (&yystack->yytops);
}
#define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \
}
#endif
+static void yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
+ yyGLRStack* yystack]b4_pure_formals[)
+ __attribute__ ((__noreturn__));
static void
yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1,
yyGLRStack* yystack]b4_pure_formals[)
YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[)
{
yySemanticOption* yybest;
- yySemanticOption* yyp;
+ yySemanticOption** yypp;
yybool yymerge;
yybest = yyoptionList;
yymerge = yyfalse;
- for (yyp = yyoptionList->yynext; yyp != NULL; yyp = yyp->yynext)
+ for (yypp = &yyoptionList->yynext; *yypp != NULL; )
{
+ yySemanticOption* yyp = *yypp;
+
if (yyidenticalOptions (yybest, yyp))
- yymergeOptionSets (yybest, yyp);
+ {
+ yymergeOptionSets (yybest, yyp);
+ *yypp = yyp->yynext;
+ }
else
- switch (yypreference (yybest, yyp))
- {
- case 0:
- yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[);
- break;
- case 1:
- yymerge = yytrue;
- break;
- case 2:
- break;
- case 3:
- yybest = yyp;
- yymerge = yyfalse;
- break;
- }
+ {
+ switch (yypreference (yybest, yyp))
+ {
+ case 0:
+ yyreportAmbiguity (yybest, yyp, yystack]b4_pure_args[);
+ break;
+ case 1:
+ yymerge = yytrue;
+ break;
+ case 2:
+ break;
+ case 3:
+ yybest = yyp;
+ yymerge = yyfalse;
+ break;
+ default:
+ /* This cannot happen so it is not worth a YYASSERT (yyfalse),
+ but some compilers complain if the default case is
+ omitted. */
+ break;
+ }
+ yypp = &yyp->yynext;
+ }
}
if (yymerge)
{
+ yySemanticOption* yyp;
int yyprec = yydprec[yybest->yyrule];
YYCHK (yyresolveAction (yybest, yystack, yyvalp, yylocp]b4_user_args[));
for (yyp = yybest->yynext; yyp != NULL; yyp = yyp->yynext)
yychar = YYLEX;
*yytokenp = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);
- YYDPRINTF ((stderr, "\n"));
}
yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts);
YY_SYMBOL_PRINT ("shifting", *yytokenp, yylvalp, yyllocp);
yyglrShift (yystack, yyk, yyaction, yyposn+1,
*yylvalp, yyllocp);
- YYDPRINTF ((stderr, ", now in state #%d\n",
+ YYDPRINTF ((stderr, "Stack %lu now in state #%d\n",
+ (unsigned long int) yyk,
yystack->yytops.yystates[yyk]->yylrState));
break;
}
yychar = YYLEX;
*yytokenp = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", *yytokenp, yylvalp, yyllocp);
- YYDPRINTF ((stderr, "\n"));
yyj = yypact[yystack->yytops.yystates[0]->yylrState];
if (yyis_pact_ninf (yyj))
return;
YYLLOC_DEFAULT (yyerrloc, yystack->yyerror_range, 2);]])[
YY_SYMBOL_PRINT ("Shifting", yystos[yytable[yyj]],
yylvalp, &yyerrloc);
- YYDPRINTF ((stderr, "\n"));
yyglrShift (yystack, 0, yytable[yyj],
yys->yyposn, *yylvalp, &yyerrloc);
yys = yystack->yytops.yystates[0];
}
}
]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
- yydestruct ("Error: popping",
- yystos[yys->yylrState],
- &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+ yydestroyGLRState ("Error: popping", yys);
yystack->yytops.yystates[0] = yys->yypred;
yystack->yynextFree -= 1;
yystack->yyspaceLeft += 1;
#define YYCHK1(YYE) \
do { \
switch (YYE) { \
- default: \
+ case yyok: \
break; \
case yyabort: \
goto yyabortlab; \
goto yyacceptlab; \
case yyerr: \
goto yyuser_error; \
+ default: \
+ goto yybuglab; \
} \
} while (0)
[
if (! yyinitGLRStack (&yystack, YYINITDEPTH))
goto yyexhaustedlab;
- switch (setjmp (yystack.yyexception_buffer))
+ switch (YYSETJMP (yystack.yyexception_buffer))
{
+ case 0: break;
case 1: goto yyabortlab;
case 2: goto yyexhaustedlab;
+ default: goto yybuglab;
}
yystack.yytokenp = &yytoken;
yyglrShift (&yystack, 0, 0, 0, yylval, &yylloc);
yychar = YYLEX;
yytoken = YYTRANSLATE (yychar);
YY_SYMBOL_PRINT ("Next token is", yytoken, yylvalp, yyllocp);
- YYDPRINTF ((stderr, "\n"));
}
yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts);
if (*yyconflicts != 0)
if (yyisShiftAction (yyaction))
{
YY_SYMBOL_PRINT ("Shifting", yytoken, yylvalp, yyllocp);
- YYDPRINTF ((stderr, "\n"));
if (yytoken != YYEOF)
yytoken = YYEMPTY;
yyposn += 1;
yyresult = 0;
goto yyreturn;
+ yybuglab:
+ YYASSERT (yyfalse);
+ /* Fall through. */
+
yyabortlab:
yyresult = 1;
goto yyreturn;
yyreturn:
if (yytoken != YYEOF && yytoken != YYEMPTY)
- yydestruct ("Error: discarding lookahead",
+ yydestruct ("Cleanup: discarding lookahead",
yytoken, yylvalp]b4_location_if([, yyllocp])[);
- /* Now pop stack until empty, destroying its entries as we go. */
- {
- yyGLRState** yystates = yystack.yytops.yystates;
- if (yystates)
- while (yystates[0])
- {
- yyGLRState *yys = yystates[0];
+ /* If the stack is well-formed, pop the stack until it is empty,
+ destroying its entries as we go. But free the stack regardless
+ of whether it is well-formed. */
+ if (yystack.yyitems)
+ {
+ yyGLRState** yystates = yystack.yytops.yystates;
+ if (yystates)
+ while (yystates[0])
+ {
+ yyGLRState *yys = yystates[0];
]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
-)[ yydestruct ("Error: popping",
- yystos[yys->yylrState],
- &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
- yystates[0] = yys->yypred;
- yystack.yynextFree -= 1;
- yystack.yyspaceLeft += 1;
- }
- }
+)[ yydestroyGLRState ("Cleanup: popping", yys);
+ yystates[0] = yys->yypred;
+ yystack.yynextFree -= 1;
+ yystack.yyspaceLeft += 1;
+ }
+ yyfreeGLRStack (&yystack);
+ }
- yyfreeGLRStack (&yystack);
return yyresult;
}
/* DEBUGGING ONLY */
#ifdef YYDEBUG
-static void yypstack (yyGLRStack* yystack, size_t yyk) ATTRIBUTE_UNUSED;
-static void yypdumpstack (yyGLRStack* yystack) ATTRIBUTE_UNUSED;
+static void yypstack (yyGLRStack* yystack, size_t yyk)
+ __attribute__ ((__unused__));
+static void yypdumpstack (yyGLRStack* yystack) __attribute__ ((__unused__));
static void
yy_yypstack (yyGLRState* yys)
b4_copyright([Skeleton parser for GLR parsing with Bison],
[2002, 2003, 2004, 2005])
-b4_token_defines(b4_tokens)
+b4_token_enums(b4_tokens)
#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED)
m4_ifdef([b4_stype],
-[b4_syncline([b4_stype_line], [b4_filename])
+[b4_syncline([b4_stype_line], [b4_file_name])
typedef union m4_bregexp(b4_stype, [^{], [YYSTYPE ])b4_stype YYSTYPE;
/* Line __line__ of glr.c. */
b4_syncline([@oline@], [@ofile@])],