How can you build heterogeneous ASTs when the corresponding nodes are created in an action.
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Franck_Yvetot
Posted On:   Thursday, August 29, 2002 05:48 AM

Most of my AST nodes have the same default type set by a parser.setASTNodeType("MyCommonAST") statement. A few of them have a different type MySymbolAST because they carry symbol related information. I specified their type in the token section: token { METHOD_DEF etc... } and requested the AST construction in an action clause (NB. simplified example): functionDefinition![AST m, AST t] : // modifiers and function type as rule params id:IDENT // method name LPAREN! pl:parameterDeclarationList RPAREN! // params fb:functionBlock { ## = #( #[METHOD_DEF],m,t,id,pl,fb); } ; Unfortunately, in   More>>

Most of my AST nodes have the same default type set by a

parser.setASTNodeType("MyCommonAST")
statement. A few of them have a different type MySymbolAST because they carry
symbol related information. I specified their type in the token section:

			
token { METHOD_DEF etc... }

and requested the AST construction in an action clause (NB. simplified example):


			functionDefinition![AST m, AST t] : // modifiers and function type as rule params
			
id:IDENT // method name
LPAREN! pl:parameterDeclarationList RPAREN! // params
fb:functionBlock
{ ## = #( #[METHOD_DEF],m,t,id,pl,fb); }
;


Unfortunately,
in the result tree, the generated METHOD_DEF AST has a type of MyCommonAST instead of the
expected MySymbolAST . Is there a way to force antlr to use the AST type declared
in the token section ?

   <<Less
About | Sitemap | Contact