[antlr-interest] philosophy about translation
Andy Tripp
antlr at jazillian.com
Fri Oct 6 11:35:36 PDT 2006
Johnicholas Hines wrote:
> Is the deep analysis that Andy Tripp's COBOL to Java project requires
> a corner case of ANTLR usage? It seems to me he's building at least a
> full dataflow graph, which I believe is more extreme than most
> transformations.
>
> My projects with antlr include things like "replicate bash's
> brace-expansion in a standalone tool", and "convert pure lambda
> calculus to continuation-passing style".
>
> As far as I can tell, these tasks are not "99% static analysis and 1%
> tree transformation". Admittedly, I have no working code, so perhaps
> you should take my opinions with dash of salt.
>
> Johnicholas
Yes, I agree mine is a "corner case" - but I think it's the case that
deserves
the name "one source programming language to another source programming
language translator".
and maybe even the shorthand "language translator". I think most people
using ANTLR
are doing stuff like you are, which is more "parsing and generating
source code".
The distinction because I think a lot of people mistakenly believe that
tools like ANTLR and
ASTs will "scale up" from simple stuff to real, complete translation. I
especially remember
the TXL documentation seeming to say basically "here's how you replace a
node in an AST,
and now you have what you need to translate one language to another". I
was quite unhappy
to discover that I got almost nowhere with that approach. Now I think
that's like saying
"To convert English to Spanish, replace 'Hello' with 'Hola', but the
adjectives after the nouns,
and so on". Meanwhile, people are spending their whole lives writing
English to Spanish
translators, an the simple "replace words with equivalents and put
adjectives after nouns"
got them about 0.00001% of the way there.
And yes, I do have to understand control flow, but not just that. I have
to understand
that when the format string of printf() ends with '\n', it's replaced
with println(), not print().
I have to be able to parse a printf() format string and know what
"%4.2d" means. And lots
more.
I don't want people to get the wrong impression when they hear
"look at how well this work for C- to Java"
that the same technique will be reasonable for C to Java.
Andy
p.s. or the other way to look at it is "I sure hope I haven't strayed
down the wrong track
a long time ago, so I'll keep explaining what I did and why, and see if
someone can tell me
where I went wrong".
More information about the antlr-interest
mailing list