[antlr-interest] New article on StringTemplates and Treewalkers
Andy Tripp
atripp at jazillian.com
Tue Jan 10 14:50:51 PST 2006
>
>
>I think that Andy was more bothered by how to translate something like
>
>int func(int x)
>{
> if(x=5)
> return 3;
>}
>
>since even though it looks like java, it is not valid java.
>
>Shmuel
>
I'm worried about that too :)
I do mention that issue in the article, saying "how do you make sure x
is a boolean when you have if(x)".
My ForceToBooleanRule is one of the most complex, and one of the few
that uses an ANTLR parser :)
The interesting thing about your example is that the "natural" Java
translation (what a person would write) is
if (x == 5)
whereas any traditional AST-walking translator would probably produce
if ((x = 5) != 0)
While the second one is technically correct, and is probably what my
product would produce today,
my product is designed so that I can easily add a rule to check for a
"if (v=n)" bug, and go ahead and
fix the bug during translation. And I can and do add those sorts of
rules! Do not try this at home
with your treewalking translator, kids :)
Andy
More information about the antlr-interest
mailing list