[antlr-interest] Trouble with Templates in Tree Grammar

Terence Parr parrt at cs.usfca.edu
Tue Dec 14 20:56:56 PST 2010


try setting ASTLabelType option in grammar but that .text stuff should work. i use it all the time.
Ter
On Dec 14, 2010, at 7:10 PM, Scott Stevenson wrote:

> I learning how to use templates in a tree grammar.  I'm mimicking some of
> the examples in the ANTLR Reference.  I have a rule:
> 
> primary
> :    INT          -> primaryTemplate(text={$INT.text})
> |    DECIMAL -> primaryTemplate(text={$DECIMAL.text})
> |    ID            -> primaryTemplate(text={$ID.text})
> ;
> 
> where primaryTemplate is the name of the template to evaluate.
> 
> In the tree parser code it declares $INT to be type Object.
> Object INT4;
> 
> and later tries to invoke INT4.getText().  This gives an error because
> Object does not have method getText().
> 
> Can anyone tell me what am I doing wrong?  This looks just like the example
> in the book.
> 
> Thanks in advance.
> 
> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> Unsubscribe: http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list