[antlr-interest] ANTLR3 Converting Java to C++ subset (sorta)

David Holroyd dave at badgers-in-foil.co.uk
Tue Mar 27 07:17:08 PDT 2007


On Tue, Mar 27, 2007 at 02:06:51PM +0000, David Holroyd wrote:
> On Tue, Mar 27, 2007 at 08:27:48AM -0400, Kailey Joanette wrote:
> > I will look into it. but how easy is it to do language translation?  Also, I
> > would like to mention that we will also be doing C++ parsing later to do
> > memory optimization and a number of other tweaks to code.  Would it be
> > accurate to assume I would have to do this separately to the Java to C++
> > conversion?
> 
> ANTLR will make all the Java syntax available to you in an AST to
> manipulate with pure Java code, an ANTLR tree parser, or whatever.
> 
> By using something the JDT DOM, you will get *extra* support on top of
> syntax recognition.  e.g. given...
> 
>   foo.get(bar)
> 
> ...either approach will tell you that you've got a method call, but a
> good Java representation will directly support you being able to ask for
> the types of the different variable references, so that you could
> translate, for instance, java.util.List accesses in one way, and
> java.util.Map accesses in another.  
> 
> Then, you code-up a load of translation logic based on what the model
> exposes from the source.
> 
> Of course, this approach is trying to do a better job with the
> language-specific issues, so it won't really help when you switch to a
> different input language, like C++.
> 
> So, if you're just looking to translate syntax, ANTLR on its own will do
> well.  If you want to translate some (tiny part) of the semantics too,
> consider a framework that 'knows' the code better.
> 
> Finally, even *if* you go for a more complex/capable representation, it
> will still fail to handle the really fiddly cases, like translating
> idioms between languages.

Well, not "fail to handle the really fiddly cases" maybe; more like "not
directly support you with really fiddly cases" :)


-- 
http://david.holroyd.me.uk/


More information about the antlr-interest mailing list