[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: mid-rule actions
From: |
Hans Aberg |
Subject: |
Re: mid-rule actions |
Date: |
Tue, 11 Jan 2005 01:12:28 +0100 |
User-agent: |
Microsoft-Outlook-Express-Macintosh-Edition/5.0.6 |
[Warning: Your email got two spam marks.]
At 21:10 +0300 2005/01/10, hz kto wrote:
>I have a question about mid-rule actions, here is the example from the bison
documentation:
>
>compound: '{' { prepare_for_local_variables (); }
> declarations statements '}'
> | '{' statements '}'
> ;
>
>If we are parsing "declarations statements" from the first part of the rule and
find out that we need to use just "statements" will
prepare_for_local_variables() already be executed or will it run only if the
"declarations statements" match?
I think it may depend on what lookahead the LALR(1) parsing algorithm needs.
There is in no easy way to tell that. Mid-rule actions are implemented as an
empty rule with the action.
>If the former is the case, how do I undo the effects?
There is no way to undo it in Bison. In the example, workaround may be to
always push the environment stack. I.e.,
compound: { push_stack; } '{' declarations_statements { pop_stack(); } '}'
;
declarations_statements:
declarations statements
| statements
;
The environment stack will then always be pushed, even if there are no local
variables declared.
Hans Aberg