[antlr-interest] Adding state variables to a tree parser

Cameron Ross cross at symboticware.com
Mon Dec 4 09:01:01 PST 2006


Hello,

I have a tree parser called Expander that extends a BaseTreeParser 
defined within a super-grammar.  Expander overrides a BaseTreeParser 
rule so that the text the a specific token is gets expanded N number of 
times.  Everything works as expected when I hard-code the value for N 
within Expander.  However, I would like to add a property to Expander so 
that N can be set by a parser client and read from within the Expander 
action code. 

I've defined a subclass of BaseTreeParser with the required property and 
then attempted to define Expander in the following ways:
    1) class Expander extends 
BaseTreeParser("my.package.name.BaseExpander");
    2) class Expander extends TreeParser("my.package.name.BaseExpander");
    3) class Expander extends BaseExpander; // with appropriate import 
statement in header block

None of these work.

Is there a way that I can achieve my objective?  Note that I'm using 
ANTLR version 2.7.6.

Thanks in advance,
Cameron Ross.


More information about the antlr-interest mailing list