[antlr-interest] Modification of Node Attributes using Tree Grammar

Terence Parr parrt at jguru.com
Thu Jun 13 13:44:08 PDT 2002


On Thursday, June 13, 2002, at 01:25  PM, Niall Gormley wrote:

> Thanks Terence,
>
> I modified the Tree Grammar to look like this.
>
> dims!
>   : #( l:LITERAL_DIM i:IDENT )
>     {
>     i.setVariantType(9);
>     #dims = #( l, i);
>     }
>   ;
>
> The code generated looks like
> i.setVariantType(9);
> dims_AST = (oracle.mtg.chrysalis.ASTNode)astFactory.make( (new
> ASTArray(2)).add(l_AST).add(i_AST));
>
> Sould I reference i as i_AST in the Tree Grammar (when buildAST=true), 
> or
> should the generator generate ....add(l).add(i) ?

Wow...that is weird.  What does the i:IDENT generate?  It should be 
i_AST=LT(1) or some such.  The .add(i_AST) seems right then.  
OOooooooh!  Remember: #i is the tree node, i is typically a token 
reference and i didn't want it to mean two different things (token in 
parser and tree node in tree parser).  I wonder if that should be a 
warning.

Anybody know the answer to this: Should plain 'i' mean anything in a 
tree grammar outside of a #(...) context in an action?

Ter


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 



More information about the antlr-interest mailing list