Search code examples
c++compiler-constructionprogramming-languagesc-preprocessor

Which backend languages should my compiler target?


I've written a compiler for a general-purpose programming language that produces an optimised parse tree of its input. This intermediate format is then run through a preprocessor to translate it into a target language for subsequent compilation to a native executable.

At present the only target language is C++, but I'd like to offer other solutions as well, in case certain programs might benefit from being compiled with a backend that better supports certain constructs in the source language.

Are there any languages that are designed for or very well suited to the role of compiler target?

I'm aware of LLVM, and though it's an exciting project in its own right, I believe it's too low-level to target directly. I'm looking for generic, mid- to high-level languages with high-quality implementations, whose syntax is capable of being produced by a C preprocessor — thus nothing like Python or Ruby. Support for lambdas would be nice, but isn't strictly necessary.


Solution

  • JavaScript, I'd add. Syntax like C, has lambdas, very popular, has very fast HQ implementations which compile to native code and is available everywhere. Double-plus: you can demo your compiler in any web browser and everybody is listening today, if you have something that cranks out JavaScript.