Skip to main content

Learn · Topic path

Compilers

Follow a program from source text to a native executable. You design a small language, then write each stage that turns it into x86-64 machine code, testing every stage before the next one depends on it.

Chapters
10
Project
1
Explorer
1

Recommended path

  1. Read Article · 12 min read

    x86-64 Assembly Hello World in Docker (NASM & Linux Guide)

    See what the compiler will eventually have to emit

  2. Build Compiler project · ch. 3 · 16 min read

    How to Build a Lexer in C++: Lexical Analysis and Tokens

  3. Build Compiler project · ch. 4 · 28 min read

    How to Build a Recursive Descent Parser in C++ with an AST

  4. Explore Explorer

    Expression Parser Explorer: step through precedence and the AST

    Type an expression and watch the tokens, the recursive-descent call stack and the AST.

Every chapter

Frequently asked questions

Do I need a compiler theory background?

No. The path assumes you can read C++ and use a terminal. Grammars, tokens, abstract syntax trees and intermediate representations are introduced as each stage is built.

Why write the compiler by hand instead of using a parser generator?

A hand-written lexer and recursive descent parser keep every decision visible in ordinary code, which makes precedence, error reporting and the shape of the AST easier to understand and debug.

Which CPU does the compiler target?

Linux x86-64. The backend emits NASM assembly, and NASM plus the system linker turn it into a native executable. Docker provides the Linux environment on any host.

How does this path relate to computer architecture?

Code generation is where the two meet: registers, the stack and calling conventions are architecture concepts. The architecture path's CPU chapter is useful background before the backend chapters.