[antlr-interest] Bug with tree construction
Martin Probst
mail at martin-probst.com
Wed Nov 16 06:56:12 PST 2005
Hi,
I have the following code in a grammar file:
varDefn:
kd:Kdefine_variable^ q:bindVar! (td:typeDeclaration!)?
{ ... }
( COLON_EQUALS! expr
| ext:Kexternal
{ ... }
)
Which produces the following code directly after the code inserted for
the first { ... } block:
currentAST.root = varDefn_AST;
currentAST.child = varDefn_AST!=null &&
varDefn_AST.getFirstChild()!=null
? varDefn_AST.getFirstChild() : varDefn_AST;
currentAST.advanceChildToEnd(); // <- not important
This creates a currentAST AST Pair that has a root of varDefn_AST and a
child of varDefn_AST. When afterwards "expr" matches something,
automatic AST creation tries to add that to the currentAST tree by:
match(COLON_EQUALS);
expr();
astFactory.addASTChild(currentAST, returnAST);
Which in turn by default adds the returnAST as a sibling to the
currentAST.child AST, if present. This is not what I would expect, as
Kdefine_variable is supposed to be the root of the result ("^").
Is this a known bug for Version 2.7.5 (20050128)? Do you need more to
reproduce the error?
Martin
More information about the antlr-interest
mailing list