HiveBrain v1.2.0
Get Started
← Back to all entries
patternMinor

Why translating a program from one high-level programming language directly into another is difficult?

Submitted by: @import:stackexchange-cs··
0
Viewed 0 times
whytranslatinglevelintoprogramminghighprogramlanguageonedirectly

Problem

I am looking for a better explanation (research level, papers) to answer:

Why translating a program from one high-level programming language directly into another is difficult?

Note: When I say difficult I don't mean "hard" - i.e. I am not taking about computational complexity here simply because I am unaware of such results, but you are very much welcome to correct my ignorance.

I understand that at the core of the argument can say something like one-to-one mapping for such translation simply does not exists.

In general, I am not comfortable with terminology used in my own question.

We know from text books: Low-level language - each command or object of the language has one-to-one mapping to CPU commands (e.g. Assembler). All other languages are High-level.

Is there a way to reformulate the question into FSA formalism like with regular languges, or some other formalism. But I don't think Church–Turing thesis can help here - it is not about computability or existence of a proof.

PS

My motivation is very simple - I want to discuss/answer how difficult is such a problem for example in translating PHP to Java. Please note that direct translation is indeed a mapping of language commands or objects (e.g. HipHop does not qualify).

Probably any pragmatic solution would be indirect translation, i.e. in order to (partially) convert a program P written in high-level language A into a high-level language B:

  • (complexity lowering) convert codebase of program P from A to low or inter-mediate level language C



  • (shared codebase) resue parts of converted codebase of program P by calling commands in low or inter-mediate level language C from high level language B

Solution

The task is simple. Here are two naive strategies.

Say we want to compile from A to B.

-
Pick a language C for which you have a compiler A $\to$ C and an interpreter for $C$ in $B$.

Create a new program in B that includes the compilate (in C) as string and the code of the interpreter.

-
Compile code in A to machine code or intermediate language. Translate line by line to B.

Both give horrible programs -- but you did not require anything fancy.

The more theoretical answer is: we know that effective (i.e. Turing-computable) compilers exist between any two Turing-complete languages, since such define nothing but an admissible numbering.

Context

StackExchange Computer Science Q#48857, answer score: 3

Revisions (0)

No revisions yet.