X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/48b16bbc0492820cf1fdb683b289c77f4cdadb3d..422494834c997d34b85f31f22bcc54f8859876c4:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 6faa86d3..f427cfa9 100644 --- a/data/glr.c +++ b/data/glr.c @@ -34,6 +34,16 @@ m4_define_default([b4_stack_depth_init], [200]) ## ------------------------ ## +# b4_user_formals +# --------------- +# The possible parse-params formal arguments preceded by a comma. +# +# This is not shared with yacc.c in c.m4 because GLR relies on ISO C +# formal argument declarations. +m4_define([b4_user_formals], +[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])]) + + # b4_lex_param # ------------ # Accumule in b4_lex_param all the yylex arguments. @@ -44,15 +54,10 @@ b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl m4_ifdef([b4_lex_param], [, ]b4_lex_param))) -# b4_user_formals -# --------------- -m4_define([b4_user_formals], -[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])]) - - # b4_yyerror_args # --------------- -# Arguments passed to yyerror: user args plus yylloc. +# Optional effective arguments passed to yyerror: user args plus yylloc, and +# a trailing comma. m4_define([b4_yyerror_args], [b4_pure_if([b4_location_if([yylocp, ])])dnl m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) @@ -68,18 +73,11 @@ m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])]) # b4_pure_args # ------------ -# Arguments needed by yyerror: user args plus yylloc. +# Same as b4_yyerror_args, but with a leading comma. m4_define([b4_pure_args], [b4_pure_if([b4_location_if([, yylocp])])[]b4_user_args]) -# b4_pure_formals -# --------------- -# Arguments passed to yyerror: user formals plus yyllocp. -m4_define([b4_pure_formals], -[b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals]) - - # b4_lpure_args # ------------- # Same as above, but on the look-ahead, hence yyllocp instead of yylocp. @@ -87,6 +85,13 @@ m4_define([b4_lpure_args], [b4_pure_if([b4_location_if([, yyllocp])])[]b4_user_args]) +# b4_pure_formals +# --------------- +# Arguments passed to yyerror: user formals plus yyllocp. +m4_define([b4_pure_formals], +[b4_pure_if([b4_location_if([, YYLTYPE *yylocp])])[]b4_user_formals]) + + # b4_lpure_formals # ---------------- # Same as above, but on the look-ahead, hence yyllocp instead of yylocp. @@ -111,7 +116,7 @@ m4_define([b4_lhs_value], # Expansion of $NUM, where the current rule has RULE-LENGTH # symbols on RHS. m4_define([b4_rhs_value], -[(((yyGLRStackItem const *)yyvsp)@{YYFILL (m4_eval([$2 - $1]))@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3]))]) +[(((yyGLRStackItem const *)yyvsp)@{YYFILL ($2 - $1)@}.yystate.yysemantics.yysval[]m4_ifval([$3], [.$3]))]) @@ -131,7 +136,13 @@ m4_define([b4_lhs_location], # Expansion of @NUM, where the current rule has RULE-LENGTH symbols # on RHS. m4_define([b4_rhs_location], -[(((yyGLRStackItem const *)yyvsp)@{YYFILL (m4_eval([$2 - $1]))@}.yystate.yyloc)]) +[(((yyGLRStackItem const *)yyvsp)@{YYFILL ($2 - $1)@}.yystate.yyloc)]) + + + +## -------------- ## +## Output files. ## +## -------------- ## # We do want M4 expansion after # for CPP macros. m4_changecom() @@ -143,6 +154,7 @@ b4_copyright([Skeleton parser for GLR parsing with Bison], /* This is the parser code for GLR (Generalized LR) parser. */ ]b4_identification + m4_if(b4_prefix[], [yy], [], [/* Substitute the variable and function names. */ #define yyparse b4_prefix[]parse @@ -152,30 +164,17 @@ m4_if(b4_prefix[], [yy], [], #define yychar b4_prefix[]char #define yydebug b4_prefix[]debug #define yynerrs b4_prefix[]nerrs -#define yylloc b4_prefix[]lloc]) +#define yylloc b4_prefix[]lloc]) -b4_token_defines(b4_tokens) +dnl # b4_shared_declarations +dnl # ---------------------- +dnl # Declaration that might either go into the header (if --defines) +dnl # or open coded in the parser body. +m4_define([b4_shared_declarations], +[b4_token_enums(b4_tokens)[ /* Copy the first part of user declarations. */ -b4_pre_prologue[ - -/* Enabling traces. */ -#ifndef YYDEBUG -# define YYDEBUG ]b4_debug[ -#endif - -/* Enabling verbose error messages. */ -#ifdef YYERROR_VERBOSE -# undef YYERROR_VERBOSE -# define YYERROR_VERBOSE 1 -#else -# define YYERROR_VERBOSE ]b4_error_verbose[ -#endif - -/* Enabling the token table. */ -#ifndef YYTOKEN_TABLE -# define YYTOKEN_TABLE ]b4_token_table[ -#endif +]b4_pre_prologue[ #if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) ]m4_ifdef([b4_stype], @@ -203,6 +202,29 @@ typedef struct YYLTYPE # define YYLTYPE_IS_DECLARED 1 # define YYLTYPE_IS_TRIVIAL 1 #endif +]]) + +m4_if(b4_defines_flag, 0, + [b4_shared_declarations], + [#include @output_header_name@])[ + +/* Enabling traces. */ +#ifndef YYDEBUG +# define YYDEBUG ]b4_debug[ +#endif + +/* Enabling verbose error messages. */ +#ifdef YYERROR_VERBOSE +# undef YYERROR_VERBOSE +# define YYERROR_VERBOSE 1 +#else +# define YYERROR_VERBOSE ]b4_error_verbose[ +#endif + +/* Enabling the token table. */ +#ifndef YYTOKEN_TABLE +# define YYTOKEN_TABLE ]b4_token_table[ +#endif /* Default (constant) value used for initialization for null right-hand sides. Unlike the standard yacc.c template, @@ -221,7 +243,6 @@ b4_syncline([@oline@], [@ofile@]) #include #include #include -#include #ifndef YY_ # if YYENABLE_NLS @@ -235,6 +256,9 @@ b4_syncline([@oline@], [@ofile@]) # endif #endif +/* Suppress unused-variable warnings by "using" E. */ +#define YYUSE(e) do {;} while (/*CONSTCOND*/ yyfalse && (e)) + #ifndef YYFREE # define YYFREE free #endif @@ -255,6 +279,13 @@ b4_syncline([@oline@], [@ofile@]) #define yytrue 1 #define yyfalse 0 +#ifndef YYSETJMP +# include +# define YYJMP_BUF jmp_buf +# define YYSETJMP(env) setjmp (env) +# define YYLONGJMP(env, val) longjmp (env, val) +#endif + /*-----------------. | GCC extensions. | `-----------------*/ @@ -464,7 +495,7 @@ static const ]b4_int_type_for([b4_stos])[ yystos[] = (Current).first_column = (Current).last_column = \ YYRHSLOC (Rhs, 0).last_column; \ } \ - while (0) + while (/*CONSTCOND*/ 0) /* YY_LOCATION_PRINT -- Print the location on the stream. This macro was not mandated originally: define only if we know @@ -509,7 +540,7 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; #define YYCHK(YYE) \ do { YYRESULTTAG yyflag = YYE; if (yyflag != yyok) return yyflag; } \ - while (0) + while (/*CONSTCOND*/ 0) #if YYDEBUG @@ -521,20 +552,20 @@ typedef enum { yyok, yyaccept, yyabort, yyerr } YYRESULTTAG; do { \ if (yydebug) \ YYFPRINTF Args; \ -} while (0) +} while (/*CONSTCOND*/ 0) ]b4_yysymprint_generate([b4_c_ansi_function_def])[ -# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ -do { \ - if (yydebug) \ - { \ - YYFPRINTF (stderr, "%s ", Title); \ - yysymprint (stderr, \ - Type, Value]b4_location_if([, Location])[); \ - YYFPRINTF (stderr, "\n"); \ - } \ -} while (0) +# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \ +do { \ + if (yydebug) \ + { \ + YYFPRINTF (stderr, "%s ", Title); \ + yysymprint (stderr, \ + Type, Value]b4_location_if([, Location])[]b4_user_args[); \ + YYFPRINTF (stderr, "\n"); \ + } \ +} while (/*CONSTCOND*/ 0) /* Nonzero means print parse trace. It is left uninitialized so that multiple parsers can coexist. */ @@ -580,6 +611,21 @@ int yydebug; # endif #endif +#if YYSTACKEXPANDABLE +# define YY_RESERVE_GLRSTACK(Yystack) \ + do { \ + if (Yystack->yyspaceLeft < YYHEADROOM) \ + yyexpandGLRStack (Yystack); \ + } while (/*CONSTCOND*/ 0) +#else +# define YY_RESERVE_GLRSTACK(Yystack) \ + do { \ + if (Yystack->yyspaceLeft < YYHEADROOM) \ + yyMemoryExhausted (Yystack); \ + } while (/*CONSTCOND*/ 0) +#endif + + #if YYERROR_VERBOSE # ifndef yystpcpy @@ -728,7 +774,7 @@ struct yyGLRStack { int yyrawchar; ])[ yySymbol* yytokenp; - jmp_buf yyexception_buffer; + YYJMP_BUF yyexception_buffer; yyGLRStackItem* yyitems; yyGLRStackItem* yynextFree; size_t yyspaceLeft; @@ -746,7 +792,7 @@ 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) @@ -754,7 +800,7 @@ static void yyMemoryExhausted (yyGLRStack* yystack) static void yyMemoryExhausted (yyGLRStack* yystack) { - longjmp (yystack->yyexception_buffer, 2); + YYLONGJMP (yystack->yyexception_buffer, 2); } #if YYDEBUG || YYERROR_VERBOSE @@ -771,8 +817,7 @@ yytokenName (yySymbol yytoken) /** Fill in YYVSP[YYLOW1 .. YYLOW0-1] from the chain of states starting * at YYVSP[YYLOW0].yystate.yypred. Leaves YYVSP[YYLOW1].yystate.yypred - * containing the pointer to the next state in the chain. Assumes - * YYLOW1 < YYLOW0. */ + * containing the pointer to the next state in the chain. */ static void yyfillin (yyGLRStackItem *, int, int) __attribute__ ((__unused__)); static void yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) @@ -791,8 +836,8 @@ yyfillin (yyGLRStackItem *yyvsp, int yylow0, int yylow1) } /* Do nothing if YYNORMAL or if *YYLOW <= YYLOW1. Otherwise, fill in - YYVSP[YYLOW1 .. *YYLOW-1] as in yyfillin and set *YYLOW = YYLOW1. - For convenience, always return 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__)); static inline int @@ -871,9 +916,8 @@ b4_syncline([@oline@], [@ofile@]) static void yyuserMerge (int yyn, YYSTYPE* yy0, YYSTYPE* yy1) { - /* `Use' the arguments. */ - (void) yy0; - (void) yy1; + YYUSE (yy0); + YYUSE (yy1); switch (yyn) { @@ -894,11 +938,11 @@ yyrhsLength (yyRuleNum yyrule) } static void -yydestroyGLRState (char const *yymsg, yyGLRState *yys) +yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[) { if (yys->yyresolved) yydestruct (yymsg, yystos[yys->yylrState], - &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); + &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[); else { #if YYDEBUG @@ -906,7 +950,7 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys) { YYFPRINTF (stderr, "%s unresolved ", yymsg); yysymprint (stderr, yystos[yys->yylrState], - &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[); + &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[]b4_user_args[); YYFPRINTF (stderr, "\n"); } #endif @@ -914,12 +958,12 @@ yydestroyGLRState (char const *yymsg, yyGLRState *yys) if (yys->yysemantics.yyfirstVal) { yySemanticOption *yyoption = yys->yysemantics.yyfirstVal; - yyGLRState *yyrhs; + yyGLRState *yyrh; int yyn; - for (yyrhs = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); + for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule); yyn > 0; - yyrhs = yyrhs->yypred, yyn -= 1) - yydestroyGLRState (yymsg, yyrhs); + yyrh = yyrh->yypred, yyn -= 1) + yydestroyGLRState (yymsg, yyrh]b4_user_args[); } } } @@ -932,9 +976,9 @@ yylhsNonterm (yyRuleNum yyrule) } #define yyis_pact_ninf(yystate) \ - ]m4_if(m4_eval(b4_pact_ninf < b4_pact_min), 1, - 0, - ((yystate) == YYPACT_NINF))[ + ]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). */ @@ -952,9 +996,9 @@ yydefaultAction (yyStateNum yystate) } #define yyis_table_ninf(yytable_value) \ - ]m4_if(m4_eval(b4_table_ninf < b4_table_min), 1, - 0, - ((yytable_value) == YYTABLE_NINF))[ + ]m4_if(m4_eval(b4_table_ninf < b4_table_min), [1], + [0], + [((yytable_value) == YYTABLE_NINF)])[ /** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. * Result R means @@ -1011,21 +1055,32 @@ yyisErrorAction (int yyaction) /* GLRStates */ +/** Return a fresh GLRStackItem. Callers should call + * YY_RESERVE_GLRSTACK afterwards to make sure there is sufficient + * headroom. */ + +static inline yyGLRStackItem* +yynewGLRStackItem (yyGLRStack* yystack, yybool yyisState) +{ + yyGLRStackItem* yynewItem = yystack->yynextFree; + yystack->yyspaceLeft -= 1; + yystack->yynextFree += 1; + yynewItem->yystate.yyisState = yyisState; + return yynewItem; +} + static void yyaddDeferredAction (yyGLRStack* yystack, yyGLRState* yystate, yyGLRState* rhs, yyRuleNum yyrule) { - yySemanticOption* yynewItem; - yynewItem = &yystack->yynextFree->yyoption; - yystack->yyspaceLeft -= 1; - yystack->yynextFree += 1; - yynewItem->yyisState = yyfalse; - yynewItem->yystate = rhs; - yynewItem->yyrule = yyrule; - yynewItem->yynext = yystate->yysemantics.yyfirstVal; - yystate->yysemantics.yyfirstVal = yynewItem; - if (yystack->yyspaceLeft < YYHEADROOM) - yyexpandGLRStack (yystack); + yySemanticOption* yynewOption = + &yynewGLRStackItem (yystack, yyfalse)->yyoption; + yynewOption->yystate = rhs; + yynewOption->yyrule = yyrule; + yynewOption->yynext = yystate->yysemantics.yyfirstVal; + yystate->yysemantics.yyfirstVal = yynewOption; + + YY_RESERVE_GLRSTACK (yystack); } /* GLRStacks */ @@ -1066,7 +1121,9 @@ yyinitGLRStack (yyGLRStack* yystack, size_t yysize) return yyinitStateSet (&yystack->yytops); } -#define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ + +#if YYSTACKEXPANDABLE +# define YYRELOC(YYFROMITEMS,YYTOITEMS,YYX,YYTYPE) \ &((YYTOITEMS) - ((YYFROMITEMS) - (yyGLRStackItem*) (YYX)))->YYTYPE /** If STACK is expandable, extend it. WARNING: Pointers into the @@ -1077,7 +1134,6 @@ yyinitGLRStack (yyGLRStack* yystack, size_t yysize) static void yyexpandGLRStack (yyGLRStack* yystack) { -#if YYSTACKEXPANDABLE yyGLRStackItem* yynewItems; yyGLRStackItem* yyp0, *yyp1; size_t yysize, yynewSize; @@ -1130,11 +1186,8 @@ yyexpandGLRStack (yyGLRStack* yystack) yystack->yyitems = yynewItems; yystack->yynextFree = yynewItems + yysize; yystack->yyspaceLeft = yynewSize - yysize; - -#else - yyMemoryExhausted (yystack); -#endif } +#endif static void yyfreeGLRStack (yyGLRStack* yystack) @@ -1212,21 +1265,17 @@ yyglrShift (yyGLRStack* yystack, size_t yyk, yyStateNum yylrState, size_t yyposn, YYSTYPE yysval, YYLTYPE* yylocp) { - yyGLRStackItem* yynewItem; + yyGLRState* yynewState = &yynewGLRStackItem (yystack, yytrue)->yystate; - yynewItem = yystack->yynextFree; - yystack->yynextFree += 1; - yystack->yyspaceLeft -= 1; - yynewItem->yystate.yyisState = yytrue; - yynewItem->yystate.yylrState = yylrState; - yynewItem->yystate.yyposn = yyposn; - yynewItem->yystate.yyresolved = yytrue; - yynewItem->yystate.yypred = yystack->yytops.yystates[yyk]; - yystack->yytops.yystates[yyk] = &yynewItem->yystate; - yynewItem->yystate.yysemantics.yysval = yysval; - yynewItem->yystate.yyloc = *yylocp; - if (yystack->yyspaceLeft < YYHEADROOM) - yyexpandGLRStack (yystack); + yynewState->yylrState = yylrState; + yynewState->yyposn = yyposn; + yynewState->yyresolved = yytrue; + yynewState->yypred = yystack->yytops.yystates[yyk]; + yynewState->yysemantics.yysval = yysval; + yynewState->yyloc = *yylocp; + yystack->yytops.yystates[yyk] = yynewState; + + YY_RESERVE_GLRSTACK (yystack); } /** Shift stack #K of YYSTACK, to a new state corresponding to LR @@ -1236,19 +1285,17 @@ static inline void yyglrShiftDefer (yyGLRStack* yystack, size_t yyk, yyStateNum yylrState, size_t yyposn, yyGLRState* rhs, yyRuleNum yyrule) { - yyGLRStackItem* yynewItem; + yyGLRState* yynewState = &yynewGLRStackItem (yystack, yytrue)->yystate; - yynewItem = yystack->yynextFree; - yynewItem->yystate.yyisState = yytrue; - yynewItem->yystate.yylrState = yylrState; - yynewItem->yystate.yyposn = yyposn; - yynewItem->yystate.yyresolved = yyfalse; - yynewItem->yystate.yypred = yystack->yytops.yystates[yyk]; - yynewItem->yystate.yysemantics.yyfirstVal = NULL; - yystack->yytops.yystates[yyk] = &yynewItem->yystate; - yystack->yynextFree += 1; - yystack->yyspaceLeft -= 1; - yyaddDeferredAction (yystack, &yynewItem->yystate, rhs, yyrule); + yynewState->yylrState = yylrState; + yynewState->yyposn = yyposn; + yynewState->yyresolved = yyfalse; + yynewState->yypred = yystack->yytops.yystates[yyk]; + yynewState->yysemantics.yyfirstVal = NULL; + yystack->yytops.yystates[yyk] = yynewState; + + /* Invokes YY_RESERVE_GLRSTACK. */ + yyaddDeferredAction (yystack, yynewState, rhs, yyrule); } /** Pop the symbols consumed by reduction #RULE from the top of stack @@ -1276,11 +1323,18 @@ yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, } else { + /* At present, doAction is never called in nondeterministic + * mode, so this branch is never taken. It is here in + * anticipation of a future feature that will allow immediate + * evaluation of selected actions in nondeterministic mode. */ int yyi; yyGLRState* yys; yyGLRStackItem yyrhsVals[YYMAXRHS + YYMAXLEFT + 1]; yys = yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred - = yystack->yytops.yystates[yyk]; + = yystack->yytops.yystates[yyk];]b4_location_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yys->yyloc;]])[ for (yyi = 0; yyi < yynrhs; yyi += 1) { yys = yys->yypred; @@ -1294,29 +1348,42 @@ yydoAction (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, } #if !YYDEBUG -# define YY_REDUCE_PRINT(K, Rule) +# define YY_REDUCE_PRINT(Args) #else -# define YY_REDUCE_PRINT(K, Rule) \ +# define YY_REDUCE_PRINT(Args) \ do { \ if (yydebug) \ - yy_reduce_print (K, Rule); \ -} while (0) + yy_reduce_print Args; \ +} while (/*CONSTCOND*/ 0) /*----------------------------------------------------------. | Report that the RULE is going to be reduced on stack #K. | `----------------------------------------------------------*/ static inline void -yy_reduce_print (size_t yyk, yyRuleNum yyrule) +yy_reduce_print (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, + YYSTYPE* yyvalp, YYLTYPE* yylocp]b4_user_formals[) { + int yynrhs = yyrhsLength (yyrule); + yybool yynormal __attribute__ ((__unused__)) = + (yystack->yysplitPoint == NULL); + yyGLRStackItem* yyvsp = (yyGLRStackItem*) yystack->yytops.yystates[yyk]; + int yylow = 1; int yyi; - YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu), ", + YYFPRINTF (stderr, "Reducing stack %lu by rule %d (line %lu):\n", (unsigned long int) yyk, yyrule - 1, (unsigned long int) 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])); + //for (yyi = yyprhs[yyrule]; 0 <= yyrhs[yyi]; yyi++) + for (yyi = 0; yyi < yynrhs; yyi++) + { + fprintf (stderr, " $%d = ", yyi); + yysymprint (stderr, yyrhs[yyprhs[yyrule] + yyi], + &]b4_rhs_value(yynrhs, yyi)[ + ]b4_location_if([, &]b4_rhs_location(yynrhs, yyi))[]dnl + b4_user_args[); + fprintf (stderr, "\n"); + } } #endif @@ -1342,8 +1409,9 @@ yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, YYSTYPE yysval; YYLTYPE yyloc; - YY_REDUCE_PRINT (yyk, yyrule); + YY_REDUCE_PRINT ((yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc]b4_user_args[)); + YY_SYMBOL_PRINT ("-> $$ =", yyr1[yyrule], &yysval, &yyloc); yyglrShift (yystack, yyk, yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState, yylhsNonterm (yyrule)), @@ -1554,7 +1622,10 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack, yynrhs = yyrhsLength (yyopt->yyrule); YYCHK (yyresolveStates (yyopt->yystate, yynrhs, yystack]b4_user_args[)); - yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate; + yyrhsVals[YYMAXRHS + YYMAXLEFT].yystate.yypred = yyopt->yystate;]b4_location_if([[ + if (yynrhs == 0) + /* Set default location. */ + yyrhsVals[YYMAXRHS + YYMAXLEFT - 1].yystate.yyloc = yyopt->yystate->yyloc;]])[ return yyuserAction (yyopt->yyrule, yynrhs, yyrhsVals + YYMAXRHS + YYMAXLEFT - 1, yyvalp, yylocp, yystack]b4_user_args[); @@ -1615,9 +1686,8 @@ static void yyreportAmbiguity (yySemanticOption* yyx0, yySemanticOption* yyx1, yyGLRStack* yystack]b4_pure_formals[) { - /* `Unused' warnings. */ - (void) yyx0; - (void) yyx1; + YYUSE (yyx0); + YYUSE (yyx1); #if YYDEBUG YYFPRINTF (stderr, "Ambiguity detected.\n"); @@ -1668,6 +1738,11 @@ yyresolveValue (yySemanticOption* yyoptionList, yyGLRStack* yystack, 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; } @@ -1825,9 +1900,8 @@ static void yyreportSyntaxError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp]b4_user_formals[) { - /* `Unused' warnings. */ - (void) yylvalp; - (void) yyllocp; + YYUSE (yylvalp); + YYUSE (yyllocp); if (yystack->yyerrState == 0) { @@ -1957,7 +2031,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack, yyerror_range[2].yystate.yyloc = *yyllocp; YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[ yydestruct ("Error: discarding", - *yytokenp, yylvalp]b4_location_if([, yyllocp])[); + *yytokenp, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[); } YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; @@ -2012,7 +2086,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack, } } ]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[ - yydestroyGLRState ("Error: popping", yys); + yydestroyGLRState ("Error: popping", yys]b4_user_args[); yystack->yytops.yystates[0] = yys->yypred; yystack->yynextFree -= 1; yystack->yyspaceLeft += 1; @@ -2024,7 +2098,7 @@ yyrecoverSyntaxError (yyGLRStack* yystack, #define YYCHK1(YYE) \ do { \ switch (YYE) { \ - default: \ + case yyok: \ break; \ case yyabort: \ goto yyabortlab; \ @@ -2032,8 +2106,10 @@ yyrecoverSyntaxError (yyGLRStack* yystack, goto yyacceptlab; \ case yyerr: \ goto yyuser_error; \ + default: \ + goto yybuglab; \ } \ - } while (0) + } while (/*CONSTCOND*/ 0) /*----------. @@ -2079,10 +2155,12 @@ b4_syncline([@oline@], [@ofile@])])dnl [ 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); @@ -2187,6 +2265,10 @@ b4_syncline([@oline@], [@ofile@])])dnl yyresult = 0; goto yyreturn; + yybuglab: + YYASSERT (yyfalse); + /* Fall through. */ + yyabortlab: yyresult = 1; goto yyreturn; @@ -2199,7 +2281,7 @@ b4_syncline([@oline@], [@ofile@])])dnl yyreturn: if (yytoken != YYEOF && yytoken != YYEMPTY) yydestruct ("Cleanup: discarding lookahead", - yytoken, yylvalp]b4_location_if([, yyllocp])[); + yytoken, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[); /* If the stack is well-formed, pop the stack until it is empty, destroying its entries as we go. But free the stack regardless @@ -2212,7 +2294,7 @@ b4_syncline([@oline@], [@ofile@])])dnl { yyGLRState *yys = yystates[0]; ]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]] -)[ yydestroyGLRState ("Cleanup: popping", yys); +)[ yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[); yystates[0] = yys->yypred; yystack.yynextFree -= 1; yystack.yyspaceLeft += 1; @@ -2300,39 +2382,11 @@ b4_epilogue m4_if(b4_defines_flag, 0, [], [@output @output_header_name@ b4_copyright([Skeleton parser for GLR parsing with Bison], - [2002, 2003, 2004, 2005]) + [2002, 2003, 2004, 2005]) -b4_token_defines(b4_tokens) +b4_shared_declarations -#if ! defined (YYSTYPE) && ! defined (YYSTYPE_IS_DECLARED) -m4_ifdef([b4_stype], -[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@])], -[typedef int YYSTYPE;]) -# define YYSTYPE_IS_DECLARED 1 -# define YYSTYPE_IS_TRIVIAL 1 -#endif - -b4_pure_if([], -[extern YYSTYPE b4_prefix[]lval;]) - -#if ! defined (YYLTYPE) && ! defined (YYLTYPE_IS_DECLARED) -typedef struct YYLTYPE -{ -b4_location_if([ - int first_line; - int first_column; - int last_line; - int last_column; -],[ - char yydummy; -]) -} YYLTYPE; -# define YYLTYPE_IS_DECLARED 1 -# define YYLTYPE_IS_TRIVIAL 1 -#endif +extern YYSTYPE b4_prefix[]lval; b4_location_if([b4_pure_if([], [extern YYLTYPE b4_prefix[]lloc;])