[antlr-interest] Custom AST Node
Scott Amort
jsamort at gmail.com
Fri Aug 4 07:14:12 PDT 2006
Hi Henry,
Henry Butowsky wrote:
> However in order to get the program to compile I have had to add
> casts where the AST nodes refer to a child or sibling e.g
>
> run((RefncoAST)(blk->getFirstChild()));
> var=out((RefncoAST)(exp->getFirstChild()));
>
> I would like to sort out ncoAST so I don't have to add casts as code
> like above is doted throughout my tree parser -- Im no expert in C++
> Pleae help
Unfortunately, you are stuck with casting in this situation. The
standard way to fix this problem would be to override getFirstChild() in
your custom AST to have it return a RefncoAST type. However, you will
get a compiler error related to an invalid covariant return type in this
case as RefncoAST is not a derived class of RefAST (a C++ requirement
for covariant returns, i.e. a virtual function being overridden to
return a different type). RefAST is a typedef for ASTRefCount<AST>, and
RefncoAST is a typedef for ASTRefCount<ncoAST>: two separate types.
Best,
Scott
More information about the antlr-interest
mailing list