[antlr-interest] Custom AST breaks things

Edward Povazan epovazan at telus.net
Mon Oct 6 15:26:14 PDT 2003


Hello,

I just finished my parser and tree parser (yay), and am now adding the 'code
generation' part for my little scripts.
I am playing with adding my own tree nodes, each with a 'compile' method to
create the necessary evaluation objects for this subtree.
However, now my tree parser does odd things.
I get class cast errors (it is trying to cast to a CommonAST and I derived
from a BaseAST). So I derived from a CommonAST to prevent this.
Still problems like 'expecting AST node: if' and so on.
Even if I add
tokens { PLUS<AST=antlr.CommonAST>; } I get these errors. Without this, it
all works fine.

I normally created parsers to create robust access to structured data, but
never used it to 'generate code' (in my case a lot of new NodeName(left,
right) etc).
Where is the best place to insert this? I can add it to the tree parser:
#(OR l=expr r=expr) { res = new OR(l, r); }
or I can generate it via my compile() method call in custom AST nodes
(assuming I get it to work, in which case I don't need the tree parser).
However I would also like to print the expressions, which I do via a print()
method in my custom AST nodes. To do this with the tree parser, I would need
to have a separate tree parser (correct?) which seems a little verbose.
Any hints of the ideal way to attack this?

Thanks.


 

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/ 




More information about the antlr-interest mailing list