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

Sven Van Echelpoel sven.van.echelpoel at empolis.com
Thu Apr 30 01:10:04 PDT 2009


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 ); }
  : //  the actual rule
  ;

I have one ordinary grammar and a bunch of tree grammars in a pipeline.
The grammars in the front of the pipeline have some rules that either
have automatic backtracking switched on, or have some syntactic
predicates. The grammars at the end of the pipeline do not require this.
Now, I have observed that those grammars in which I have introduced
backtracking the symmetric pairing of @init/@after is lost. I.E. I get
much more enterParserRule() calls then leaveParserRule(). Because the
code behind it relies on this symmetry, I find myself in somewhat of a
pickle.

Note that I'm not using scopes in these instances, as I want to keep the
actual implementation of the parser neatly separated from the generated
parser. I only use scopes to communicate values up the stack during
parsing.

Would it be correct to say that during backtracking the 'stack' is not
properly unwound, or am I missing something obvious? I'm not saying that
this is a bug or that there may not be very good reasons for this
behavior. I'm just trying to understand what I'm observing, so that I
can properly deal with this.

Any input would be greatly appreciated. Thanks,

Sven



More information about the antlr-interest mailing list