[antlr-interest] Re: java.tree.g #(QUESTION expr expr expr)
micheal_jor
open.zone at virgin.net
Sat May 24 07:04:05 PDT 2003
"rustydstone" wrote:
> Hi,
>
> The following is slightly modified grammar from java.g and
java.tree.g
>
> conditionalExpression
> : logicalOrExpression
> ( QUESTION^ conditionalExpression COLON!
conditionalExpression )?
> ;
>
> #(QUESTION q1:. q2:. q3:.)
>
> When expression "(true || false)? 1 + 1 : 0 + 0" is processed the
> following q1, q2 and q3 ASTs are received (printed using
toStringList()):
>
> q1 ( || true false ) ( + 1 1 ) ( + 0 0 )
> q2 ( + 1 1 ) ( + 0 0 )
> q3 ( + 0 0 )
>
> Why does q1 contain q2 and q3? Why does q2 contain q3? I somehow
> expected that the output would be like the following:
> q1 ( || true false )
> q2 ( + 1 1 )
> q3 ( + 0 0 )
toStringList() does just that - it prints the list of nodes starting
from the specified node. The "list" being the node and it's following
siblings.
In the same vein toStringTree() should do what you wanted - it should
print the tree rooted at the specified node but not it's siblings[1*].
Cheers,
Micheal
[1*] I have botched up this behaviour in ANTLR/C# by overriding
ToStringTree() to print a nice tree-like representation and not a
lisp-like representation of the specified tree only. This will be
fixed and the nice tree-structured printing would be moved to new
methods - do I hear any better monikers than ToNiceList()/ToNiceTree
() or even ToTreeList()/ToTreeTree()?
Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
More information about the antlr-interest
mailing list