[antlr-interest] Navigate the C target AST

Jim Idle jimi at temporal-wave.com
Tue Dec 7 16:39:54 PST 2010


Yes - do not use ASTLabelType, you want the default BASE_TREE

Jim

> -----Original Message-----
> From: Richard Connon [mailto:conan at irconan.co.uk]
> Sent: Tuesday, December 07, 2010 3:31 PM
> To: Jim Idle
> Subject: Re: [antlr-interest] Navigate the C target AST
> 
> On 07/12/10 23:26, Jim Idle wrote:
> > Use the super pointer in the ANTLR3_BASE_TREE and cast it to
> > pANTLR3_COMMON_TREE.
> 
> Is that different to setting
> ASTLabelType = pANTLR3_COMMON_TREE;
> and using the COMMON_TREE provided?
> 
> > The getToken returns the BASE_TOKEN, which  has a super, which is
> casy
> > to COMMON_TOKEN.
> 
> every time I've run getToken so far it's returned 0x0 so casting it
> would hardly help...

When you are doing it correctly, it will.

> 
> > Check: makeDot in basetreeadaptor for some examples.

Again, check that function in the source, but this time do not use
generating options. Get the function to work for you

nodes	= antlr3CommonTreeNodeStreamNewTree(psrReturn.tree,
ANTLR3_SIZE_HINT);
dotSpec   = nodes->adaptor->makeDot(nodes->adaptor, psrReturn.tree);


Also, look at the code for the adaptor.

Jim


> >
> > You can only get tokens for nodes that have them of course.
> >
> > Jim
> >
> >> -----Original Message-----
> >> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> >> bounces at antlr.org] On Behalf Of Richard Connon
> >> Sent: Tuesday, December 07, 2010 2:51 PM
> >> To: antlr-interest at antlr.org
> >> Subject: [antlr-interest] Navigate the C target AST
> >>
> >> 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.
> >>
> >> List: http://www.antlr.org/mailman/listinfo/antlr-interest
> >> Unsubscribe:
> >> http://www.antlr.org/mailman/options/antlr-interest/your-
> >> email-address
> >
> >
> > List: http://www.antlr.org/mailman/listinfo/antlr-interest
> > Unsubscribe:
> > http://www.antlr.org/mailman/options/antlr-interest/your-email-
> address




More information about the antlr-interest mailing list