[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: too many warnings from Bison CVS for Pike
From: |
Joel E. Denny |
Subject: |
Re: too many warnings from Bison CVS for Pike |
Date: |
Tue, 21 Feb 2006 16:02:11 -0500 (EST) |
On Mon, 13 Feb 2006, Joel E. Denny wrote:
> On Mon, 13 Feb 2006, Paul Eggert wrote:
>
> > "Joel E. Denny" <address@hidden> writes:
> >
> > > You can convert a mid-rule action to a nonterminal, but it seems there is
> > > no other way to prevent its value from being leaked during error
> > > recovery.
> > > Is my understanding correct?
> >
> > I think so, yes.
> >
> > This limitation should be documented, I suppose,
>
> OK, I'll try to get to it later this week.
I installed this. Please revise as you see fit.
Joel
2006-02-21 Joel E. Denny <address@hidden>
* doc/bison.texinfo (Mid-Rule Actions): Explain how to bury a
mid-rule action inside a nonterminal symbol in order to declare a
destructor for its semantic value.
Index: doc/bison.texinfo
===================================================================
RCS file: /sources/bison/bison/doc/bison.texinfo,v
retrieving revision 1.176
diff -p -u -r1.176 bison.texinfo
--- doc/bison.texinfo 8 Feb 2006 19:25:38 -0000 1.176
+++ doc/bison.texinfo 21 Feb 2006 20:56:21 -0000
@@ -3317,6 +3317,46 @@ earlier action is used to restore the pr
removes the temporary @code{let}-variable from the list so that it won't
appear to exist while the rest of the program is parsed.
address@hidden %destructor
address@hidden discarded symbols, mid-rule actions
address@hidden error recovery, mid-rule actions
+In the above example, if the parser initiates error recovery (@pxref{Error
+Recovery}) while parsing the tokens in the embedded statement @code{stmt},
+it might discard the previous semantic context @code{$<context>5} without
+restoring it.
+Thus, @code{$<context>5} needs a destructor (@pxref{Destructor Decl, , Freeing
+Discarded Symbols}).
+However, Bison currently provides no means to declare a destructor for a
+mid-rule action's semantic value.
+
+One solution is to bury the mid-rule action inside a nonterminal symbol and to
+declare a destructor for that symbol:
+
address@hidden
address@hidden
+%type <context> let
+%destructor @{ pop_context ($$); @} let
+
+%%
+
+stmt: let stmt
+ @{ $$ = $2;
+ pop_context ($1); @}
+ ;
+
+let: LET '(' var ')'
+ @{ $$ = push_context ();
+ declare_variable ($3); @}
+ ;
+
address@hidden group
address@hidden example
+
address@hidden
+Note that the action is now at the end of its rule.
+Any mid-rule action can be converted to an end-of-rule action in this way, and
+this is what Bison actually does to implement mid-rule actions.
+
Taking action before a rule is completely recognized often leads to
conflicts since the parser must commit to a parse in order to execute the
action. For example, the following two rules, without mid-rule actions,
@@ -3410,10 +3450,7 @@ compound: subroutine
@noindent
Now Bison can execute the action in the rule for @code{subroutine} without
-deciding which rule for @code{compound} it will eventually use. Note that
-the action is now at the end of its rule. Any mid-rule action can be
-converted to an end-of-rule action in this way, and this is what Bison
-actually does to implement mid-rule actions.
+deciding which rule for @code{compound} it will eventually use.
@node Locations
@section Tracking Locations
- Re: too many warnings from Bison CVS for Pike, (continued)
- Message not available
- (no subject), haberg, 2006/02/06
Re: too many warnings from Bison CVS for Pike, Joel E. Denny, 2006/02/13