What are modern and old compilers written in?

2019-04-01 02:28发布

As a compiler, other than an interpreter, only needs to translate the input and not run it the performance of itself should be not that problematic as with an interpreter. Therefore, you wouldn't write an interpreter in, let's say Ruby or PHP because it would be far too slow.

However, what about compilers?

If you would write a compiler in a scripting language maybe even featuring rapid development you could possibly cut the source code and initial development time by halv, at least I think so.

To be sure: With scripting language I mean interpreted languages having typical features that make programming faster, easier and more enjoyable for the programmer, usually at least. Examples: PHP, Ruby, Python, maybe JavaScript though that may be an odd choice for a compiler

  • What are compilers normally written in? As I suppose you will respond with something low-level like C, C++ or even Assembler, why?

  • Are there compilers written in scripting languages?

  • What are the (dis)advantages of using low or high level programming languages for compiler writing?

7条回答
甜甜的少女心
2楼-- · 2019-04-01 03:04

The javac compiler from the SUN / Oracle JVM is written in Java; as is the compiler of Java used within the Eclipse IDE for the background compilation as you edit. Compilers for many functional languages are often written in that language, as functional languages are typically quite suited to writing compilers. Compilers for restricted languages (e.g. GPU programming such as GLSL/OpenCL) will not be written in languages executable on GPUs.

One fundamental issue is that the language compiled by a given compiler may not be a good language for implementing a compiler; I don't know of anyone writing compilers for FORTRAN in FORTRAN.

In essence, the implementation language of a compiler may or may not be an input language to that compiler, depending on the suitability of the languages involved and a host of other criteria from development time, required runtime performance, tool availability and developer familiarity.

查看更多
登录 后发表回答