|Parser error handling piotr.wyderskiREMOVE@hoga.pl (Piotr Wyderski) (2003-08-20)|
|Re: Parser error handling firstname.lastname@example.org (2003-08-23)|
|Re: Parser error handling piotr.wyderskiREMOVE@hoga.pl (Piotr Wyderski) (2003-08-30)|
|Re: Parser error handling email@example.com (2003-09-04)|
|From:||firstname.lastname@example.org (Hans Aberg)|
|Date:||23 Aug 2003 23:10:25 -0400|
|Posted-Date:||23 Aug 2003 23:10:25 EDT|
"Piotr Wyderski" <piotr.wyderskiREMOVE@hoga.pl> wrote:
>I'm writing a translator for an experimental language using Bison and
>One of my problems is to report a lexical error and stop the parser
>immediately after that.
>So, my first question is how to report lexical
>errors and stop parsing correctly.
Depends on what you mean by "stop parsing correctly". You could for
example let the lexer write out an error message, and then return a
token to the parser which is not used anywhere, which will cause it to
generate an error.
I think that is about how good the Flex/Bison error handshaking is
right now, but that improvements is on the todo list.
If one wants any outstanding reductions to first be executed I
recently made a suggestion to the Bug-Bison list, in the thread
"Featuritis: Token actions": Tokens with actions attached to them
which would be executed when it is time to shift the next token. This
seems to be right for debugging tokens. There remains only somebody
willing to implement it in to Bison. :-)
>The second question is about cleaning the intermediate results during
>failures. The parsing tree is composed of objects derived from the
>Node class; the parser's stack stores pointers to that
>objects. Provided semantic actions use that pointers as parameters,
>create and initialize a new node using them and put it onto the stack
>-- nothing unusual. When there's an error, the stack may contain
>pointers to "intermediate" nodes. They should be deleted to prevent
>memory leakage. How to assure that those objects will be destroyed?
I assume you are using C as output language. I use C++, where I write
user classes which the C++ language can clean up.
For C, Akim Demaille has implemented a %destructor feature. See for
example the thread "Destructor trouble" in May in the Help-Bison
list. I do not know exactly how it works, as I am only using C++ where
it is not needed, but it should be called when there is an error and
the stack needs to be unwinded. In other cases (non-error), you will
have to do the cleanup via the parser actions.
>Could you please show me a good flex/bison translator (i.e. its source
>code) with correctly solved error reporting? I'd like to see a good
>example of ER and finish my own translator. Thanks in advance.
You can always ask in the Flex and Bison lists:
Help-flex mailing list
Hans Aberg * Anti-spam: remove "remove." from email address.
* Email: Hans Aberg <email@example.com>
* Home Page: <http://www.math.su.se/~haberg/>
* AMS member listing: <http://www.ams.org/cml/>
Return to the
Search the comp.compilers archives again.