[antlr-interest] Invalid code being generated - return attribute not being parsed in @init?
Sam Barnett-Cormack
s.barnett-cormack at lancaster.ac.uk
Sat Mar 21 06:27:48 PDT 2009
Hi all,
Working based on the example on page 86 of TDAR, I have the following rule:
objIdComponents returns [boolean hasNandN]
@init {
$hasNandN = false;
}
: (c=objIdComponent {if $c.nAndN $hasNandN=true;})+ ;
And the generated code includes:
ASN_1Parser.objIdComponents_return retval = new
ASN_1Parser.objIdComponents_return();
retval.start = input.LT(1);
int objIdComponents_StartIndex = input.index();
CommonTree root_0 = null;
ASN_1Parser.objIdComponent_return c = null;
$hasNandN = false;
The final quoted line would appear to be generated by the @init action.
The code generated from the action embedded in the rule seems to be
fine. I'm sure I could work-around this by putting retval.hasNandN in
the @init block, but I'd rather be doing it 'right'. Am I doing
something wrong, or is there some sort of bug? Using ANTLR 3.1.2,
through ANTLR-IDE in Eclipse.
Sam
More information about the antlr-interest
mailing list