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

Karim Chichakly kchichakly at iseesystems.com
Fri Feb 18 13:13:19 PST 2011


With the C target, you have to use:

    ASTLabelType = pANTLR3_BASE_TREE;

And all the nodes you get will be of this type.

Karim


On Fri, Feb 18, 2011 at 3:57 PM, Kevin J. Cummings <
cummings at kjchome.homeip.net> wrote:

> 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
> kjchome at verizon.net
> cummings at kjchome.homeip.net
> cummings at kjc386.framingham.ma.us
> 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
>


More information about the antlr-interest mailing list