mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 12:23:04 +00:00
(yyparse): Correct error handling to conform to
POSIX and yacc. Specifically, after syntax error is discovered, do not reduce further before shifting the error token. Clean up the code a bit by removing the labels yyerrdefault, yyerrhandle, yyerrpop.
This commit is contained in:
@@ -1120,30 +1120,21 @@ yyerrlab1:
|
|||||||
|
|
||||||
yyerrstatus = 3; /* Each real token shifted decrements this. */
|
yyerrstatus = 3; /* Each real token shifted decrements this. */
|
||||||
|
|
||||||
goto yyerrhandle;
|
for (;;)
|
||||||
|
{
|
||||||
|
yyn = yypact[yystate];
|
||||||
|
if (yyn != YYFLAG)
|
||||||
|
{
|
||||||
|
yyn += YYTERROR;
|
||||||
|
if (0 <= yyn && yyn <= YYLAST && yycheck[yyn] == YYTERROR)
|
||||||
|
{
|
||||||
|
yyn = yytable[yyn];
|
||||||
|
if (0 < yyn)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Pop the current state because it cannot handle the error token. */
|
||||||
/*-------------------------------------------------------------------.
|
|
||||||
| yyerrdefault -- current state does not do anything special for the |
|
|
||||||
| error token. |
|
|
||||||
`-------------------------------------------------------------------*/
|
|
||||||
yyerrdefault:
|
|
||||||
#if 0
|
|
||||||
/* This is wrong; only states that explicitly want error tokens
|
|
||||||
should shift them. */
|
|
||||||
|
|
||||||
/* If its default is to accept any token, ok. Otherwise pop it. */
|
|
||||||
yyn = yydefact[yystate];
|
|
||||||
if (yyn)
|
|
||||||
goto yydefault;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
/*---------------------------------------------------------------.
|
|
||||||
| yyerrpop -- pop the current state because it cannot handle the |
|
|
||||||
| error token. |
|
|
||||||
`---------------------------------------------------------------*/
|
|
||||||
yyerrpop:
|
|
||||||
if (yyssp == yyss)
|
if (yyssp == yyss)
|
||||||
YYABORT;
|
YYABORT;
|
||||||
yyvsp--;
|
yyvsp--;
|
||||||
@@ -1162,29 +1153,7 @@ yyerrpop:
|
|||||||
YYFPRINTF (stderr, "\n");
|
YYFPRINTF (stderr, "\n");
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/*--------------.
|
|
||||||
| yyerrhandle. |
|
|
||||||
`--------------*/
|
|
||||||
yyerrhandle:
|
|
||||||
yyn = yypact[yystate];
|
|
||||||
if (yyn == YYFLAG)
|
|
||||||
goto yyerrdefault;
|
|
||||||
|
|
||||||
yyn += YYTERROR;
|
|
||||||
if (yyn < 0 || yyn > YYLAST || yycheck[yyn] != YYTERROR)
|
|
||||||
goto yyerrdefault;
|
|
||||||
|
|
||||||
yyn = yytable[yyn];
|
|
||||||
if (yyn < 0)
|
|
||||||
{
|
|
||||||
if (yyn == YYFLAG)
|
|
||||||
goto yyerrpop;
|
|
||||||
yyn = -yyn;
|
|
||||||
goto yyreduce;
|
|
||||||
}
|
}
|
||||||
else if (yyn == 0)
|
|
||||||
goto yyerrpop;
|
|
||||||
|
|
||||||
if (yyn == YYFINAL)
|
if (yyn == YYFINAL)
|
||||||
YYACCEPT;
|
YYACCEPT;
|
||||||
|
|||||||
Reference in New Issue
Block a user