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.

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);
}

Jim


> -----Original Message-----
> From: [email protected] [mailto:antlr-interest-
> [email protected]] On Behalf Of Kevin J. Cummings
> Sent: Friday, February 18, 2011 12:58 PM
> To: [email protected]
> Subject: [antlr-interest] Problem with AST type in tree grammar in C
> target
>
> I'm trying to implement a Tree Grammar for my Lexer and Parser.
>
> In my Tree Grammar, I specify:
>
> > tree grammar m2Emit;
> >
> > options { language=C;
> >           ASTLabelType=pANTLR3_COMMON_TREE;
> >         }
>
> Further down, I have a rule:
>
> > stmt
> >     : ^(ASSIGN assLhs=ref assExp=exp )
> >     ;
>
> When I compile, I see the following errors:
>
> > m2Emit.c: In function 'm2Emit_exp_return exp(m2Emit_Ctx_struct*)':
> > m2Emit.c:1113:20: error: cannot convert 'ANTLR3_BASE_TREE_struct*' to
> > 'ANTLR3_COMMON_TREE_struct*' in assignment
> > m2Emit.c: In function 'm2Emit_ref_return ref(m2Emit_Ctx_struct*)':
> > m2Emit.c:2193:20: error: cannot convert 'ANTLR3_BASE_TREE_struct*' to
> > 'ANTLR3_COMMON_TREE_struct*' in assignment
>
> In m2Emit.c, I can see the following code:
>
> >     retval.start = LT(1); retval.stop = retval.start;
>
> It looks like LT(1) is an ANTLR3_BASE_TREE_struct*, while retval.start
> is an ANTLR3_COMMON_TREE_struct*.
>
> Is this a bug, or did I miss some important documentation?
>
> In case it matters, I'm trying to compile as C++....
>
>
> --
> Kevin J. Cummings
> [email protected]
> [email protected]
> [email protected]
> Registered Linux User #1232 (http://counter.li.org)
>
> 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

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to