[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: push parser
From: |
Joel E. Denny |
Subject: |
Re: push parser |
Date: |
Wed, 20 Dec 2006 01:46:38 -0500 (EST) |
On Wed, 20 Dec 2006, Joel E. Denny wrote:
> Thanks, I committed it and the following patch. I'll soon commit another
> patch which fixes the bug revealed by the following patch.
I committed the following.
Index: ChangeLog
===================================================================
RCS file: /sources/bison/bison/ChangeLog,v
retrieving revision 1.1634
diff -p -u -r1.1634 ChangeLog
--- ChangeLog 20 Dec 2006 06:33:30 -0000 1.1634
+++ ChangeLog 20 Dec 2006 06:38:49 -0000
@@ -1,5 +1,20 @@
2006-12-20 Joel E. Denny <address@hidden>
+ 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 <address@hidden>
+
Rearrange initialization of the parser state variables so that the
skeleton doesn't have to have a copy for pull mode and another for push
mode. This patch also fixes at least a bug such that yylloc was not
Index: data/push.c
===================================================================
RCS file: /sources/bison/bison/data/push.c,v
retrieving revision 1.21
diff -p -u -r1.21 push.c
--- data/push.c 20 Dec 2006 06:33:30 -0000 1.21
+++ data/push.c 20 Dec 2006 06:38:50 -0000
@@ -227,9 +227,9 @@ b4_c_function_decl([[yypstate_delete]],
[[[yypstate *yyps]], [[yyps]]])
b4_c_function_decl([[yypush_parse]], [[int]],
[[[yypstate *yyps]], [[yyps]]],
- [[[int yynchar]], [[yynchar]]],
- [[[YYSTYPE const *yynlval]], [[yynlval]]]b4_locations_if([,
- [[[YYLTYPE const *yynlloc]], [[yynlloc]]]])m4_ifset([b4_parse_param], [,
+ [[[int yypushed_char]], [[yypushed_char]]],
+ [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
+ [[[YYLTYPE const *yypushed_loc]],
[[yypushed_loc]]]])m4_ifset([b4_parse_param], [,
b4_parse_param]))[
#endif
]])
@@ -1102,9 +1102,9 @@ b4_push_if(
]b4_push_if([
b4_c_function_def([[yypush_parse]], [[int]], [[[yypstate *yyps]], [[yyps]]],
- [[[int yynchar]], [[yynchar]]],
- [[[YYSTYPE const *yynlval]], [[yynlval]]]b4_locations_if([,
- [[[YYLTYPE const *yynlloc]], [[yynlloc]]]])m4_ifset([b4_parse_param], [,
+ [[[int yypushed_char]], [[yypushed_char]]],
+ [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
+ [[[YYLTYPE const *yypushed_loc]],
[[yypushed_loc]]]])m4_ifset([b4_parse_param], [,
b4_parse_param]))], [
#ifdef YYPARSE_PARAM
b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])
@@ -1127,20 +1127,10 @@ b4_c_function_def([yyparse], [int], b4_p
/* The number of symbols on the RHS of the reduced rule.
Keep to zero when no symbol should be popped. */
int yylen = 0;
-]b4_push_if([ yychar = yynchar;
- if (yynlval)
- yylval = *yynlval;
-]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;])[
-
+]b4_push_if([[
+ if (!yyps->yynew)
+ goto yyread_pushed_token;
+]])[
yytoken = 0;
yyss = yyssa;
yyvs = yyvsa;
@@ -1152,6 +1142,8 @@ b4_c_function_def([yyparse], [int], b4_p
yystate = 0;
yyerrstatus = 0;
+]b4_push_if([], [[ yynerrs = 0;]])[
+ yychar = YYEMPTY; /* Cause a token to be read. */
/* Initialize stack pointers.
Waste one element of value and location stack
@@ -1170,7 +1162,7 @@ b4_c_function_def([yyparse], [int], b4_p
m4_ifdef([b4_initial_action], [
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
- /* User initialization code. */
+/* User initialization code. */
b4_user_initial_action
m4_popdef([b4_dollar_dollar])dnl
m4_popdef([b4_at_dollar])])dnl
@@ -1282,14 +1274,23 @@ yybackup:
/* YYCHAR is either YYEMPTY or YYEOF or a valid lookahead symbol. */
if (yychar == YYEMPTY)
{
- ]b4_push_if([
- YYDPRINTF ((stderr, "Return for a new token:\n"));
- yyresult = YYPUSH_MORE;
- goto yypushreturn;
-gottoken:])[
- YYDPRINTF ((stderr, "Reading a token: "));
- ]b4_push_if([], [yychar = YYLEX;])[
- }
+]b4_push_if([[ if (!yyps->yynew)
+ {
+ YYDPRINTF ((stderr, "Return for a new token:\n"));
+ yyresult = YYPUSH_MORE;
+ goto yypushreturn;
+ }
+ 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)
{
@@ -1640,9 +1641,9 @@ b4_c_function_decl([b4_prefix[pstate_del
[[b4_prefix[pstate *yyps]], [[yyps]]])
b4_c_function_decl([b4_prefix[push_parse]], [[int]],
[[b4_prefix[pstate *yyps]], [[yyps]]],
- [[[int yynchar]], [[yynchar]]],
- [[[YYSTYPE const *yynlval]], [[yynlval]]]b4_locations_if([,
- [[[YYLTYPE const *yynlloc]], [[yynlloc]]]])m4_ifset([b4_parse_param], [,
+ [[[int yypushed_char]], [[yypushed_char]]],
+ [[[YYSTYPE const *yypushed_val]], [[yypushed_val]]]b4_locations_if([,
+ [[[YYLTYPE const *yypushed_loc]],
[[yypushed_loc]]]])m4_ifset([b4_parse_param], [,
b4_parse_param]))[
#endif
]])
- Re: push parser, (continued)
- Re: push parser, Joel E. Denny, 2006/12/18
- Re: push parser, Joel E. Denny, 2006/12/18
- Re: push parser, Joel E. Denny, 2006/12/19
- Re: push parser, Joel E. Denny, 2006/12/19
- Re: push parser, Paul Eggert, 2006/12/19
- Re: push parser, Joel E. Denny, 2006/12/19
- Re: push parser, Paul Eggert, 2006/12/19
- Re: push parser, Joel E. Denny, 2006/12/19
- Re: push parser, Paul Eggert, 2006/12/20
- Re: push parser, Joel E. Denny, 2006/12/20
- Re: push parser,
Joel E. Denny <=
- Re: push parser, Joel E. Denny, 2006/12/20
- Re: push parser, Joel E. Denny, 2006/12/20
- Re: push parser, Joel E. Denny, 2006/12/20
- Re: push parser, Bob Rossi, 2006/12/23
- Re: push parser, Joel E. Denny, 2006/12/26
- Re: push parser, Bob Rossi, 2006/12/26
- Re: push parser, Joel E. Denny, 2006/12/26
- Re: push parser, Bob Rossi, 2006/12/26
- Re: push parser, Joel E. Denny, 2006/12/26
- Re: push parser, Bob Rossi, 2006/12/27