[antlr-interest] ANTLR tree construction problem

Gavin Lambert antlr at mirality.co.nz
Tue Mar 11 11:54:17 PDT 2008


At 15:46 11/03/2008, Kenneth Domino wrote:
 >I think the rule is ok.  The problem seems to be in the code
 >generated for the expression:
 >
 >"(modifier=('protected'|'public'|'private'|'fragment') )?"
 >
 >There is no code emitted to set label "modifier", which is used
 >later on for tree construction.  As a result, modifier in the
 >generated code below is always null, and addChild() always
 >receives null:

Yes, this is a known quirk (and ANTLR really ought to emit an 
error when you try it, or be changed so it actually 
works).  Basically you can't label a block, you can only label an 
entity (token or subrule).  If you change it to this then it will 
work:

   (modifier=ruleModifier)?
...
ruleModifier: 'protected' | 'public' | 'private' | 'fragment';



More information about the antlr-interest mailing list