[antlr-interest] transforming AST's in place when generated
Carter Cheng
carter_cheng at yahoo.com
Sat Feb 23 10:16:56 PST 2008
Thanks Mark. Just one followup question is there a way
to explicitly pass back a forest in ANTLR? i.e. when
you do
-> init_declarator+
it seems like you are not really passing back a rooted
tree.
Thanks again,
Carter.
--- 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
>
> --
>
____________________________________________________________________________________
Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ
More information about the antlr-interest
mailing list