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

Niall Gormley ngormley at hotmail.com
Thu Jun 13 13:25:48 PDT 2002


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) ?

Thanks for taking the time to look at this.

Regards,
Niall

>From: Terence Parr <parrt at jguru.com>
>Reply-To: antlr-interest at yahoogroups.com
>To: antlr-interest at yahoogroups.com
>Subject: Re: [antlr-interest] Modification of Node Attributes using Tree 
>Grammar
>Date: Thu, 13 Jun 2002 11:32:07 -0700
>
>
>On Thursday, June 13, 2002, at 09:40  AM, Niall Gormley wrote:
>
> > Hi,
> >
> > Is it possible to use a Tree Grammar to modify Node attributes?
> >
> > The node "i" is getting modified buy the call to "setVariantType" but I
> > can't seem to get it copied to the output AST for the dims expression.
> > So
> > the real question might be, how can I get source node "i" to end up in
> > the
> > output expression?
> >
> > dims!
> >   : #( LITERAL_DIM i:IDENT )
> >     {
> >     i.setVariantType(0);
> >     #dims = #( #[LITERAL_DIM], #(i));
> >     }
> >   ;
>
>Howdy.  i points to the output node created from IDENT so you it seems
>you are setting the proper variable.  #(i) is very strange though.  What
>do you mean here?  #i or i works, but #(i) is a long way to say make i
>the root of a tree with only one  node: i.  That may be something for
>which the code gen is broken.  Try removing the #(...) around the i and
>see what happens.  Let me know if this is a bug and I'll add to the
>list.  Loring may already have found this ;)
>
>Ter
>
>
>
>
>Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>


_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com


 

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



More information about the antlr-interest mailing list