Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There's quite a few languages that bootstrap: https://en.wikipedia.org/wiki/Bootstrapping_%28compilers%29#...


So if you follow it all the way down, what does all these self-hosting code become? Machine code?


A common pattern used to be as follows:

Start by implementing in Assembly as little as possible for the programming language as an interpreter.

Meaning just one form of conditionals, just one looping construct, very few basic types, basic IO.

Then use the bare bones interpreter for the second stage, writing a real compiler that is able to process the same basic language and additional constructs.

Another alternative is to add some bytecode format that can then be used equally for interpretation or as input to native code generation.

Niklaus Wirth originally designed P-Code with the intent to make Pascal compilers easier to port. He wasn't thinking to use it as full OS VM, like the guys at UCSD did with they Pascal dialect.

Another trick is to design the bytecode in such a way that it can directly be translated to native code via a macro assembler. It won't generate fast code, but it will provide an easy path for a compiler instead.

Nowadays the Assembly step tends to be replaced by another language that can be found in most platforms, so many tend to choose C.

Not always because it is the best language to write compilers in, but rather because it is ubiquitous or there is some library the authors want to use, thus perpetuating the myth that all languages require C for those not so well versed in compiler design.


They usually need a previous version of the compiler to compile themselves. Turtles all the way down if you will.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: