[antlr-interest] Changes don't affect AST but require code regenration of tree parser?

Gavin Lambert antlr at mirality.co.nz
Fri Aug 1 17:02:00 PDT 2008


At 07:35 2/08/2008, Raphael Reitzig wrote:
 >However, after I generated parser code, even the simplest
 >examples won't be accepted anymore. Tree gramar won't read a
 >token it always had, stating "No rule viable". I swore and
 >searched and swore and despaired - until I reminded myself of
 >the "Clean and rebuild all if anything is strange" mantra. I
 >generated all code again, including the tree walker. Note
 >that tree gramar never changed! Though, now everything works
 >perfectly again.
 >
 >What happened there? Why did an internal change in parser rules
 >(even lexer rules should not have been affected) render the
 >genereated tree walker code useless?

Are you sure you didn't change any of the lexer rules?  (And 
remember that if you're using a combined grammar, using a string 
literal in the parser counts as changing the lexer 
rules!)  Reordering the rules without actually changing them will 
have a similar effect (and again, if you've used quoted literals 
then that includes parser rules).

In any event, it sounds like the token definitions changed, so the 
tree parser was working on outdated values.  You need to inform 
your build environment that the YourGrammar.tokens file is an 
input dependency of YourTreeGrammar.g in order to make it realise 
it needs to rebuild the tree grammar in such cases.  (Exactly how 
you do that depends on your platform, language, and build tools of 
choice.)



More information about the antlr-interest mailing list