Skip to main content

Write a Compiler

35h 41m
English
Paid

Unlock the Complexity of Software Development by Writing a Compiler. The course on compiler development is traditionally considered a capstone discipline for computer science students—and it's no accident. Compilers are tools that programmers encounter almost daily, regardless of the subject area. Implementing their own compiler touches upon nearly all aspects of computer science: from theoretical foundations to applied techniques. A deep understanding of how a compiler works makes a developer a more mature and conscious engineer.

Why Study Compiler Development?

At the same time, it may seem that writing a compiler is scarcely related to typical tasks in the industry. To some extent, this is true. However, developing a compiler is, above all, an exercise in managing software complexity. Compilers have numerous components, they are difficult to test and debug, and this is what makes them an ideal environment for studying the problems faced by large real-world projects.

From experience: one of the course graduates once recounted how he helped prevent a serious error in a medical insurance system. When asked, "How did you manage to do that?" he replied, "I used what I learned when writing a compiler."

Course Details

Target Audience

The course is aimed at experienced programmers interested in software architecture, data processing, standard systems, and the structure of programming languages. Very few developers get the chance to write their own compiler unless they study this subject at a university or graduate school. Therefore, the course helps fill in the gaps. If you have experience studying compilers, the course will allow you to take a more practical look at the topic.

Learning Format

The course is entirely project-based and is conducted in a live coding format, without slides. The goal is not only to learn how to write a compiler but also to understand how to approach this task "from scratch." During the sessions, participants discuss task decomposition, techniques, architectural solutions, testing, and other engineering aspects. The remaining time is dedicated to individual development.

Code examples are provided in Python; however, the project does not require external libraries or specific tools. Participants can use any programming language. For those wishing to challenge themselves, writing a compiler will be a good way to learn a new language.

Participant Requirements

To complete the course, experience in programming and basic knowledge of data structures is sufficient. Special preparation in the field of compilers is not required, but an understanding of key concepts of programming languages (types, functions, scopes, etc.) is highly desirable. It is also recommended to have a general understanding of text processing and computer architecture. Robert Nystrom's book "Crafting Interpreters" can serve as helpful background material.

Course Content

During the course, participants create a compiler for a small statically typed imperative language called Wabbit, generating native code through LLVM. The project includes the following key stages:

  • Data Model: Representing the program as a proper data structure, rather than text. This forms the basis for an abstract syntax tree (AST).
  • Parsing: Building a tokenizer and writing recursive descent for converting program text into an AST.
  • Program Transformation: Implementing transformations that reduce complex language constructs to simpler ones and understanding basic optimization techniques.
  • Type Checking: Creating a static analyzer that detects type and semantic errors. If time permits, advanced topics such as algebraic types are considered.
  • Code Generation: Outputting LLVM IR and/or WebAssembly to produce executable programs. Alternative code generation targets are discussed: bytecode, virtual machines.

The main goal of the course is to form an intuition about compiler structure and demonstrate how all components work together. Participants create a compiler entirely from scratch, without using ready-made frameworks.

Practical Outcomes

Although compilers are rarely written in everyday work, the skills gained in this course are useful in a variety of fields:

  • Working with text and parsing for data analysis, protocols, automation.
  • Manipulating complex data structures: trees, graphs, recursive algorithms.
  • Testing complex systems: unit tests, integration tests, test oracles, contracts.
  • Practicing object-oriented design techniques.
  • Mastering functional approaches: recursion, pattern matching, combinators.
  • A deep understanding of programming language semantics, including the type system, memory model, computation rules, call stack structure.
  • General expansion of horizons in computer science.

Is it possible to write a compiler in 5 days? Yes, if you focus on practical programming. Unlike a university course with formal grammar theory, proofs, and LALR algorithm analysis, this course is geared toward engineers and emphasizes real development and testing.

Over five intensive days, participants write 2000–3000 lines of code—a project comparable in complexity to academic courses. And, as in real life, the final version will likely contain errors—this is an important part of the educational process.

About the Author: David Beazley

David Beazley thumbnail

David Beazley is an independent author, educator, and researcher, widely known for his contributions to the Python community. Early in his career, he worked on high-performance scientific software, leading to the creation of SWIG—a compiler that enabled the integration of C/C++ code with Python and other dynamic languages. In 1999, he wrote Python Essential Reference, the first Python reference book.

From 1998 to 2005, David was an associate professor in the Department of Computer Science at the University of Chicago, where he taught courses on operating systems and networks. Since 2007, he has been developing his own educational project, Dabeaz LLC, humorously calling it a "one-man graduate school."

David is the author of the third edition of Python Cookbook (2013), the book Python Distilled (2021), as well as video courses and numerous well-known presentations ranging from live coding to experiments with WebAssembly. In 2023-2024, he taught a course on programming language design and implementation at Brown University, jointly with Shriram Krishnamurthi.

David holds a Ph.D. in computer science and master's and bachelor's degrees in mathematics.

Watch Online 10 lessons

This is a demo lesson (10:00 remaining)

You can watch up to 10 minutes for free. Subscribe to unlock all 10 lessons in this course and access 10,000+ hours of premium content across all courses.

View Pricing
0:00
/
#1: Day 1-1
All Course Lessons (10)
#Lesson TitleDurationAccess
1
Day 1-1 Demo
03:26:32
2
Day 1-2
03:30:12
3
Day 2-1
03:30:15
4
Day 2-2
03:28:02
5
Day 3-1
03:25:36
6
Day 3-2
03:28:39
7
Day 4-1
03:27:33
8
Day 4-2
03:26:37
9
Day 5-1
04:27:57
10
Day 5-2
03:29:37
Unlock unlimited learning

Get instant access to all 9 lessons in this course, plus thousands of other premium courses. One subscription, unlimited knowledge.

Learn more about subscription