Leanpub Header

Skip to main content

Building Programming Languages with Rust

From Lexers to LLVM: A Complete Guide to Language Implementation

This book is 100% completeLast updated on 2026-07-14

Learn how to build a modern programming language from scratch in Rust. By implementing a complete language called Rune, you will explore every stage of language design, from lexing and parsing to type checking, virtual machines, LLVM code generation, and developer tooling, with practical code and clear explanations throughout.

Minimum price

$19.00

$29.00

You pay

Author earns

$

Also available for 1 book credit with a Reader Membership

PDF
EPUB
WEB
APP
278
Pages
About

About

About the Book

This book teaches you how to build a complete, production-quality programming language from scratch using Rust. Over twenty chapters, you will design and implement every component of a real language called Rune: the lexer, parser, type system, interpreter, bytecode virtual machine, native code generator, standard library, and full developer tooling chain including a REPL, formatter, linter, and language server. Every chapter includes complete, compilable Rust code with detailed explanations of design trade-offs, performance considerations, and common pitfalls. By the end, you will have built a feature-complete language and deep understanding of how programming languages work internally.

Bundle

Bundles that include this book

Author

About the Author

Steve Publications

Steve is a technology professional with more than 20 years of experience in software development, server infrastructure, cybersecurity, vulnerability research and reverse engineering. Throughout his career, he has designed, secured, analyzed and tested complex software and infrastructure, with a particular focus on understanding how systems fail and how they can be made more secure.

Outside of work, Steve enjoys sharing knowledge with the technology community. He collaborates with researchers, industry experts and technology professionals to write practical books covering software development, cybersecurity, cloud computing, networking, DevOps, artificial intelligence and enterprise technologies. His books focus on practical learning through clear explanations, real-world examples and hands-on exercises. With more than two decades of industry experience, his goal is to help IT professionals, students and technology enthusiasts build useful skills and stay current in a rapidly changing industry.

We believe readers deserve to know how our books are created. Most of our authors are not native English speakers, so we use AI to help translate, proofread manuscripts, fix grammar, improve sentence structure and make technical explanations easier to read. AI is used as an editing tool only. It does not replace the research, technical knowledge or hands-on experience behind our books. Some of our authors also prefer to remain anonymous for privacy or professional reasons. In those cases, we publish their work under a different name. The author's name may be different, but the quality of the content and our review process remain the same.

Every book is written, reviewed and maintained by experienced technology professionals, with contributions from our private technical community of more than 420 engineers and researchers from Ukraine, Belarus and Russia. We spend far more time validating technical accuracy and keeping our content up to date than generating text. We are always interested in working with experienced professionals who have deep expertise in a particular technology or domain. If you would like to publish a book with us or help review an existing manuscript, we'd love to hear from you. Send us a message describing your area of expertise. We are especially interested in niche technologies, specialized skills and emerging topics that are underrepresented in existing technical literature.

If you look through the contents of our books, you'll see practical examples, detailed explanations and material that is regularly updated. Our goal is to publish books that professionals can actually rely on, not low-effort AI-generated content. If you ever feel that one of our books does not meet that standard, Leanpub offers a 60-day money-back guarantee. Feel free to request a refund if you are not satisfied with your purchase.

Contents

Table of Contents

From Lexers to LLVM: A Complete Guide to Language Implementation

Introduction: The Language Builder’s Journey

  1. Why Build a Language?
  2. Why Rust?
  3. What Is Rune?
  4. How This Book Is Structured
  5. What You Need to Know
  6. How to Use the Code
  7. A Note on Scope
  8. The Journey Ahead

Chapter 1: Why Build a Language? The Landscape and the Vision

  1. What Is a Programming Language, Really?
  2. The Rust Advantage for Language Implementation
  3. Survey of Existing Languages Built in Rust
  4. Designing Rune: Goals and Non-Goals
  5. Project Structure and Tooling Setup
  6. Chapter Summary
  7. Exercises

Chapter 2: Language Design Fundamentals

  1. Syntax Philosophy: Minimalism Versus Expressiveness
  2. Core Semantic Model
  3. Type System Design Choices
  4. Memory and Ownership Semantics
  5. The Standard Library Blueprint
  6. Chapter Summary
  7. Exercises

Chapter 3: Formal Grammars and Lexical Analysis

  1. Regular Expressions and Token Definitions
  2. Building the Lexer: State Machine Approach
  3. Error Recovery in Lexing
  4. Unicode and Source Encoding
  5. Lexer Benchmarks and Optimization
  6. Chapter Summary
  7. Exercises

Chapter 4: Recursive Descent Parsing

  1. Context-Free Grammars and Parse Trees
  2. AST Node Design in Rust
  3. Writing the Parser
  4. Expression Parsing and Operator Precedence
  5. Error Reporting with Source Spans
  6. Chapter Summary
  7. Exercises

Chapter 5: Advanced Parsing – Pratt Parsers and Parser Generators

  1. The Pratt Parser Algorithm
  2. Integrating Pratt Parsing into Rune
  3. Parser Generators in Rust: LALRPOP Deep Dive
  4. Nom and Combinator-Based Parsing
  5. Choosing Your Parser Strategy
  6. Chapter Summary
  7. Exercises

Chapter 6: Abstract Syntax Trees and Tree Transformations

  1. Arena Allocation for AST Nodes
  2. Desugaring Passes
  3. Tree-Walking Patterns
  4. Source Maps and Debug Information
  5. AST Serialization and Caching
  6. Chapter Summary
  7. Exercises

Chapter 7: Semantic Analysis and Symbol Tables

  1. Scope Chains and Symbol Resolution
  2. Building the Symbol Table
  3. Name Mangling and Uniqueness
  4. Semantic Error Detection
  5. Cross-Module Name Resolution
  6. Chapter Summary
  7. Exercises

Chapter 8: Type Systems and Type Checking

  1. Type Representation in Rust
  2. The Type Checker Architecture
  3. Type Inference with Unification
  4. Generics and Monomorphization
  5. Trait Resolution and Dispatch
  6. Chapter Summary
  7. Exercises

Chapter 9: Error Reporting and Recovery

  1. The Anatomy of a Good Error Message
  2. Building the Diagnostics Engine
  3. Parse Recovery Strategies
  4. Type Error Messages That Help
  5. Error Collection and Summarization
  6. Chapter Summary
  7. Exercises

Chapter 10: The Interpreter

  1. Evaluation Semantics
  2. Environment and Closure Implementation
  3. Built-in Functions and Foreign Function Interface
  4. Garbage Collection for the Interpreter
  5. REPL Implementation
  6. Chapter Summary
  7. Exercises

Chapter 11: Bytecode Virtual Machine

  1. Instruction Set Architecture Design
  2. Rune’s Instruction Set
  3. Code Generation from AST to Bytecode
  4. The VM Execution Engine
  5. Performance: Bytecode vs Tree Walking
  6. Chapter Summary
  7. Exercises

Chapter 12: Native Code Generation with LLVM

  1. LLVM Architecture Overview
  2. Inkwell: The Rust LLVM Binding
  3. Codegen for Expressions and Statements
  4. Optimization Passes
  5. Linking and Runtime Support
  6. Chapter Summary
  7. Exercises

Chapter 13: Memory Management Strategies

  1. Manual Memory Management Model
  2. Tracing Garbage Collection in Rust
  3. Region-Based Memory Management
  4. Ownership and Borrowing for Scripting Languages
  5. Memory Profiling and Debugging
  6. Chapter Summary
  7. Exercises

Chapter 14: Optimization Techniques

  1. Peephole Optimizations
  2. Data Flow Analysis
  3. Loop Optimizations
  4. Inline Caching and Monomorphization
  5. Profiling-Guided Optimization
  6. Chapter Summary
  7. Exercises

Chapter 15: Concurrency Model

  1. Threads vs Green Threads vs Actors
  2. Rune’s Concurrency Primitives
  3. Implementing Async/Await
  4. Shared-State Concurrency
  5. Parallel Compilation
  6. Chapter Summary
  7. Exercises

Chapter 16: Modules, Packages, and the Standard Library

  1. Module System Design
  2. Package Manager Architecture
  3. Building the Standard Library
  4. Foreign Function Interface
  5. Documentation System
  6. Chapter Summary
  7. Exercises

Chapter 17: Macros and Metaprogramming

  1. Macro Design Philosophy
  2. Token-Based Macros
  3. Hygienic Macro Implementation
  4. Compile-Time Evaluation
  5. Macro Debugging and Error Reporting
  6. Chapter Summary
  7. Exercises

Chapter 18: Tooling – Formatter, Linter, and Language Server

  1. Automatic Code Formatting
  2. Static Analysis Linter
  3. Language Server Protocol Implementation
  4. Debugger Architecture
  5. IDE Integration
  6. Chapter Summary
  7. Exercises

Chapter 19: Testing, Benchmarking, and Quality Assurance

  1. Test Infrastructure
  2. Property-Based Testing for Compilers
  3. Fuzzing the Parser and VM
  4. Performance Benchmarking
  5. Continuous Integration Pipeline
  6. Chapter Summary
  7. Exercises

Chapter 20: Packaging, Distribution, and Maintenance

  1. Cross-Platform Compilation
  2. Installer and Package Distribution
  3. Documentation Strategy
  4. Semantic Versioning for Languages
  5. Community and Ecosystem Building
  6. Chapter Summary

Conclusion: The Language Builder’s Path Forward

References

Glossary

Appendix A: Complete Cargo Workspace Configuration

Appendix B: Rune Language Specification Summary

Appendix C: Building and Running Rune

Get the free sample chapters

Click the buttons to get the free sample in PDF or EPUB, or read the sample online here

The Leanpub 60 Day 100% Happiness Guarantee

Within 60 days of purchase you can get a 100% refund on any Leanpub purchase, in two clicks.

See full terms...

Earn $8 on a $10 Purchase, and $16 on a $20 Purchase

We pay 80% royalties on purchases of $7.99 or more, and 80% royalties minus a 50 cent flat fee on purchases between $0.99 and $7.98. You earn $8 on a $10 sale, and $16 on a $20 sale. So, if we sell 5000 non-refunded copies of your book for $20, you'll earn $80,000.

(Yes, some authors have already earned much more than that on Leanpub.)

In fact, authors have earned over $15 million writing, publishing and selling on Leanpub.

Learn more about writing on Leanpub

Free Updates. DRM Free.

If you buy a Leanpub book, you get free updates for as long as the author updates the book! Many authors use Leanpub to publish their books in-progress, while they are writing them. All readers get free updates, regardless of when they bought the book or how much they paid (including free).

Most Leanpub books are available in PDF (for computers) and EPUB (for phones, tablets and Kindle). The formats that a book includes are shown at the top right corner of this page.

Finally, Leanpub books don't have any DRM copy-protection nonsense, so you can easily read them on any supported device.

Learn more about Leanpub's ebook formats and where to read them

Write and Publish on Leanpub

You can use Leanpub to easily write, publish and sell in-progress and completed ebooks and online courses!

Leanpub is a powerful platform for serious authors, combining a simple, elegant writing and publishing workflow with a store focused on selling in-progress ebooks.

Leanpub is a magical typewriter for authors: just write in plain text, and to publish your ebook, just click a button. (Or, if you are producing your ebook your own way, you can even upload your own PDF and/or EPUB files and then publish with one click!) It really is that easy.

Learn more about writing on Leanpub