[antlr-interest] transforming AST's in place when generated

Mark Wright markwright at internode.on.net
Sat Feb 23 21:36:21 PST 2008


> Thanks Mark. Just one followup question is there a way
> to explicitly pass back a forest in ANTLR?

Hello Carter,

It sort of looks like it is passing back a forest
of trees (with DD and FUNCTION_DECLARATION roots).

> i.e. when you do 
> 
> -> init_declarator+
> 
> it seems like you are not really passing back a rooted
> tree.
> 
> Thanks again,
> 
> Carter.

This question seems too easy,  I am not sure I really
understand the question.  If you wanted a rooted
tree you could do something like:

-> ^(DECL init_declarator+)

I guess you would want to create the AST in which
ever structure is easiest to handle with the next processing
phase of the compiler or whatever program it is.

Regards, Mark

> 
> --- Mark Wright <markwright at internode.on.net> wrote:
> 
> > Hello Carter,
> > 
> > The idea is to pass the int type_id AST as a
> > paramater to the
> > init_declarator_list, and the init_declarator_list
> > passes it as a
> > parameter to the init_declarator, something like:
> > 
> > declaration
> >   :    storage_class_specifier? type_id
> > init_declarator_list[$storage_class_specifier.tree,
> > $type_id.tree] ';'
> >           -> init_declarator_list
> >   ;
> > 
> > init_declarator_list[CommonTree scs, CommonTree ti]
> >   :   init_declarator[$scs, $ti] (','
> > init_declarator[$scs, $ti])*
> >           -> init_declarator+
> >   ;
> > 
> > init_declarator[CommonTree scs, CommonTree ti]
> >   :    function_declarator
> >           -> {(scs == null)}? ^(FUNCTION_DECLARATION
> > {$ti} function_declarator)
> >           -> {(scs != null)}? ^(FUNCTION_DECLARATION
> > {$scs} {$ti} function_declarator)
> >           ->
> >   |   declarator initializer?
> >           -> {(scs == null)}? ^(DD {$ti} declarator
> > initializer?)
> >           -> {(scs != null)}? ^(DD {$scs} {$ti}
> > declarator initializer?)
> >           ->
> >   ;
> > 
> > etc.
> > 
> > Regards, Mark
> > 
> > -- 

-- 


More information about the antlr-interest mailing list