--- Begin Message ---
Subject: |
Re: %destructor feedback |
Date: |
Fri, 21 Oct 2005 13:39:33 +0200 |
User-agent: |
Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) |
>>> "Wolfgang" == Wolfgang Spraul <address@hidden> writes:
> Akim -
>> We need no %destructor-param etc., we need to fix yydestructor and
>> yysymprint so that %parse-param are passed to them, just like yyerror.
> That would be perfectly fine for me.
As a matter of fact, the documentation already claimed it ran this
way. Could you please confirm that the appended patch (committed)
does address your issue?
Index: ChangeLog
from Akim Demaille <address@hidden>
* data/c.m4 (b4_yydestruct_generate, b4_yysymprint_generate): Pass
the %parse-params.
* data/glr.c (YY_SYMBOL_PRINT, yydestroyGLRState): Adjust.
* data/yacc.c (b4_Pure_if): Rename as...
(b4_yacc_pure_if): this.
(YY_SYMBOL_PRINT, yyparse): Adjust.
* doc/bison.texinfo: Formatting changes.
Index: NEWS
===================================================================
RCS file: /cvsroot/bison/bison/NEWS,v
retrieving revision 1.129
diff -u -u -r1.129 NEWS
--- NEWS 13 Oct 2005 19:38:46 -0000 1.129
+++ NEWS 21 Oct 2005 11:36:03 -0000
@@ -3,6 +3,10 @@
Changes in version 2.1a:
+* GLR, YACC parsers.
+ The %parse-params are available in the %destructor's (and the
+ experimental %printer's) as per the documentation.
+
* Bison now warns if it finds a stray `$' or `@' in an action.
* %require "VERSION"
Index: data/c.m4
===================================================================
RCS file: /cvsroot/bison/bison/data/c.m4,v
retrieving revision 1.38
diff -u -u -r1.38 c.m4
--- data/c.m4 13 Oct 2005 06:23:54 -0000 1.38
+++ data/c.m4 21 Oct 2005 11:36:03 -0000
@@ -96,7 +96,6 @@
b4_parse_param))
-
## ------------ ##
## Data Types. ##
## ------------ ##
@@ -342,7 +341,6 @@
## Synclines. ##
## ----------- ##
-
# b4_syncline(LINE, FILE)
# -----------------------
m4_define([b4_syncline],
@@ -382,8 +380,9 @@
[static void],
[[const char *yymsg], [yymsg]],
[[int yytype], [yytype]],
- [[YYSTYPE *yyvaluep], [yyvaluep]]b4_location_if([,
- [[YYLTYPE *yylocationp], [yylocationp]]]))[
+ [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
+b4_location_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
+m4_ifset([b4_parse_param], [, b4_parse_param]))[
{
YYUSE (yyvaluep);
]b4_location_if([ YYUSE (yylocationp);
@@ -416,11 +415,12 @@
[static void],
[[FILE *yyoutput], [yyoutput]],
[[int yytype], [yytype]],
- [[YYSTYPE *yyvaluep], [yyvaluep]]b4_location_if([,
- [[YYLTYPE *yylocationp], [yylocationp]]]))
+ [[YYSTYPE *yyvaluep], [yyvaluep]][]dnl
+b4_location_if( [, [[YYLTYPE *yylocationp], [yylocationp]]])[]dnl
+m4_ifset([b4_parse_param], [, b4_parse_param]))[
{
YYUSE (yyvaluep);
-b4_location_if([ YYUSE (yylocationp);
+]b4_location_if([ YYUSE (yylocationp);
])dnl
[
if (yytype < YYNTOKENS)
@@ -443,5 +443,5 @@
break;
}
YYFPRINTF (yyoutput, ")");
-}
-]])
+}]dnl
+])
Index: data/glr.c
===================================================================
RCS file: /cvsroot/bison/bison/data/glr.c,v
retrieving revision 1.129
diff -u -u -r1.129 glr.c
--- data/glr.c 6 Oct 2005 07:17:21 -0000 1.129
+++ data/glr.c 21 Oct 2005 11:36:03 -0000
@@ -34,6 +34,14 @@
## ------------------------ ##
+# b4_user_formals
+# ---------------
+# This is specific to GLR because it relies on ISO C formal argument
+# declarations.
+m4_define([b4_user_formals],
+[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
+
+
# b4_lex_param
# ------------
# Accumule in b4_lex_param all the yylex arguments.
@@ -44,12 +52,6 @@
m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
-# b4_user_formals
-# ---------------
-m4_define([b4_user_formals],
-[m4_ifset([b4_parse_param], [, b4_c_ansi_formals(b4_parse_param)])])
-
-
# b4_yyerror_args
# ---------------
# Arguments passed to yyerror: user args plus yylloc.
@@ -534,15 +536,15 @@
]b4_yysymprint_generate([b4_c_ansi_function_def])[
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
-do { \
- if (yydebug) \
- { \
- YYFPRINTF (stderr, "%s ", Title); \
- yysymprint (stderr, \
- Type, Value]b4_location_if([, Location])[); \
- YYFPRINTF (stderr, "\n"); \
- } \
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title);
\
+ yysymprint (stderr, \
+ Type, Value]b4_location_if([, Location])[]b4_user_args[); \
+ YYFPRINTF (stderr, "\n");
\
+ } \
} while (/*CONSTCOND*/ 0)
/* Nonzero means print parse trace. It is left uninitialized so that
@@ -902,11 +904,11 @@
}
static void
-yydestroyGLRState (char const *yymsg, yyGLRState *yys)
+yydestroyGLRState (char const *yymsg, yyGLRState *yys]b4_user_formals[)
{
if (yys->yyresolved)
yydestruct (yymsg, yystos[yys->yylrState],
- &yys->yysemantics.yysval]b4_location_if([, &yys->yyloc])[);
+ &yys->yysemantics.yysval]b4_location_if([,
&yys->yyloc])[]b4_user_args[);
else
{
#if YYDEBUG
@@ -914,7 +916,7 @@
{
YYFPRINTF (stderr, "%s unresolved ", yymsg);
yysymprint (stderr, yystos[yys->yylrState],
- &yys->yysemantics.yysval]b4_location_if([,
&yys->yyloc])[);
+ &yys->yysemantics.yysval]b4_location_if([,
&yys->yyloc])[]b4_user_args[);
YYFPRINTF (stderr, "\n");
}
#endif
@@ -927,7 +929,7 @@
for (yyrh = yyoption->yystate, yyn = yyrhsLength (yyoption->yyrule);
yyn > 0;
yyrh = yyrh->yypred, yyn -= 1)
- yydestroyGLRState (yymsg, yyrh);
+ yydestroyGLRState (yymsg, yyrh]b4_user_args[);
}
}
}
@@ -1968,7 +1970,7 @@
yyerror_range[2].yystate.yyloc = *yyllocp;
YYLLOC_DEFAULT (yys->yyloc, yyerror_range, 2);]])[
yydestruct ("Error: discarding",
- *yytokenp, yylvalp]b4_location_if([, yyllocp])[);
+ *yytokenp, yylvalp]b4_location_if([,
yyllocp])[]b4_user_args[);
}
YYDPRINTF ((stderr, "Reading a token: "));
yychar = YYLEX;
@@ -2023,7 +2025,7 @@
}
}
]b4_location_if([[ yystack->yyerror_range[1].yystate.yyloc =
yys->yyloc;]])[
- yydestroyGLRState ("Error: popping", yys);
+ yydestroyGLRState ("Error: popping", yys]b4_user_args[);
yystack->yytops.yystates[0] = yys->yypred;
yystack->yynextFree -= 1;
yystack->yyspaceLeft += 1;
@@ -2218,7 +2220,7 @@
yyreturn:
if (yytoken != YYEOF && yytoken != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead",
- yytoken, yylvalp]b4_location_if([, yyllocp])[);
+ yytoken, yylvalp]b4_location_if([, yyllocp])[]b4_user_args[);
/* If the stack is well-formed, pop the stack until it is empty,
destroying its entries as we go. But free the stack regardless
@@ -2231,7 +2233,7 @@
{
yyGLRState *yys = yystates[0];
]b4_location_if([[ yystack.yyerror_range[1].yystate.yyloc = yys->yyloc;]]
-)[ yydestroyGLRState ("Cleanup: popping", yys);
+)[ yydestroyGLRState ("Cleanup: popping", yys]b4_user_args[);
yystates[0] = yys->yypred;
yystack.yynextFree -= 1;
yystack.yyspaceLeft += 1;
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.115
diff -u -u -r1.115 yacc.c
--- data/yacc.c 13 Oct 2005 06:23:54 -0000 1.115
+++ data/yacc.c 21 Oct 2005 11:36:03 -0000
@@ -36,10 +36,10 @@
## ------------------------ ##
-# b4_pure_if(IF-TRUE, IF-FALSE)
-# -----------------------------
+# b4_yacc_pure_if(IF-TRUE, IF-FALSE)
+# ----------------------------------
# Expand IF-TRUE, if %pure-parser and %parse-param, IF-FALSE otherwise.
-m4_define([b4_Pure_if],
+m4_define([b4_yacc_pure_if],
[b4_pure_if([m4_ifset([b4_parse_param],
[$1], [$2])],
[$2])])
@@ -49,7 +49,7 @@
# ---------------
# Arguments passed to yyerror: user args plus yylloc.
m4_define([b4_yyerror_args],
-[b4_Pure_if([b4_location_if([&yylloc, ])])dnl
+[b4_yacc_pure_if([b4_location_if([&yylloc, ])])dnl
m4_ifset([b4_parse_param], [b4_c_args(b4_parse_param), ])])
@@ -628,15 +628,15 @@
YYFPRINTF Args; \
} while (/*CONSTCOND*/ 0)
-# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
-do { \
- if (yydebug) \
- { \
- YYFPRINTF (stderr, "%s ", Title); \
- yysymprint (stderr, \
- Type, Value]b4_location_if([, Location])[); \
- YYFPRINTF (stderr, "\n"); \
- } \
+# define YY_SYMBOL_PRINT(Title, Type, Value, Location) \
+do { \
+ if (yydebug) \
+ { \
+ YYFPRINTF (stderr, "%s ", Title);
\
+ yysymprint (stderr, \
+ Type, Value]b4_location_if([, Location])[]b4_user_args[); \
+ YYFPRINTF (stderr, "\n");
\
+ } \
} while (/*CONSTCOND*/ 0)
/*------------------------------------------------------------------.
@@ -1346,7 +1346,8 @@
}
else
{
- yydestruct ("Error: discarding", yytoken, &yylval]b4_location_if([,
&yylloc])[);
+ yydestruct ("Error: discarding",
+ yytoken, &yylval]b4_location_if([,
&yylloc])[]b4_user_args[);
yychar = YYEMPTY;
}
}
@@ -1400,7 +1401,8 @@
YYABORT;
]b4_location_if([[ yyerror_range[0] = *yylsp;]])[
- yydestruct ("Error: popping", yystos[yystate], yyvsp]b4_location_if([,
yylsp])[);
+ yydestruct ("Error: popping",
+ yystos[yystate], yyvsp]b4_location_if([,
yylsp])[]b4_user_args[);
YYPOPSTACK;
yystate = *yyssp;
YY_STACK_PRINT (yyss, yyssp);
@@ -1451,11 +1453,11 @@
yyreturn:
if (yychar != YYEOF && yychar != YYEMPTY)
yydestruct ("Cleanup: discarding lookahead",
- yytoken, &yylval]b4_location_if([, &yylloc])[);
+ yytoken, &yylval]b4_location_if([, &yylloc])[]b4_user_args[);
while (yyssp != yyss)
{
yydestruct ("Cleanup: popping",
- yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
+ yystos[*yyssp], yyvsp]b4_location_if([,
yylsp])[]b4_user_args[);
YYPOPSTACK;
}
#ifndef yyoverflow
Index: doc/bison.texinfo
===================================================================
RCS file: /cvsroot/bison/bison/doc/bison.texinfo,v
retrieving revision 1.164
diff -u -u -r1.164 bison.texinfo
--- doc/bison.texinfo 12 Oct 2005 10:15:11 -0000 1.164
+++ doc/bison.texinfo 21 Oct 2005 11:36:03 -0000
@@ -3810,28 +3810,28 @@
@cindex freeing discarded symbols
@findex %destructor
-Some symbols can be discarded by the parser. During error
-recovery (@pxref{Error Recovery}), symbols already pushed
-on the stack and tokens coming from the rest of the file
-are discarded until the parser falls on its feet. If the parser
-runs out of memory, all the symbols on the stack must be discarded.
-Even if the parser succeeds, it must discard the start symbol.
+Some symbols can be discarded by the parser. During error recovery
+(@pxref{Error Recovery}), symbols already pushed on the stack and tokens
+coming from the rest of the file are discarded until the parser falls on
+its feet. If the parser runs out of memory, all the symbols on the
+stack must be discarded. Even if the parser succeeds, it must discard
+the start symbol.
When discarded symbols convey heap based information, this memory is
lost. While this behavior can be tolerable for batch parsers, such as
-in traditional compilers, it is unacceptable for programs like shells
-or protocol implementations that may parse and execute indefinitely.
+in traditional compilers, it is unacceptable for programs like shells or
+protocol implementations that may parse and execute indefinitely.
The @code{%destructor} directive defines code that
is called when a symbol is discarded.
@deffn {Directive} %destructor @{ @var{code} @} @var{symbols}
@findex %destructor
-Invoke @var{code} whenever the parser discards one of the
address@hidden Within @var{code}, @code{$$} designates the semantic
-value associated with the discarded symbol. The additional
-parser parameters are also available
-(@pxref{Parser Function, , The Parser Function @code{yyparse}}).
+Invoke @var{code} whenever the parser discards one of the @var{symbols}.
+Within @var{code}, @code{$$} designates the semantic value associated
+with the discarded symbol. The additional parser parameters are also
+available (@pxref{Parser Function, , The Parser Function
address@hidden).
@strong{Warning:} as of Bison 2.1, this feature is still
experimental, as there has not been enough user feedback. In particular,
_______________________________________________
address@hidden http://lists.gnu.org/mailman/listinfo/help-bison
--- End Message ---