X-Git-Url: https://git.saurik.com/bison.git/blobdiff_plain/17acead581306a47622213c3ff949bb237b1268f..2a1fe6ed6f0688bbf05f94228b54642fd699dd13:/data/glr.c diff --git a/data/glr.c b/data/glr.c index 0868f025..680d1207 100644 --- a/data/glr.c +++ b/data/glr.c @@ -169,10 +169,10 @@ typedef union b4_stype yystype; typedef struct yyltype { ]b4_location_if([ - int yyfirst_line; - int yyfirst_column; - int yylast_line; - int yylast_column;])[ + int first_line; + int first_column; + int last_line; + int last_column;])[ } yyltype; # define YYLTYPE ]b4_ltype[ # define YYLTYPE_IS_TRIVIAL 1 @@ -333,7 +333,8 @@ static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] = /* YYTABLE[YYPACT[STATE-NUM]]. What to do in state STATE-NUM. If positive, shift that token. If negative, reduce the rule which - number is the opposite. If zero, do what YYDEFACT says. */ + number is the opposite. If zero, do what YYDEFACT says. + If YYTABLE_NINF, parse error. */ #define YYTABLE_NINF ]b4_table_ninf[ static const ]b4_int_type_for([b4_table])[ yytable[] = { @@ -396,10 +397,10 @@ int yyparse (void); #ifndef YYLLOC_DEFAULT # define YYLLOC_DEFAULT(yyCurrent, yyRhs, YYN) \ - yyCurrent.yyfirst_line = YYRHSLOC(yyRhs,1).yyfirst_line; \ - yyCurrent.yyfirst_column = YYRHSLOC(yyRhs,1).yyfirst_column; \ - yyCurrent.yylast_line = YYRHSLOC(yyRhs,YYN).yylast_line; \ - yyCurrent.yylast_column = YYRHSLOC(yyRhs,YYN).yylast_column; + yyCurrent.first_line = YYRHSLOC(yyRhs,1).first_line; \ + yyCurrent.first_column = YYRHSLOC(yyRhs,1).first_column; \ + yyCurrent.last_line = YYRHSLOC(yyRhs,YYN).last_line; \ + yyCurrent.last_column = YYRHSLOC(yyRhs,YYN).last_column; #endif /* YYLEX -- calling `yylex' with the right arguments. */ @@ -692,7 +693,7 @@ yydefaultAction (yyStateNum yystate) return yydefact[yystate]; } -/** Set *ACTION to the action to take in STATE on seeing TOKEN. +/** Set *YYACTION to the action to take in YYSTATE on seeing YYTOKEN. * Result R means * R < 0: Reduce on rule -R. * R = 0: Error. @@ -705,16 +706,21 @@ yygetLRActions (yyStateNum yystate, int yytoken, int* yyaction, const short** yyconflicts) { int yyindex = yypact[yystate] + yytoken; - if (yyindex < 0 || yyindex > YYLAST || yycheck[yyindex] != yytoken) + if (yyindex < 0 || YYLAST < yyindex || yycheck[yyindex] != yytoken) { *yyaction = -yydefact[yystate]; *yyconflicts = yyconfl; } - else + else if (yytable[yyindex] != YYTABLE_NINF) { *yyaction = yytable[yyindex]; *yyconflicts = yyconfl + yyconflp[yyindex]; } + else + { + *yyaction = 0; + *yyconflicts = yyconfl + yyconflp[yyindex]; + } } static inline yyStateNum @@ -722,7 +728,7 @@ yyLRgotoState (yyStateNum yystate, yySymbol yylhs) { int yyr; yyr = yypgoto[yylhs - YYNTOKENS] + yystate; - if (yyr >= 0 && yyr <= YYLAST && yycheck[yyr] == yystate) + if (0 <= yyr && yyr <= YYLAST && yycheck[yyr] == yystate) return yytable[yyr]; else return yydefgoto[yylhs - YYNTOKENS]; @@ -737,7 +743,7 @@ yyisShiftAction (int yyaction) static inline bool yyisErrorAction (int yyaction) { - return yyaction == 0 || yyaction == YYPACT_NINF; + return yyaction == 0; } /* GLRStates */ @@ -1063,13 +1069,25 @@ yyglrReduce (yyGLRStack* yystack, size_t yyk, yyRuleNum yyrule, YYSTYPE yysval; YYLTYPE yyloc; +#if YYDEBUG + if (yydebug) + { + int yyi; + 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]; yyrhs[yyi] >= 0; yyi++) + YYFPRINTF (stderr, "%s ", yytokenName (yyrhs[yyi])); + YYFPRINTF (stderr, " -> %s\n", yytokenName (yyr1[yyrule])); + } +#endif YYCHK (yydoAction (yystack, yyk, yyrule, &yysval, &yyloc)); yyglrShift (yystack, yyk, yyLRgotoState (yystack->yytops.yystates[yyk]->yylrState, yylhsNonterm (yyrule)), yyposn, yysval, &yyloc); - YYDPRINTF ((stderr, "Reduced stack %d by rule #%d. Now in state %d.\n", - yyk, yyrule-1, yystack->yytops.yystates[yyk]->yylrState)); + YYDPRINTF ((stderr, "Stack %d entering state %d\n", + yyk, yystack->yytops.yystates[yyk]->yylrState)); } else { @@ -1256,7 +1274,7 @@ yyresolveAction (yySemanticOption* yyopt, yyGLRStack* yystack, } #if YYDEBUG -static yyGLRState YYLEFTMOST_STATE = { 0, NULL, -1, 0, { NULL } }; +static yyGLRState YYLEFTMOST_STATE = { 0, 0, -1, NULL, 0, { NULL } }; static void yyreportTree (yySemanticOption* yyx, int yyindent) { @@ -1448,9 +1466,11 @@ yyprocessOneStack (yyGLRStack* yystack, int yyk, { if (*yytokenp == YYEMPTY) { + YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; *yytokenp = YYTRANSLATE(yychar); - YYDPRINTF ((stderr, "Read token %s\n", yytokenName (*yytokenp))); + YYDPRINTF ((stderr, "Next token is %s\n", + yytokenName (*yytokenp))); } yygetLRActions (yystate, *yytokenp, &yyaction, &yyconflicts); @@ -1467,7 +1487,7 @@ yyprocessOneStack (yyGLRStack* yystack, int yyk, if (yyisShiftAction (yyaction)) { - YYDPRINTF ((stderr, "Shifted token %s on stack %d, ", + YYDPRINTF ((stderr, "Shifting token %s on stack %d, ", yytokenName (*yytokenp), yyk)); yyglrShift (yystack, yyk, yyaction, yyposn+1, *yylvalp, yyllocp); YYDPRINTF ((stderr, "which is now in state #%d\n", @@ -1524,7 +1544,7 @@ yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) { yyprefix = ", expecting "; for (yyx = yyn < 0 ? -yyn : 0; yyx < yytname_size; yyx += 1) - if (yycheck[yyx + yyn] == yyx) + if (yycheck[yyx + yyn] == yyx && yyx != YYTERROR) { yyp += sprintf (yyp, "%s%s", yyprefix, yytokenName (yyx)); yyprefix = " or "; @@ -1540,13 +1560,9 @@ yyreportParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) } } -/* Recover from a syntax error on STACK, assuming that TOKENP, +/* Recover from a syntax error on YYSTACK, assuming that YYTOKENP, YYLVALP, and YYLLOCP point to the syntactic category, semantic - value, and location of the lookahead. - NOTE: This uses the panic-mode recovery algorithm described in the - Bison documentation, which differs from what is in bison.simple. - Specifically, this routine performs no reductions before shifting - the error token. */ + value, and location of the lookahead. */ static void yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) { @@ -1557,21 +1573,22 @@ yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) if (yystack->yyerrState == 0) yystack->yyerrState = 3; else if (yystack->yyerrState == 3) - { - /* We just shifted the error token and (perhaps) took some - reductions. Skip tokens until we can proceed. */ - do { + /* We just shifted the error token and (perhaps) took some + reductions. Skip tokens until we can proceed. */ + while (yytrue) + { if (*yytokenp == YYEOF) yyFail (yystack, NULL); if (*yytokenp != YYEMPTY) YYDPRINTF ((stderr, "Discarding token %s\n", yytokenName (*yytokenp))); + YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; *yytokenp = YYTRANSLATE (yychar); - YYDPRINTF ((stderr, "Read token %s\n", yytokenName (*yytokenp))); + YYDPRINTF ((stderr, "Next token is %s\n", yytokenName (*yytokenp))); yyj = yypact[yystack->yytops.yystates[0]->yylrState]; if (yyj == YYPACT_NINF) - /* Something's not right; we shouldn't be here */ + /* Something's not right; we shouldn't be here. */ yyFail (yystack, NULL); yyj += *yytokenp; if (yyj < 0 || yyj > YYLAST || yycheck[yyj] != *yytokenp) @@ -1581,10 +1598,9 @@ yyrecoverParseError (yyGLRStack* yystack, YYSTYPE* yylvalp, YYLTYPE* yyllocp) } else if (yytable[yyj] != 0 && yytable[yyj] != YYTABLE_NINF) return; - } while (yytrue); - } + } - /* Reduce to one stack */ + /* Reduce to one stack. */ for (yyk = 0; yyk < yystack->yytops.yysize; yyk += 1) if (yystack->yytops.yystates[yyk] != NULL) break; @@ -1650,6 +1666,8 @@ yyparse (YYPARSE_PARAM_ARG) yyinitGLRStack (&yystack, YYINITDEPTH); yystack.yytokenp = &yytoken; + YYDPRINTF ((stderr, "Starting parse\n")); + if (setjmp (yystack.yyexception_buffer) != 0) goto yyDone; @@ -1687,9 +1705,10 @@ yyparse (YYPARSE_PARAM_ARG) { if (yytoken == YYEMPTY) { + YYDPRINTF ((stderr, "Reading a token: ")); yychar = YYLEX; yytoken = YYTRANSLATE (yychar); - YYDPRINTF ((stderr, "Read token %s\n", + YYDPRINTF ((stderr, "Next token is %s\n", yytokenName (yytoken))); } yygetLRActions (yystate, yytoken, &yyaction, &yyconflicts); @@ -1697,7 +1716,7 @@ yyparse (YYPARSE_PARAM_ARG) break; if (yyisShiftAction (yyaction)) { - YYDPRINTF ((stderr, "Shifted token %s. ", + YYDPRINTF ((stderr, "Shifting token %s, ", yytokenName (yytoken))); if (yytoken != YYEOF) yytoken = YYEMPTY; @@ -1705,7 +1724,7 @@ yyparse (YYPARSE_PARAM_ARG) yyglrShift (&yystack, 0, yyaction, yyposn, yylval, yyllocp); if (yystack.yyerrState > 0) yystack.yyerrState -= 1; - YYDPRINTF ((stderr, "Now in state #%d\n", + YYDPRINTF ((stderr, "Entering state %d\n", yystack.yytops.yystates[0]->yylrState)); } else if (yyisErrorAction (yyaction)) @@ -1855,10 +1874,10 @@ b4_location_if( [#ifndef YYLTYPE typedef struct yyltype { - int yyfirst_line; - int yyfirst_column; - int yylast_line; - int yylast_column; + int first_line; + int first_column; + int last_line; + int last_column; } yyltype; # define YYLTYPE yyltype #endif