[antlr-interest] Mismatched tree node
Jim Idle
jimi at temporal-wave.com
Fri Apr 2 08:26:13 PDT 2010
Use ANTLR Works to visualize the AST that you are producing with ->(X e+) and you should see that your tree grammar does not reflect it. You want:
T : ^(TOK_ARRAY_INDEX e+) ;
In your tree grammar. In general, the tree grammar rule is the RHS of your parser rule.
Jim
> -----Original Message-----
> From: antlr-interest-bounces at antlr.org [mailto:antlr-interest-
> bounces at antlr.org] On Behalf Of Christian Hoffmann
> Sent: Friday, April 02, 2010 4:22 AM
> To: ANTR Interest
> Subject: [antlr-interest] Mismatched tree node
>
> Hi,
>
> I struggling with the error "Mismatched tree node" at my C grammar.
> The error disappears if i remove the '+' at the imaginary node
> creation for TOK_ARRAY_INDEX to -> ^(TOK_ARRAY_INDEX expression)
> The examples in Terence book shows exactly this to collect input
> elements.
> The rule 'arrayDef' doesn't generate the error but i got only 1 node,
> even for multidimensional array definition like 'a[1][2][3];'
>
> // 1. problem
>
> arrayIdent
> : IDENT^ arrayDef
> ;
> arrayDef // like a[1][2][3]...
> : arrayDefTmp (arrayDefTmp)* -> ^(TOK_ARRAY_DEF arrayDefTmp+)
> ;
> arrayDefTmp
> : '['! intConst ']'!
> ;
>
> .....
>
> // 2. problem
>
> postfixExpression
> : methodCall
> | encapsulatedExpression
> | IDENT {
> ( '++' -> ^(TOK_POSTINC primaryExpression)
> | '--' -> ^(TOK_POSTDEC primaryExpression)
> | arrayIndex* //-> ^(primaryExpression arrayIndex)
> )
> ;
>
> arrayIndex
> : ('[' expression ']') -> ^(TOK_ARRAY_INDEX expression+)
> ;
>
>
> Can anyone give me a hint?
> Thx
>
>
> --
> Christian Hoffmann
> Ützenkamp 4
> 38118 Braunschweig
> Tel: 0171/7300609
> Web: www.c-hoffmann.de
> www.logical-arts.de
>
>
> 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