[antlr-interest] philosophy about translation

Monty Zukowski monty at codetransform.com
Fri Oct 6 12:24:40 PDT 2006


Andy Tripp wrote:
> I think just this simple example that I brought up before actually
> brings the problem to the surface:
>
> String hello = "hello";
> String world = "world";
> printf("%s %s\n", hello, world);
>
> ...becomes...
>
> System.out.println("Hello World");
>
> I can't see how that can be done by treewalking. By the time the code is
> actually written to implement "printf to System.out.println",
> there will be almost no "tree-transformation" or even "tree walking" logic.
>

Well, I would have one pass that replaced all variable references of
variables that are defined and used before being modified with the
value from the declaration.  That would leave a printf("%s %s\n",
"hello", "world");

In a later pass I would check for and eliminate any variables that are
never referenced.

Also later I would have a printf rewrite rule that does string
substitution for any constant arguments.

Treewalking is just a handy way for me to do pattern matching.

Monty


More information about the antlr-interest mailing list