[antlr-interest] Navigate the C target AST

Richard Connon conan at irconan.co.uk
Tue Dec 7 14:51:04 PST 2010


Hi. I'm trying to navigate the AST built using the ANTLR3 C target.

I'm wondering how the token information is stored in the tree nodes. It 
seems there are two types of tree nodes. ANTLR3_BASE_TREE and 
ANTLR3_COMMON_TREE and I can set my grammar to produce the AST with 
either one.

The documentation suggests that an ANTLR3_BASE_TREE has no token 
information yet it contains a pointer to the getToken(ANTLR3_BASE_TREE) 
function. Can anyone clarify this?

I've been trying out each type to try and work it out.

getToken(ANTLR3_BASE_TREE) on the ANTLR3_BASE_TREE seems to return 0x0 
which would support what the docs say about it having no token "payload" 
but then why does this function exist.

When using ANTLR3_COMMON_TREE instead since I assumed this to be the 
solution, the token member of the struct is also 0x0
Finally doing commonTree->baseTree.getToken(&commonTree->basetree) as a 
last resort caused the program to segfault in dupTree()

All in all I'm a bit confused about where the "content" of the AST 
actually lies.


More information about the antlr-interest mailing list