mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-11 21:33:04 +00:00
Clean up handling of %destructor for the end token (token 0).
Discussed starting at <http://lists.gnu.org/archive/html/bison-patches/2006-07/msg00019.html> and <http://lists.gnu.org/archive/html/help-bison/2006-07/msg00013.html>. Make the skeletons consistent in how they pop the end token and invoke its %destructor. * data/glr.c (yyrecoverSyntaxError, yyparse): Don't pop the start state, which has token number 0, since this would invoke the %destructor for the end token. * data/lalr1.cc (yy::parser::parse): Don't check for the final state until after shifting the end token, or else it won't be popped. * data/yacc.c (yyparse): Likewise. * data/glr.c (yyparse): Clear the lookahead after shifting it even when it's the end token. Upon termination, destroy an unshifted lookahead even when it's the end token. * data/lalr1.cc (yy::parser::parse): Likewise. * data/yacc.c (yyparse): Likewise. * src/reader.c (packgram): Don't check rule 0. This suppresses unused value warnings for the end token when the user gives the end token a %destructor. * tests/actions.at (Printers and Destructors): Test all the above.
This commit is contained in:
11
data/glr.c
11
data/glr.c
@@ -2261,7 +2261,8 @@ yyrecoverSyntaxError (yyGLRStack* yystackp]b4_user_formals[)
|
||||
}
|
||||
}
|
||||
]b4_locations_if([[ yystackp->yyerror_range[1].yystate.yyloc = yys->yyloc;]])[
|
||||
yydestroyGLRState ("Error: popping", yys]b4_user_args[);
|
||||
if (yys->yypred != NULL)
|
||||
yydestroyGLRState ("Error: popping", yys]b4_user_args[);
|
||||
yystackp->yytops.yystates[0] = yys->yypred;
|
||||
yystackp->yynextFree -= 1;
|
||||
yystackp->yyspaceLeft += 1;
|
||||
@@ -2373,8 +2374,7 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
if (yyisShiftAction (yyaction))
|
||||
{
|
||||
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
|
||||
if (yychar != YYEOF)
|
||||
yychar = YYEMPTY;
|
||||
yychar = YYEMPTY;
|
||||
yyposn += 1;
|
||||
yyglrShift (&yystack, 0, yyaction, yyposn, &yylval, &yylloc);
|
||||
if (0 < yystack.yyerrState)
|
||||
@@ -2490,7 +2490,7 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
goto yyreturn;
|
||||
|
||||
yyreturn:
|
||||
if (yychar != YYEOF && yychar != YYEMPTY)
|
||||
if (yychar != YYEMPTY)
|
||||
yydestruct ("Cleanup: discarding lookahead",
|
||||
YYTRANSLATE (yychar),
|
||||
&yylval]b4_locations_if([, &yylloc])[]b4_user_args[);
|
||||
@@ -2512,7 +2512,8 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
{
|
||||
yyGLRState *yys = yystates[yyk];
|
||||
]b4_locations_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
|
||||
)[ yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
|
||||
)[ if (yys->yypred != NULL)
|
||||
yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
|
||||
yystates[yyk] = yys->yypred;
|
||||
yystack.yynextFree -= 1;
|
||||
yystack.yyspaceLeft += 1;
|
||||
|
||||
@@ -567,6 +567,11 @@ m4_popdef([b4_at_dollar])])dnl
|
||||
yynewstate:
|
||||
yystate_stack_.push (yystate);
|
||||
YYCDEBUG << "Entering state " << yystate << std::endl;
|
||||
|
||||
/* Accept? */
|
||||
if (yystate == yyfinal_)
|
||||
goto yyacceptlab;
|
||||
|
||||
goto yybackup;
|
||||
|
||||
/* Backup. */
|
||||
@@ -616,16 +621,11 @@ m4_ifdef([b4_lex_param], [, ]b4_lex_param))[;
|
||||
goto yyreduce;
|
||||
}
|
||||
|
||||
/* Accept? */
|
||||
if (yyn == yyfinal_)
|
||||
goto yyacceptlab;
|
||||
|
||||
/* Shift the lookahead token. */
|
||||
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
|
||||
|
||||
/* Discard the token being shifted unless it is eof. */
|
||||
if (yychar != yyeof_)
|
||||
yychar = yyempty_;
|
||||
/* Discard the token being shifted. */
|
||||
yychar = yyempty_;
|
||||
|
||||
yysemantic_stack_.push (yylval);
|
||||
yylocation_stack_.push (yylloc);
|
||||
@@ -780,9 +780,6 @@ b4_error_verbose_if([, yytoken])[));
|
||||
YY_STACK_PRINT ();
|
||||
}
|
||||
|
||||
if (yyn == yyfinal_)
|
||||
goto yyacceptlab;
|
||||
|
||||
yyerror_range[1] = yylloc;
|
||||
// Using YYLLOC is tempting, but would change the location of
|
||||
// the lookahead. YYLOC is available though.
|
||||
@@ -808,7 +805,7 @@ b4_error_verbose_if([, yytoken])[));
|
||||
goto yyreturn;
|
||||
|
||||
yyreturn:
|
||||
if (yychar != yyeof_ && yychar != yyempty_)
|
||||
if (yychar != yyempty_)
|
||||
yydestruct_ ("Cleanup: discarding lookahead", yytoken, &yylval, &yylloc);
|
||||
|
||||
/* Do not reclaim the symbols of the rule which action triggered
|
||||
|
||||
16
data/yacc.c
16
data/yacc.c
@@ -1164,6 +1164,9 @@ m4_ifdef([b4_at_dollar_used], [[ yylsp[0] = yylloc;
|
||||
|
||||
YYDPRINTF ((stderr, "Entering state %d\n", yystate));
|
||||
|
||||
if (yystate == YYFINAL)
|
||||
YYACCEPT;
|
||||
|
||||
goto yybackup;
|
||||
|
||||
/*-----------.
|
||||
@@ -1213,9 +1216,6 @@ yybackup:
|
||||
goto yyreduce;
|
||||
}
|
||||
|
||||
if (yyn == YYFINAL)
|
||||
YYACCEPT;
|
||||
|
||||
/* Count tokens shifted since error; after three, turn off error
|
||||
status. */
|
||||
if (yyerrstatus)
|
||||
@@ -1224,9 +1224,8 @@ yybackup:
|
||||
/* Shift the lookahead token. */
|
||||
YY_SYMBOL_PRINT ("Shifting", yytoken, &yylval, &yylloc);
|
||||
|
||||
/* Discard the shifted token unless it is eof. */
|
||||
if (yychar != YYEOF)
|
||||
yychar = YYEMPTY;
|
||||
/* Discard the shifted token. */
|
||||
yychar = YYEMPTY;
|
||||
|
||||
yystate = yyn;
|
||||
*++yyvsp = yylval;
|
||||
@@ -1418,9 +1417,6 @@ yyerrlab1:
|
||||
YY_STACK_PRINT (yyss, yyssp);
|
||||
}
|
||||
|
||||
if (yyn == YYFINAL)
|
||||
YYACCEPT;
|
||||
|
||||
*++yyvsp = yylval;
|
||||
]b4_locations_if([[
|
||||
yyerror_range[1] = yylloc;
|
||||
@@ -1461,7 +1457,7 @@ yyexhaustedlab:
|
||||
#endif
|
||||
|
||||
yyreturn:
|
||||
if (yychar != YYEOF && yychar != YYEMPTY)
|
||||
if (yychar != YYEMPTY)
|
||||
yydestruct ("Cleanup: discarding lookahead",
|
||||
yytoken, &yylval]b4_locations_if([, &yylloc])[]b4_user_args[);
|
||||
/* Do not reclaim the symbols of the rule which action triggered
|
||||
|
||||
Reference in New Issue
Block a user