Reputation: 3381
I'm studying translation of languages (normally its just compilation). We study what to do to be able to translate from a language to another (say Java into Python but in our case C to assembler). I asked my teacher about the condition that the languages must satisfy to be able to do the translation. The answer was that there isn't any condition and that we can translate from any language to another (for example Java --> XML).
Is that really possible? What if one of the two language isn't Turing-complet language?
Upvotes: 1
Views: 150
Reputation: 49826
The answer was that there isn't any condition and that we can translate from any language to another (for example Java --> XML).
This is true in the sense that you could use XML to represent anything with a tree structure, and java is implicitly tree structured.
However, you could construct pairs of languages where this is not true, e.g. a language which describes arbitrary graphs cannot be translated to a language which can only describe trees.
However, if we're talking about translating programming languages, then the question (as you have identified), is whether the target language is as powerful as the source language. Where (as is the normal case) both languages are turing complete, this is a given. However, one cannot translate e.g. every Java program to regular expressions.
Upvotes: 1
Reputation: 1962
In theory you can translate any programming language to any other programming language. The example you gave, however, does not hold up because XML is not a programming language. You could certainly translate Java into an XML syntax but that language would not have any semantics. If you'd like you could define then and write a byte code compiler for your new Java like language with XML syntax. That would not be XML though. It'd be a new language with subset of XML as the syntax and Java's semantics.
In practise, if you have a real programming language, you can compile any language to it but you might have slightly different properties based on things that turning completeness does not account for. For example you might have really bad runtime on concurrent programs if you compile Haskell to python. In an extreme case, you can't do IO if you compile any normal language to the lambda calculus.
Upvotes: 0