Bootstrapping a Compiler

It’s the technique used to create a compiler of a specific language written in the same language. (chicken or the egg dilemma)


What is given

  1. CPU (understands machine code)
  2. Assembler (translates assembly language into machine code)
Assembly Language → Assembler → Machine Code → CPU

How it’s solved

Let’s assume you have designed a new language called ABC.

  1. The first ABC compiler (v1) has to be written in assembly language (or machine code).
  2. Now you can use this ABC compiler (v1) to compile an ABC compiler (v2) written in ABC.
  3. Finally, you can use the ABC compiler (v2) to compile its own source code. (self-compiled)
ABC Compiler v1 (written in Assembly)
        │
        │ compiles
        ▼
ABC Compiler v2 (written in ABC)
        │
        │ compiles itself
        ▼
ABC Compiler v3 (self-compiled)