[antlr-interest] Manual tree construction in 2.7.6 (buggy?)
Micheal J
open.zone at virgin.net
Mon Mar 27 15:41:25 PST 2006
> I construct the tree by hand like this:
>
> decl_default!
> : d:DEFAULT i:IDENT COMMA e:exp SEMI
>
> {## = #(#d, #([IF,":IF"],
> #([EQ_EQ,"=="],#i,#([NIL,"NIL"])),
> #([STMTS,"STMTS"],
> #([EXPR,"EXPR"],
> #([BECOMES,"BECOMES"],#i,#e))
> )
> )
> );
> }
> ;
>
> When I dump the tree (or visualize it with antlr.astframe) I see this:
>
> ( :DEFAULT ( :IF ( == x NIL 1) ( STMTS ( EXPR ( BECOMES x NIL 1 )))))
>
> That is, there is a spurious "1" in the test, and a spurious
> "NIL" in the assignment. Yet, the tree constructor looks OK
> to me. Am I doing something wrong
Yes. You are trying to add the single IDENT node to two different AST
[sub-]trees.
You need to copy the node if you wish to use it multiple times. Use
dupTree() for that and be sure to set the first-child and next-sibling links
appropriately.
Cheers,
Micheal
More information about the antlr-interest
mailing list