ehsanmok/create-your-own-lang-with-rust

Create your own programming language with Rust

Rust

957

65 commits

updated Oct 3, 2026

See the code

See what people are saying

README

CreateLang.rs Logo

Create Your Own Programming Language with Rust

Learn compiler fundamentals by building four languages from scratch

Overview • Languages • Quick Start • Requirements • Book

CI GitHub Pages Read the Book License


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.


Overview

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

Languages

The book teaches programming language implementation through four progressively complex languages:

LanguageType SystemExecutionFeaturesRust Version
CalculatorNoneInterpreter/VM/JITArithmetic expressionsstable / nightly
FirstlangDynamicInterpreterVariables, functions, recursionstable 1.70+
SecondlangStaticLLVM JITType inference, compilationnightly + LLVM
ThirdlangStaticLLVM JITClasses, methods, OOPnightly + 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.

Quick Start

Firstlang (stable Rust)

cd firstlang
cargo run -- examples/fibonacci.fl    # Run a program
cargo run                              # Start REPL

Secondlang (nightly + LLVM)

cd secondlang
rustup run nightly cargo run -- examples/fibonacci.sl
rustup run nightly cargo run -- --ir examples/fibonacci.sl   # View LLVM IR

Thirdlang (nightly + LLVM)

cd thirdlang
rustup run nightly cargo run --bin thirdlang -- examples/point.tl
rustup run nightly cargo run --bin thirdlang -- examples/counter.tl

Calculator

cd calculator
cargo run --bin main examples/simple.calc                                            # Interpreter
cargo run --bin main --no-default-features --features vm examples/simple.calc        # VM
rustup run nightly cargo run --bin main --no-default-features --features jit examples/simple.calc  # JIT

Requirements

Stable Rust (Calculator interpreter/VM, Firstlang)

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Nightly Rust + LLVM (Calculator JIT, Secondlang, Thirdlang)

# 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 Versioninkwell feature
20.xllvm20-1
19.xllvm19-1
18.xllvm18-1

Running Tests

# All projects
cargo test -p calculator -p firstlang
rustup run nightly cargo test -p secondlang -p thirdlang

Building the Book

cd 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:

Child Foundation • Black Lives Matter • Food Bank of Canada

book
compiler
compiler-design
language-design
programming-language
rust-lang
teaching-materials

ehsanmok/create-your-own-lang-with-rust

Create your own programming language with Rust

Rust

957

65 commits

updated Oct 3, 2026

See the code

See what people are saying

README

CreateLang.rs Logo

Create Your Own Programming Language with Rust

Learn compiler fundamentals by building four languages from scratch

Overview • Languages • Quick Start • Requirements • Book

CI GitHub Pages Read the Book License


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.


Overview

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

Languages

The book teaches programming language implementation through four progressively complex languages:

LanguageType SystemExecutionFeaturesRust Version
CalculatorNoneInterpreter/VM/JITArithmetic expressionsstable / nightly
FirstlangDynamicInterpreterVariables, functions, recursionstable 1.70+
SecondlangStaticLLVM JITType inference, compilationnightly + LLVM
ThirdlangStaticLLVM JITClasses, methods, OOPnightly + 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.

Quick Start

Firstlang (stable Rust)

cd firstlang
cargo run -- examples/fibonacci.fl    # Run a program
cargo run                              # Start REPL

Secondlang (nightly + LLVM)

cd secondlang
rustup run nightly cargo run -- examples/fibonacci.sl
rustup run nightly cargo run -- --ir examples/fibonacci.sl   # View LLVM IR

Thirdlang (nightly + LLVM)

cd thirdlang
rustup run nightly cargo run --bin thirdlang -- examples/point.tl
rustup run nightly cargo run --bin thirdlang -- examples/counter.tl

Calculator

cd calculator
cargo run --bin main examples/simple.calc                                            # Interpreter
cargo run --bin main --no-default-features --features vm examples/simple.calc        # VM
rustup run nightly cargo run --bin main --no-default-features --features jit examples/simple.calc  # JIT

Requirements

Stable Rust (Calculator interpreter/VM, Firstlang)

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Nightly Rust + LLVM (Calculator JIT, Secondlang, Thirdlang)

# 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 Versioninkwell feature
20.xllvm20-1
19.xllvm19-1
18.xllvm18-1

Running Tests

# All projects
cargo test -p calculator -p firstlang
rustup run nightly cargo test -p secondlang -p thirdlang

Building the Book

cd 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:

Child Foundation • Black Lives Matter • Food Bank of Canada

book
compiler
compiler-design
language-design
programming-language
rust-lang
teaching-materials

Significant stargazers

(top 24 of 25)

jakevin

3,131 followers · starred Sep 2021

Erik Schierboom

602 followers · starred Jan 2026

Spenser Black

160 followers · starred Jun 2024

glepnir

1,746 followers · starred Jun 2024