mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-20 09:43:03 +00:00
Fix bug such that the first pushed token's value and location are
sometimes overwritten (sometimes by %initial-action) before being used. * data/push.c (yypush_parse): Rename arguments yynchar, yynlval, and yynlloc to yypushed_char, yypushed_val, and yypushed_loc for clarity. For the first yypush_parse invocation, initialize yychar to YYEMPTY to more closely mimic the pull parser logic. Don't copy the pushed token to yychar, yylval, and yylloc until it's time to read a token, which is after any initialization of yylval and yylloc. (gottoken): Rename label to... (yyread_pushed_token): ... for clarity and to avoid infringing on the user namespace.
This commit is contained in:
15
ChangeLog
15
ChangeLog
@@ -1,3 +1,18 @@
|
|||||||
|
2006-12-20 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
|
Fix bug such that the first pushed token's value and location are
|
||||||
|
sometimes overwritten (sometimes by %initial-action) before being used.
|
||||||
|
* data/push.c (yypush_parse): Rename arguments yynchar, yynlval, and
|
||||||
|
yynlloc to yypushed_char, yypushed_val, and yypushed_loc for clarity.
|
||||||
|
For the first yypush_parse invocation, initialize yychar to YYEMPTY to
|
||||||
|
more closely mimic the pull parser logic.
|
||||||
|
Don't copy the pushed token to yychar, yylval, and yylloc until it's
|
||||||
|
time to read a token, which is after any initialization of yylval and
|
||||||
|
yylloc.
|
||||||
|
(gottoken): Rename label to...
|
||||||
|
(yyread_pushed_token): ... for clarity and to avoid infringing on the
|
||||||
|
user namespace.
|
||||||
|
|
||||||
2006-12-20 Joel E. Denny <jdenny@ces.clemson.edu>
|
2006-12-20 Joel E. Denny <jdenny@ces.clemson.edu>
|
||||||
|
|
||||||
Rearrange initialization of the parser state variables so that the
|
Rearrange initialization of the parser state variables so that the
|
||||||
|
|||||||
65
data/push.c
65
data/push.c
@@ -227,9 +227,9 @@ b4_c_function_decl([[yypstate_delete]], [[void]],
|
|||||||
[[[yypstate *yyps]], [[yyps]]])
|
[[[yypstate *yyps]], [[yyps]]])
|
||||||
b4_c_function_decl([[yypush_parse]], [[int]],
|
b4_c_function_decl([[yypush_parse]], [[int]],
|
||||||
[[[yypstate *yyps]], [[yyps]]],
|
[[[yypstate *yyps]], [[yyps]]],
|
||||||
[[[int yynchar]], [[yynchar]]],
|
[[[int yypushed_char]], [[yypushed_char]]],
|
||||||
[[[YYSTYPE const *yynlval]], [[yynlval]]]b4_locations_if([,
|
[[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
|
||||||
[[[YYLTYPE const *yynlloc]], [[yynlloc]]]])m4_ifset([b4_parse_param], [,
|
[[[YYLTYPE const *yypushed_loc]], [[yypushed_loc]]]])m4_ifset([b4_parse_param], [,
|
||||||
b4_parse_param]))[
|
b4_parse_param]))[
|
||||||
#endif
|
#endif
|
||||||
]])
|
]])
|
||||||
@@ -1102,9 +1102,9 @@ b4_push_if(
|
|||||||
|
|
||||||
]b4_push_if([
|
]b4_push_if([
|
||||||
b4_c_function_def([[yypush_parse]], [[int]], [[[yypstate *yyps]], [[yyps]]],
|
b4_c_function_def([[yypush_parse]], [[int]], [[[yypstate *yyps]], [[yyps]]],
|
||||||
[[[int yynchar]], [[yynchar]]],
|
[[[int yypushed_char]], [[yypushed_char]]],
|
||||||
[[[YYSTYPE const *yynlval]], [[yynlval]]]b4_locations_if([,
|
[[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
|
||||||
[[[YYLTYPE const *yynlloc]], [[yynlloc]]]])m4_ifset([b4_parse_param], [,
|
[[[YYLTYPE const *yypushed_loc]], [[yypushed_loc]]]])m4_ifset([b4_parse_param], [,
|
||||||
b4_parse_param]))], [
|
b4_parse_param]))], [
|
||||||
#ifdef YYPARSE_PARAM
|
#ifdef YYPARSE_PARAM
|
||||||
b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])
|
b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])
|
||||||
@@ -1127,20 +1127,10 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
|
|||||||
/* The number of symbols on the RHS of the reduced rule.
|
/* The number of symbols on the RHS of the reduced rule.
|
||||||
Keep to zero when no symbol should be popped. */
|
Keep to zero when no symbol should be popped. */
|
||||||
int yylen = 0;
|
int yylen = 0;
|
||||||
]b4_push_if([ yychar = yynchar;
|
]b4_push_if([[
|
||||||
if (yynlval)
|
if (!yyps->yynew)
|
||||||
yylval = *yynlval;
|
goto yyread_pushed_token;
|
||||||
]b4_locations_if([ if (yynlloc)
|
]])[
|
||||||
yylloc = *yynlloc;])[],[yynerrs = 0;
|
|
||||||
yychar = YYEMPTY; /* Cause a token to be read. */])[
|
|
||||||
|
|
||||||
]b4_push_if([
|
|
||||||
if (yyps->yynew == 0)
|
|
||||||
{
|
|
||||||
goto gottoken;
|
|
||||||
}
|
|
||||||
yyps->yynew= 0;])[
|
|
||||||
|
|
||||||
yytoken = 0;
|
yytoken = 0;
|
||||||
yyss = yyssa;
|
yyss = yyssa;
|
||||||
yyvs = yyvsa;
|
yyvs = yyvsa;
|
||||||
@@ -1152,6 +1142,8 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
|
|||||||
|
|
||||||
yystate = 0;
|
yystate = 0;
|
||||||
yyerrstatus = 0;
|
yyerrstatus = 0;
|
||||||
|
]b4_push_if([], [[ yynerrs = 0;]])[
|
||||||
|
yychar = YYEMPTY; /* Cause a token to be read. */
|
||||||
|
|
||||||
/* Initialize stack pointers.
|
/* Initialize stack pointers.
|
||||||
Waste one element of value and location stack
|
Waste one element of value and location stack
|
||||||
@@ -1170,7 +1162,7 @@ b4_c_function_def([yyparse], [int], b4_parse_param)
|
|||||||
m4_ifdef([b4_initial_action], [
|
m4_ifdef([b4_initial_action], [
|
||||||
m4_pushdef([b4_at_dollar], [m4_define([b4_at_dollar_used])yylloc])dnl
|
m4_pushdef([b4_at_dollar], [m4_define([b4_at_dollar_used])yylloc])dnl
|
||||||
m4_pushdef([b4_dollar_dollar], [m4_define([b4_dollar_dollar_used])yylval])dnl
|
m4_pushdef([b4_dollar_dollar], [m4_define([b4_dollar_dollar_used])yylval])dnl
|
||||||
/* User initialization code. */
|
/* User initialization code. */
|
||||||
b4_user_initial_action
|
b4_user_initial_action
|
||||||
m4_popdef([b4_dollar_dollar])dnl
|
m4_popdef([b4_dollar_dollar])dnl
|
||||||
m4_popdef([b4_at_dollar])])dnl
|
m4_popdef([b4_at_dollar])])dnl
|
||||||
@@ -1282,14 +1274,23 @@ yybackup:
|
|||||||
/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
|
/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
|
||||||
if (yychar == YYEMPTY)
|
if (yychar == YYEMPTY)
|
||||||
{
|
{
|
||||||
]b4_push_if([
|
]b4_push_if([[ if (!yyps->yynew)
|
||||||
YYDPRINTF ((stderr, "Return for a new token:\n"));
|
{
|
||||||
yyresult = YYPUSH_MORE;
|
YYDPRINTF ((stderr, "Return for a new token:\n"));
|
||||||
goto yypushreturn;
|
yyresult = YYPUSH_MORE;
|
||||||
gottoken:])[
|
goto yypushreturn;
|
||||||
YYDPRINTF ((stderr, "Reading a token: "));
|
}
|
||||||
]b4_push_if([], [yychar = YYLEX;])[
|
yyps->yynew = 0;
|
||||||
}
|
|
||||||
|
yyread_pushed_token:
|
||||||
|
]])[ YYDPRINTF ((stderr, "Reading a token: "));
|
||||||
|
]b4_push_if([[ yychar = yypushed_char;
|
||||||
|
if (yypushed_val)
|
||||||
|
yylval = *yypushed_val;
|
||||||
|
]b4_locations_if([[ if (yypushed_loc)
|
||||||
|
yylloc = *yypushed_loc;]])],
|
||||||
|
[[ yychar = YYLEX;
|
||||||
|
]])[ }
|
||||||
|
|
||||||
if (yychar <= YYEOF)
|
if (yychar <= YYEOF)
|
||||||
{
|
{
|
||||||
@@ -1640,9 +1641,9 @@ b4_c_function_decl([b4_prefix[pstate_delete]], [[void]],
|
|||||||
[[b4_prefix[pstate *yyps]], [[yyps]]])
|
[[b4_prefix[pstate *yyps]], [[yyps]]])
|
||||||
b4_c_function_decl([b4_prefix[push_parse]], [[int]],
|
b4_c_function_decl([b4_prefix[push_parse]], [[int]],
|
||||||
[[b4_prefix[pstate *yyps]], [[yyps]]],
|
[[b4_prefix[pstate *yyps]], [[yyps]]],
|
||||||
[[[int yynchar]], [[yynchar]]],
|
[[[int yypushed_char]], [[yypushed_char]]],
|
||||||
[[[YYSTYPE const *yynlval]], [[yynlval]]]b4_locations_if([,
|
[[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
|
||||||
[[[YYLTYPE const *yynlloc]], [[yynlloc]]]])m4_ifset([b4_parse_param], [,
|
[[[YYLTYPE const *yypushed_loc]], [[yypushed_loc]]]])m4_ifset([b4_parse_param], [,
|
||||||
b4_parse_param]))[
|
b4_parse_param]))[
|
||||||
#endif
|
#endif
|
||||||
]])
|
]])
|
||||||
|
|||||||
Reference in New Issue
Block a user