X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/ae952af2272fd49967349ca7280fec8c3937fb0f..455671735e6f4e9712c2f5ac1bc153b07b33e67b:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 13fd2ff2..e67573b6 100644 --- a/data/glr.c +++ b/data/glr.c @@ -1803,6 +1803,57 @@ yyreportAmbiguity (yySemanticOption* yyx0, return yyabort; } +/** Starting at and including state S1, resolve the location for each of the + * previous N1 states that is unresolved. The first semantic option of a state + * is always chosen. */ +static void +yyresolveLocations (yyGLRState* yys1, int yyn1, + yyGLRStack *yystackp]b4_user_formals[) +{ + if (0 < yyn1) + { + yyresolveLocations (yys1->yypred, yyn1 - 1, yystackp]b4_user_args[); + if (!yys1->yyresolved) + { + yySemanticOption *yyoption; + yyGLRStackItem yyrhsloc[1 + YYMAXRHS]; + int yynrhs; + int yychar_current; + YYSTYPE yylval_current; + YYLTYPE yylloc_current; + yyoption = yys1->yysemantics.yyfirstVal; + YYASSERT (yyoption != NULL); + yynrhs = yyrhsLength (yyoption->yyrule); + if (yynrhs > 0) + { + yyGLRState *yys; + int yyn; + yyresolveLocations (yyoption->yystate, yynrhs, + yystackp]b4_user_args[); + for (yys = yyoption->yystate, yyn = yynrhs; + yyn > 0; + yys = yys->yypred, yyn -= 1) + yyrhsloc[yyn].yystate.yyloc = yys->yyloc; + } + else + { + yyGLRState *yyprevious = yyoption->yystate; + YYASSERT (yyprevious->yyresolved); + yyrhsloc[0].yystate.yyloc = yyprevious->yyloc; + } + yychar_current = yychar; + yylval_current = yylval; + yylloc_current = yylloc; + yychar = yyoption->yyrawchar; + yylval = yyoption->yyval; + yylloc = yyoption->yyloc; + YYLLOC_DEFAULT ((yys1->yyloc), yyrhsloc, yynrhs); + yychar = yychar_current; + yylval = yylval_current; + yylloc = yylloc_current; + } + } +} /** Resolve the ambiguity represented in state S, perform the indicated * actions, and set the semantic value of S. If result != yyok, the chain of @@ -1837,6 +1888,7 @@ yyresolveValue (yyGLRState* yys, yyGLRStack* yystackp]b4_user_formals[) switch (yypreference (yybest, yyp)) { case 0: + yyresolveLocations (yys, 1, yystackp]b4_user_args[); return yyreportAmbiguity (yybest, yyp]b4_pure_args[); break; case 1: