[antlr-interest] [3.1.1][C-target] @init/@after pairing lost with backtracking/semantic predicates?

Jim Idle jimi at temporal-wave.com
Thu Apr 30 08:08:37 PDT 2009


Sven Van Echelpoel wrote:
> Hi,
>
> I have observed that the pairing of @init/@after seems to be lost once
> backtracking is introduced, at least in a tree grammar. Most of my rules
> look like this:
>
> some_rule
>   @init { enterParserRule( SomeRule ); }
>   @after { leaveParserRule( SomeRule ); }
>   
@after is not supported in the C target. While it can be hacked in, 
there are ramification for all the combinations of backtracking, 
predicates, exceptions and so on. I do intend to give this a thorough 
going over before the next release though.

You can generally do what you need though like this:

s : {start();} ( alt1 | alt2 | alt3) { end(); } ;

I also recommend that you do not use backtracking for a production parser.

> Would it be correct to say that during backtracking the 'stack' is not
> properly unwound,
Sort of ;-) It is complicated to get all of this to work exactly like 
try {} catch {} finally {}. I think I can probably do it, but it needs 
some effort in the templates. I'll 'rule' on this for the next release.

Jim



More information about the antlr-interest mailing list