help-bison
[Top][All Lists]
Advanced

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

Re: %destructor


From: Bob Rossi
Subject: Re: %destructor
Date: Mon, 29 Sep 2014 22:01:22 -0400
User-agent: Mutt/1.5.21 (2010-09-15)

On Thu, Sep 25, 2014 at 09:31:02PM -0400, Bob Rossi wrote:
> Hi,
> 
> I'm writing a pure bison push parser in C.
> 
> I've unit tested the parser well, but now I'm starting to unit test
> it when the parser has a syntax error. This has proved challenging.
> 
> The grammar is lined based. So from a top level, this sort of sums
> up the grammar:
> 
>     output_list: output_list output {
>     };
> 
>     output: output_variant NEWLINE {
>           *gdbmi_output = $1;
>     };
> 
>     output: error NEWLINE {
>           yyerrok;
>     };
> 
> I placed an error at the top level rule to be a 'catch all' to start.
> It was unclear to me from the documentation if I should put,
>   yyclearin ;
> after yyerrok; in the function above. Does anyone know?

I've reread the documentation several times. It appears that as long as
I have a token after the error, that I don't need to have yyclearin.

I read this,
    Rules such as,
        stat   :   error  ';'
    are somewhat easier. Here, when there is an error, the parser attempts
    to skip over the statement but does so by skipping to the next semicolon.
    All tokens after the error and before the next semicolon cannot be
    shifted and are discarded. When the semicolon is seen, this rule will
    be reduced and any cleanup action associated with it performed. 

In the above example, yyclearin was not necessary, only yyerrok.

Several examples then showed some rules like this,
    line : error {
        resynch();
        yyerrok;
        yyclearin;
    }
In this case yyclearin is necessary to drop the token found on error
and start with a new token.

Since my grammar mirrors the first example, I don't think it's necessary
to have the yyclearin statement. Does this analysis sound correct?

Thanks,
Bob Rossi



reply via email to

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