94% of Rust compiler was written in Rust. So I can't understand how is it possible? Because for compiling rustc you already must have some rust compiler. Can someone explain how it works and how rust compiler was created?
Asked
Active
Viewed 9,095 times
8
-
https://en.wikipedia.org/wiki/Bootstrapping_%28compilers%29#The_chicken_and_egg_problem – Jacob Krall Jan 11 '16 at 19:58
-
2This is explained well in an existing question: http://stackoverflow.com/questions/193560/writing-a-compiler-in-its-own-language – voithos Jan 11 '16 at 19:58
1 Answers
12
Simply put, once you have a compiler that compiles code, you can use that to develop and compile a new compiler. That new compiler can "understand" whatever language it's designed to compile.
So, suppose there was some C++ based rust compiler, and rust code was developed that compiles to a rust compiler, once you build that you have a rust based rust compiler.

Amit
- 45,440
- 9
- 78
- 110
-
14I know you are just making a hypothetical situation but initial `Rust` compiler was written in `OCaml` not `C++`. https://en.wikipedia.org/wiki/Rust_(programming_language) – Akavall Jan 11 '16 at 23:11