help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to free symbols during error recovery


From: Laurence Finston
Subject: Re: How to free symbols during error recovery
Date: Fri, 8 Oct 2004 11:32:57 +0200 (MEST)

On Fri, 8 Oct 2004, Akim Demaille wrote:

> >>> "Laurence" == Laurence Finston <address@hidden> writes:
>
>  > If you can get `%destructor' to work, and it does what you want it to,
>  > my advice would be to use it.  If you choose to use my approach, it could,
>  > of course, be refined.  For one thing, clearing and refilling the linked
>  > list could be put into functions.
>
> I have not understood what your solution provides that %destuctor does
> not (yet?).  You seem to relate %destructor to the error token, but
> there is no connection.
>

Oliver said he couldn't get `%destructor' to work on his
system.  I make no judgements about this feature, not having
looked into it.  It's not documented in the version of the
manual that I printed out some time ago (1.35).  This is
also the version at
http://www.gnu.org/software/bison/manual/.  Would it be
possible for someone to put the maual for release 1.875
there instead?

According to my understanding, this feature makes it
possible for a function to be called that destroys objects
referenced by symbols in the parser rules when states are
popped from the stack.  This is an excerpt from the section
about error recovery in the Bison manual for Release 1.35:

   But Bison can force the situation to fit the rule, by
   discarding part of the semantic context and part of the
   input. First it discards states and objects from the stack
   until it gets back to a state in which the error token is
   acceptable. (This means that the subexpressions already
   parsed are discarded, back to the last complete stmnts.) At
   this point the error token can be shifted. Then, if the old
   look-ahead token is not acceptable to be shifted next, the
   parser reads tokens and discards them until it finds a token
   which is acceptable. In this example, Bison reads and
   discards input until the next newline so that the fourth
   rule can apply.

I've assumed that this causes the destructor to be called.
Is this correct?

I haven't considered using `%destructor' for my application,
firstly because I haven't gotten around to it, and secondly
because I don't think it will work for my parser.  I use a
`%union' containing a `void*' that can point to objects of
various types that are not all in a single class hierarchy,
so writing a destructor function would be complicated.  Nor
do I want want states and objects to be discarded in a way
that's not under my control.  I also want to determine the
position from which parsing is resumed.  I have an idea for
a solution, and if anyone's interested I will be happy to
explain it.  On the other hand, if it turns out that
`%destructor' will do the job more simply, I'll happily use
it instead.


Laurence




reply via email to

[Prev in Thread] Current Thread [Next in Thread]