Search code examples
programming-languagesmetaprogrammingcode-generation

is it possible to markup all programming languages under object oriented paradigm using a common markup schema?


i have planned to develop a tool that converts a program written in a programming language (eg: Java) to a common markup language (eg: XML) and that markup code is converted to another language (eg: C#).

in simple words, it is a programming language converter that converts program written in one language to another language.

i think it is possible but i don know where to start. i wanna know the possibilities to do so and information about some existing system.


Solution

  • What you are trying to do is extremely hard, but if you want to know what you are up for I've listed the steps you need to follow below:

    First the hard bit:

    1. First you obtain or derive an operational semantics for your source and target languages.

    2. Then you enhance the semantics to capture your source and target memory models.

    3. Then you need to unify the two enhanced-semantics within a common operational model.

    4. Then you need to define a mapping from your source languages onto the common operational model.

    5. Then you need to define a mapping from your operational model to your target language

    Step 4, as you pointed out in your question, is trivial.
    Step 1 is difficult, as most languages do not have sufficiently formal semantics specified; but I recommend checking out http://lucacardelli.name/TheoryOfObjects.html as this is the best starting point for building a traditional OO semantics.
    Step 2 is almost certainly impossible in general, but may be merely obscenely difficult if you are willing to sacrifice some efficiency.
    Step 3 will depend on how clean the result of step 1 turned out, but is going to be anything from delicate and tricky to impossible.
    Step 5 is not going to be trivial, it is effectively writing a compiler.

    Ultimately, what you propose to do is impossible in general, due to the difficulties inherited in steps 1 and 2. However it should be difficult, but doable, if you are willing to: severely restrict the source language constructs supported; pretty much forget handling threads correctly; and pick two languages with sufficiently similar semantics (ie. Java and C# are ok, but C++ and anything-else is not).