help-bison
[Top][All Lists]
Advanced

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

Re: Shift reduce errors due to embedded actions


From: David Durham
Subject: Re: Shift reduce errors due to embedded actions
Date: Tue, 16 Oct 2001 14:24:24 -0500

On Tue, 2001-10-16 at 13:49, Axel Kittenberger wrote:
> > Yes, I was just hypothetically saying: IF bison were to go ahead (which
> > it wouldn't), it wouldn't even be able to go back and undo the damage
> > that the mid-rule action (that didn't need to execute afterall) had
> > done..
> 
> Maybe I'm missing something, but do mid-level-rules have any sense but a
> little comfort for the programmer? The only think I can think about if the
> rule constructs something the lexer needs, but as Hans said already actions
> and deps in the Lexer are very dangerous and need to be carefully
>  constructed.
> 

You're right... they are mostly used if something has to change about
the lexer, but it's not limited to that... 

For instance, 
  I wrote a C preprocessor.  After a "#define" token is parsed, I want
to turn on a flag that tells the lexer NOT to expand the following IDENT
if it's a macro:
   for example:
      #define AAA 1 2 3
      ...
      #define AAA 4 5 6

If while parsing the second definition of AAA, the lexer were to expand
the previous definition for AAA (which is usually does: if an IDENT is
lex-ed that is a defined macro, then the definition should be ouput by
the lexer in place of the macro name) we wouldn't be able to detect that
AAA was trying to be redefined in error.
      It would simply become:
         #define AAA 1 2 3
         ...
         #define 1 2 3 4 5 6

So, after the "#define" is parsed (in the bison parser) we turn on a
flag that tells the lexer not to expand the next IDENT, then we turn the
flag back off with another midrule action, or most likely turn it off in
the lexer after one IDENT has been parsed, but not expanded.

And yes, there can be some unforeseen results that may occur from the
lookahead.  Therefore, if the parser is using a lookahead token while
parsing the "#define" we may put the midrule action after the "#" or
something, but we'd need to do it for all "#" and then turn the flag off
always after the next token or something... it's a pain if you're not
real sure what's going on...







reply via email to

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