[antlr-interest] Re: Modification of Node Attributes using Tree Grammar
lgcraymer
lgc at mail1.jpl.nasa.gov
Thu Jun 13 13:46:20 PDT 2002
--- In antlr-interest at y..., Terence Parr <parrt at j...> wrote:
>
> 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 ;)
I remember that some of the node construction stuff is broken, but not
which part specifically. For what you want to do, try just
dims
: #( LITERAL_DIM i:IDENT )
{
#i.setVariantType(0);
}
;
and if that fails, try replacing #i with i_AST--that will work. ANTLR
by default builds an output tree which matches the input tree and you
just need to set the contents of #i. Note that AST labels behave
differently than token labels: if i:IDENT labels a token in the
parser, #i translates to i; while in a tree grammar, #i translates to
i_ast (and #i_in translates to i).
Also, if you are using heterogeneous ASTs, make sure that you specify
them in the tree grammar as well as the parser--otherwise you will get
the default AST node type. One of the things that needs to be fixed
is that ASTFactories should know about heterogeneous ASTs:
right now, #[FOO] always builds an AST node of the default type
because the ASTFactory only knows about the default.
--Loring
>
> Ter
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list