views:

92

answers:

5

Hi, As a pet project, I was thinking about writing a program to migrate applications written in a language A into a language B. A and B would be object-oriented languages. I suppose it is a very hard task : mapping language constructs that are alike is doable, but mapping libraries concepts will be a very long task.

I was wondering what tools to use, I know this has to do with compilation, but I'm a bit afraid to use Lex and Yacc and all that stuff. I was thinking of maybe using the Eclipse Modeling Framework, which would help me write models (of application code) transformations in a readable form. But first I would have to write parsers for creating the models (and also create the metamodel from the language grammar).

Are there tools that exist that would make my task easier?

A: 

I think this is almost impossibly hard, especially as a personal project. But if you are going to do it, don't make life even more difficult for yourself by trying to come up with a general solution. Choose two specific real-life programming languages ind investigate the possibities of converting between them. I think you will be shocked by the number of problems and issues this will expose.

anon
Yes, I haven't been clear : I have chosen 2 specific languages. I don't want to make a general solution for all the existing languages, that would be madness.
Alain Michel
Well, don't keep us in suspense - which languages?
anon
I'm not sure yet, but I think the source language/framework would be Java/Swing and the target some RIA language like Flex or a Javascript/Ajax framework.
Alain Michel
A: 

There are some tools for direct migration for some combinations of A and B.

There are a variety of reverse engineering and code generation tools for different languages and platforms. It's fairly rare to see reverse engineering tools which capture all the semantics of the source language, and the semantics of UML are not well defined ( since it's designed to map to different implementation languages, it itself doesn't define a complete execution model for its behavioural representations ), so you're unlikely to be able to reverse engineer and generate code between tools. You may find one tool that does full reverse engineering and full code generation for your A and B languages, and so may be able to get somewhere.

In general you don't use the same idioms on different platforms, so you're more likely to get something which emulates A code on B rather than something which corresponds to a native B solution.

Pete Kirkham
I agree, I don't want to use UML, it wouldn't be precise enough to do the migration. When I write about "model", I thinking of using, for example, a Java metamodel. The Java code would be parsed into a Java Model, in fact that would let me store the abstract syntax tree, and use tools (like QVT, Eclipse ATL, etc.) to transform the Java program into a model B (conform to a metamodel of a programming language B).
Alain Michel
The Eclipse Modeling Framework, QVT and ATL are all based on UML metamodel, or at least were when they started.
Pete Kirkham
Yeah but using the metamodel of UML (MOF), i.e. a metametamodel (a metamodel to define metamodels) does not mean using UML. UML is a complex metamodel which has hundreds of concepts whereas you can define smaller custom metamodels, for example a metamodel for UI, for a specific business.QVT and ATL can transform UML models but also models from any other metamodel.
Alain Michel
A: 

If you want to use Java as the source language(that language you try to convert) than you might use Checkstyle AST(its used to write Rules). It gives you tree structure with every operation done in the source code. This will be much more easier than writing your own paser or using regex.

You can run com.puppycrawl.tools.checkstyle.gui.Main from checkstyle-4.4.jar to launch Swing GUI that parse Java Source Code.

martin
A: 

Based on your comment

I'm not sure yet, but I think the source language/framework would be Java/Swing and the target some RIA language like Flex or a Javascript/Ajax framework. – Alain Michel 3 hours ago

Google Web Toolkit might be worth a look.

Pete Kirkham
A: 

You can use special transformation tools/languages for that TXL or Stratego/XT.

Also you can have a look and easily try Java to Python and Java to Tcl migrating projects made by me with TXL.

You are right about mapping library concepts. It is rather hard and long task. There are two ways here:

  • Fully migrate the class library from language A to B
  • Migrate classes/functions from language A to the corresponding concepts in language B

The approach you will choose depends on your goals and time/resources available. Also in many cases you wont be doing a general A->B migration which will cover all possible cases, you will need just to convert some project/library/etc. so you will see in your particular cases what is better to do with classes/libraries.

msorc