[antlr-interest] Print an AST in original order
Kevin J. Cummings
cummings at kjchome.homeip.net
Tue Jul 29 10:13:28 PDT 2008
Varun Bhargava wrote:
> Hi All,
>
> I’m using ANTLR3 for C# target. My problem is to load up a statement
> into a tree, so some substitutions to the tree and then print out the
> tree in original order to re-generate the input statement but with some
> substitutions.
>
> I cannot seem to print the AST in its original order. For EG;
>
> WHERE
>
> |
>
> AND
>
> / \
>
> = =
>
> / \ / \
>
> A 5 b 10
Doesn't your tree actually look like this:?
WHERE
|
AND
|
= ------=
| |
A - 5 b - 10
I think your problem comes in how you are interpreting your
root/children associations. Insert your root between binary children,
or before a unary subtree (as if there is no LHS). It seems to work for
this example....
> The above tree should be printed as WHERE A=5 AND b = 10
>
> However this is not the case in ANTLR. Has anyone done this before? If
> yes could you please point me in the right direction or give me some
> sample code?
What are you using to do this with?
> Thanks
>
> Varun
--
Kevin J. Cummings
kjchome at rcn.com
cummings at kjchome.homeip.net
cummings at kjc386.framingham.ma.us
Registered Linux User #1232 (http://counter.li.org)
More information about the antlr-interest
mailing list