Language translators: everything you need to build

I'm just wondering if there is any program / application out there that will allow you to inject code in one language and translate it into another language like asm. It seems perfectly possible ... so does something like this exist?

+1


a source to share


6 answers


Yes. They are called compilers.

Compilers are just one example of a class of programs called language translators.



Compilers convert higher-level languages ​​such as C ++ and Java to lower-level languages, including VM bytecodes, assembly, C, or directly into object-coded machine code.

+13


a source


This is effectively what any compiler does, since assembler is just another form of machine code. I believe that GCC does this explicitly, and you can ask it to show you an intermediate assembler. For example, take a look at the GNU Assembler .



+4


a source


Problems arise when you say that something is "perfectly possible." A feature of one language often does not translate directly or easily to another; why we choose the language for the problem in the first place! For example converting Fibonacci number from Java to C is trivial, but for Haskell? It's still doable of course, but try converting a program that opens posix streams and listens on multiple ports for different bits of network traffic.

Almost every piece of useful code is widely used in external libraries, many of which are not open source. Other than that, what do you think should be translated to C? Java even?

def method( f ):
    G = {'a':1}
    f(G)

def f( x ):
    print( [ (key, value) for (key,value) in x.items() ] )

method(f)

      

This task is inherently more difficult than it seems for anything other than the most trivial case (the C language for the C language). The transition between static and dynamically typed languages ​​will be as rough as any language.

+1


a source


You may be interested in Haxe, see http://haxe.org/ .

+1


a source


Here is a program to convert .NET code to Java, PHP, JavaScript and ActionScript http://jsc.sourceforge.net/

0


a source


There are tools that allow you to translate one language into another. Basically, there is a parser, translator and printer.

The parser explicitly parses the source in the AST .

The translator then has to convert the AST to structures that make sense in the target language.

Finally, the printer understands post-transformed structures and can output this target code.

0


a source







All Articles