help-bison
[Top][All Lists]
Advanced

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

Re: Bison error handling


From: Akim Demaille
Subject: Re: Bison error handling
Date: Sun, 27 Jan 2013 10:13:27 +0100

Le 27 janv. 2013 à 00:45, Bernd Clausen <address@hidden> a écrit :

> I have the following destructor specified for strings like IDENT.
> 
> %destructor { printf ("free at line %d: %s\n",@$.first_line, $$->c_str()); 
> delete($$); } <str>
> 
> Now I have the following input. The first line is valid, the second line 
> isn't (identifier is missing):
> 
>    ConfigParam p;
>    ConfigParam;
> 
> Output:
> 
>    In input 2:12 - 2:12 : syntax error
>    free at line 2: p
>    free at line 1: statementlist
> 
> 
> Because of an error in the second line, Bison complains, returns a syntax 
> error and calls the destructors of all objects on the parsing stack.
> Now I don't understand why the destructor of identifier "p" from the first 
> line is called? It belongs to the first line and it was successfully parsed.

Hi!

Did you implement error _recovery_?  If you do not use the
error token, your parser, once it enters error mode, will
clean up everything.  Only once the error token is successfully
"reduced" it will stop.

See the documentation about error recovery.


reply via email to

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