Overview • Languages • Quick Start • Requirements • Book
Edition 1.0 Complete
Four languages covering interpretation, compilation, type systems, and object-oriented programming.
LLVM code generation, JIT compilation, type inference, and memory management.
This book arose from frustration with the lack of modern, clear, and concise teaching materials for beginners who want to learn how to create their own programming language.
"If you don't know how compilers work, then you don't know how computers work" 1
"If you can't explain something in simple terms, you don't understand it" 2
The book teaches programming language implementation through four progressively complex languages:
| Language | Type System | Execution | Features | Rust Version |
|---|---|---|---|---|
| Calculator | None | Interpreter/VM/JIT | Arithmetic expressions | stable / nightly |
| Firstlang | Dynamic | Interpreter | Variables, functions, recursion | stable 1.70+ |
| Secondlang | Static | LLVM JIT | Type inference, compilation | nightly + LLVM |
| Thirdlang | Static | LLVM JIT | Classes, methods, OOP | nightly + LLVM |
create-your-own-lang-with-rust/
├── calculator/ # Simple arithmetic (interpreter, VM, JIT backends)
├── firstlang/ # Interpreted language with recursion
├── secondlang/ # Compiled language with type inference
├── thirdlang/ # Object-oriented with classes and methods
└── book/ # mdbook source for createlang.rs
Each language has its own README with detailed instructions.
cd firstlang
cargo run -- examples/fibonacci.fl # Run a program
cargo run # Start REPLcd secondlang
rustup run nightly cargo run -- examples/fibonacci.sl
rustup run nightly cargo run -- --ir examples/fibonacci.sl # View LLVM IRcd thirdlang
rustup run nightly cargo run --bin thirdlang -- examples/point.tl
rustup run nightly cargo run --bin thirdlang -- examples/counter.tlcd calculator
cargo run --bin main examples/simple.calc # Interpreter
cargo run --bin main --features vm examples/simple.calc # VM
rustup run nightly cargo run --bin main --features jit examples/simple.calc # JITcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh# Install nightly
rustup toolchain install nightly
# Install LLVM
# macOS:
brew install llvm
# Debian/Ubuntu:
# See https://apt.llvm.org/Check your LLVM version and update Cargo.toml accordingly:
| LLVM Version | inkwell feature |
|---|---|
| 20.x | llvm20-1 |
| 19.x | llvm19-1 |
| 18.x | llvm18-1 |
# All projects
cargo test -p calculator -p firstlang
rustup run nightly cargo test -p secondlang -p thirdlangcd book
mdbook serve # Local preview at http://localhost:3000
mdbook build # Build static site
Support
If you found this project useful, please consider donating to: