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: [email protected] [mailto:antlr-interest-
> [email protected]] 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




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