[antlr-interest] Tree construction - Adding subtrees
Stephen Tuttlebee
themightystephen at googlemail.com
Wed Mar 9 16:42:47 PST 2011
One last attempt to make the code display better:
componentDefinition
: ^(COMPONENT_DEF IDENTIFIER ^(BOUNDARY_DECLS boundaryDeclaration*)
^(FIELD_DECLS fieldDeclaration*) runMethodDeclaration* ^(HANDLER_DECLS
handlerDeclaration*) ^(METHOD_DECLS methodDeclaration*))
{ ... some actions here you can ignore... }
-> ^(COMPONENT_DEF IDENTIFIER ^(BOUNDARY_DECLS boundaryDeclaration*)
^(FIELD_DECLS fieldDeclaration*) runMethodDeclaration*
^(HANDLER_DECLS handlerDeclaration*
{
for(String boundaryName : boundariesWithNoHandler) {
// .... calculate/get values to put in subtree ...
/* I want to be able to use ANTLR's friendly tree construction
syntax here somehow whilst in the middle of this action.
Every iteration of the for loop creates a new subtree --- if I
can't do it this way, what is the tree construction code I would need
here? */
^(HANDLER_DECL {$boundaryName} ^(IDENT {$b.getType})
{$b.getDirectionString()} ^(BLOCK BLOCK_STATEMENT))
} // end for
}
) ^(METHOD_DECLS methodDeclaration*))
;
Hope that displays better.
On 09/03/2011 23:21, Stephen Tuttlebee wrote:
> componentDefinition
> : ^(COMPONENT_DEF IDENTIFIER ^(BOUNDARY_DECLS
> boundaryDeclaration*) ^(FIELD_DECLS fieldDeclaration*)
> runMethodDeclaration* ^(HANDLER_DECLS handlerDeclaration*)
> ^(METHOD_DECLS methodDeclaration*))
> { ... some actions here you can ignore... }
> -> ^(COMPONENT_DEF IDENTIFIER ^(BOUNDARY_DECLS
> boundaryDeclaration*) ^(FIELD_DECLS fieldDeclaration*)
> runMethodDeclaration*
> ^(HANDLER_DECLS handlerDeclaration*
> {
> for(String boundaryName :
> boundariesWithNoHandler) {
> // .... calculate/get values to put in
> subtree ...
>
> /* I want to be able to use ANTLR's
> friendly tree construction syntax here somehow whilst in the middle of
> this action.
> Every iteration of the for loop
> creates a new subtree --- if I can't do it this way, what is the tree
> construction code I would need here? */
> ^(HANDLER_DECL {$boundaryName} ^(IDENT
> {$b.getType}) {$b.getDirectionString()} ^(BLOCK BLOCK_STATEMENT))
> } // end for
> }
> )
> ^(METHOD_DECLS methodDeclaration*))
> ;
More information about the antlr-interest
mailing list