[antlr-interest] Problem with AST type in tree grammar in C target

Jim Idle jimi at temporal-wave.com
Fri Feb 18 15:13:41 PST 2011


You are telling to type them as pANTLR3_COMMON_TREE and so that's what it
does. It's your fault, not ANTLR's ;-) The ability to specify the type is
just a left over from the Java, basically you should not do it as
everything is just passed around via the base pointer.

Jim

> -----Original Message-----
> From: Kevin J. Cummings [mailto:cummings at kjchome.homeip.net]
> Sent: Friday, February 18, 2011 2:19 PM
> To: Jim Idle
> Subject: Re: [antlr-interest] Problem with AST type in tree grammar in
> C target
>
> On 02/18/2011 04:59 PM, Jim Idle wrote:
> > The type of a node is pANTLR3_BASE_TREE and that is the default, you
> > do not need to specify it as it is ALWAYS that unless you want to do
> > lots and lots of work, which you don't.
>
> I had used pANTR3_COMMON_TREE for my parser AST, so I just "assumed" I
> needed to do the same for the Tree parser since it was reading in those
> nodes.
>
> > Now the default tree factory actually creates pANTLR3_COMMON_TREE but
> > this contains pANTLR3_BASE_TREE and it is the pointer to the base
> tree
> > that is used because EVERY tree node implementation must contain one
> of these.
> >
> > So, when you use the pointer, if you want to access the COMMON_TREE,
> > then you cast the 'super' pointer in the base tree to
> > pANTLR3_COMMON_TREE and hey presto.
> >
> > {
> > 	pANTLR3_COMMON_TREE ct = (pANTLR3_COMMON_TREE)($assLhs->super);
> > }
>
> But, the example I quoted below is the code that ANTLR generated, not
> something from my actions.  Shouldn't ANTLR get it right in its
> generated code?
>
> I will play further with trying to remove the AST type from the tree
> grammar and see what happens....
>
> > Jim
>
> --
> Kevin J. Cummings
> kjchome at verizon.net
> cummings at kjchome.homeip.net
> cummings at kjc386.framingham.ma.us
> Registered Linux User #1232 (http://counter.li.org)


More information about the antlr-interest mailing list