[antlr-interest] Mismatched tree node
Christian Hoffmann
Sanus at gmx.de
Fri Apr 2 04:21:44 PDT 2010
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
More information about the antlr-interest
mailing list