[antlr-interest] @init actions executed during lookahead, @after actions not

Ron Hunter-Duvar ron.hunter-duvar at oracle.com
Fri Apr 16 15:59:02 PDT 2010


Hi,

I just ran into something a little odd. I'm using @init actions in some 
parser rules to stack some information and @after to pop it again. In 
the generated Java code, the @after action gets wrapped in an "if ( 
state.backtracking==0 ) {...}", so that it only gets executed when other 
actions are being executed, not during lookahead. This is what I 
expected. But I noticed that the @init actions are executed 
unconditionally, including during lookahead. I didn't expect this. The 
result was a lot of junk on the stack when it went into a dfa. The fix 
was easy enough, just checking state.backtracking myself. But I was 
wondering if this is an Antlr bug or if it's supposed to work this way.

Ron

-- 
Ron Hunter-Duvar | Software Developer V | 403-272-6580
Oracle Service Engineering
Gulf Canada Square 401 - 9th Avenue S.W., Calgary, AB, Canada T2P 3C5

All opinions expressed here are mine, and do not necessarily represent
those of my employer.



More information about the antlr-interest mailing list