[antlr-interest] Overriding C target's pANTLR3_COMMON_TREE_ADAPTOR to create heterogeneous tree

Jack Pan Jack.Pan at Lewtan.com
Thu Jan 8 12:56:37 PST 2009


I'm thinking to take a shot at overriding C target's
pANTLR3_COMMON_TREE_ADAPTOR to create heterogeneous tree. Could some
experienced ANTLR user please give it a quick thought if I'm heading to
a brick wall here?

 

What I want to do:

 

I have a parser grammar generating a AST. It's almost java-free so I can
switch target language option easily after I tested it in AntlrWorks.
The tree has exactly the shape I needed.

 

I already have the following tree node classes implemented from
Composite pattern:

 

Class CNode

{

Public:

Vector<CNode> m_children;
};

 

Class CDistributionNode : public CNode {};

Class CTransactionNode : public CNode {};

etc. etc.

 

How difficult will it be to implement my own
pANTLR3_COMMON_TREE_ADAPTOR, to generate the same AST with my own node
types?

 

Then I would like to invoke generated parser code, get the AST from it.
I need to free the parser while keeping the AST in memory for later use.
Is there a way to detach the tree root point from parser?

 

My tree nodes will need to interact with the token object. Should I just
use the token type defined by ANTRL C target runtime, or I should make
copy asap? I'm not sure when the token objects are destroyed. (I have to
say I miss C# or Java here...)

 

Hopefully I can implement this. Then I will send out this as a sample to
implement custom TreeAdaptor in C target. 

 

Thanks,

 

Jack

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20090108/428bef9d/attachment.html 


More information about the antlr-interest mailing list