Course description

This course is designed to be a beginner-friendly introduction to compilers. As we evolve, we will incrementally put together an interpreter for a very simple scripting language.

We'll cover:

  • Lexical analysis
  • Syntax analysis
  • Parsing algorithms
  • Intermediate representation (AST)
  • Formal languages & grammars
  • BNF notation & syntax diagrams
  • Identifying and reporting errors
  • Code generation
  • Writing our own VM
  • Emitting opcodes and instructions
  • Type checking
  • LLVM IR
  • Simple code optimization
  • ...and much, much more!

Compilers always had a reputation for being a difficult topic, and their historical association with dragons 🐉 (starting with the Dragon Book) never really help the cause.

make your own programming language

We'll try to approach every explanations with beginners in mind. You can think of it as a "first course" on compilers for developers that never wrote an interpreter before.

What we'll build

We'll build together, from the ground up, a compiler for a simple programming language called Pinky. Think of a toy scripting language with a syntax inspired by Lua and ALGOL W.

x := 0
pi := 3.141592
name := 'Pinky'

-------------------------------------
-- Find the max between two numbers
-------------------------------------
func max(a, b)
  if a > b then
    ret a
  end
  ret b
end

-------------------------------------
-- Compute the factorial of a number
-------------------------------------
func factorial(n)
  if n == 1 then
    ret 1
  else
    ret n * factorial(n - 1)
  end
end

-------------------------------------
-- Main function
-------------------------------------
func main()
  i := 0
  while i <= 10 do
    print(i)  
    i := i + 1
  end
  for i := 1, 10 do
    print(factorial(i))
  end
end

main()

Our main host language will be Python. Python allows us to focus our attention on compiler-specific concepts while being extremely productive. Still, I'll try to include some helpful tips on how to implement the ideas we just learned using the C programming language.

The tools you'll need

All you need is a command-line, a simple code editor, and a Python interpreter. All these tools are cross-platform, so you'll be able to code along on either Windows, macOS, or Linux!

operating system

Is this course for you?

If you never wrote an interpreter before, or even if you did but still feel you have some blind spots in your understanding of how it all works, then this course is definitely for you!

build your own compilers

This is a self-contained course with no prerequisites. However, you will probably get the most out of it if you already know the basics of coding (if-else, loops, functions).

About the instructor

gustavo pezzi

Gustavo Pezzi is a university lecturer in London, UK. He has won multiple education awards as a teacher and is also the founder of pikuma.com.

Gustavo teaches fundamentals of computer science and mathematics; his academic path includes institutions such as Pittsburg State University, City University of London, and University of Oxford.

teaching certification
higher education academy
pgclt teaching certification
bpp university award

Course content

18 hours total length 21 Chapters Last updated November 2024
  • Motivations & Learning Outcomes
  • How to Take This Course
  • Compilers as Translators
  • A Trip to the Metal
  • CPU Components
  • Opcodes & Instructions
  • Stack Push & Pop
  • Control Flow
  • CPU Status Flags
  • Quiz: CPU Components
  • The 68000 Processor
  • What is a Program?
  • Tokens & Lexemes
  • IR & Syntax Tree
  • Types of Compilers
  • Quiz: Structure of Programs
  • Setting Up our Project Folder
  • Makefile
  • Scanning Tokens
  • A Simple Scanning Algorithm
  • Single-Character Tokens
  • Whitespace & Comments
  • Two-Character Tokens
  • Scanning Integers
  • Scanning Floats
  • Why Not Just Use Regular Expressions?
  • Scanning String Literals & Identifiers
  • Programming Languages & Code Comments
  • Multiline Comments
  • Watching our Memory Footprint
  • Quiz: Lexing
  • Syntax Analysis
  • Context-Free Grammars & BNF
  • Grammar for Simple Expressions
  • Abstract Syntax Tree Nodes
  • Recursive Descent Parsing
  • AST for Simple Expressions
  • "Pretty" AST Printing
  • Polish Notation
  • Quiz: Grammars
  • Error Messages
  • Storing Line Numbers
  • Standardizing Error Messages
  • Quiz: Reporting Errors
  • A Simple Tree-Walking Interpreter
  • Data Types
  • Dynamic Types at Runtime
  • Runtime Type Checks
  • Concating Strings
  • Can We Subtract Strings
  • Parsing Equality & Comparison
  • Exponent Operator Associativity
  • Logical AND and Logical OR
  • Short-Circuit Evaluation
  • TDD & Testing Expression Code
  • A Program as a List of Statements
  • Parsing Print Statements
  • Interpreting Print Statements
  • PrintLn Statements
  • If Statements
  • Quiz: Parsing Statements
  • Identifiers & Assignments
  • State & Memory
  • The Environment Class
  • Declaring Variables?
  • Environment Load & Store
  • Global & Local Variables
  • Quiz: Variables
  • While Statements
  • For Statements
  • Stringifying Booleans & Integers
  • Coding a Fractal (Exercise)
  • Coding a Fractal
  • Functions in Pinky
  • Parsing Function Declarations
  • Parsing Function Calls
  • Interpreting Function Declarations
  • Interpreting Function Calls
  • Max. Number of Parameters
  • Parsing Return Statements
  • Interpreting Return Statements
  • Quiz: Functions
  • Code Generation & VMs
  • Example of Stack Instructions
  • Adding classes for "Compiler" and "VM"
  • Emitting Instructions
  • Printing Opcodes & Mnemonics
  • Where are Instructions Stored?
  • VM Execution
  • VM Expression Evaluation
  • Type Checking at Runtime
  • VM Branches & Jumps
  • Global Variables
  • Keeping Track of Scope Depth at Compile-time
  • Local Variables
  • Stack Slots
  • Exporting Program Symbols
  • Register-Based VMs
  • Register-Based Bytecode
  • Looking at CPython Bytecode Disassembly
  • [ pending peer review ]
  • [ pending peer review ]
  • [ pending peer review ]
  • [ pending peer review ]
  • [ pending peer review ]
  • [ pending peer review ]

How is this course different?

This course is not just a simple tutorial on how to use third-party tools to parse an existing language. We'll build an interpreter for a toy programming language from scratch while exploring the foundations of formal languages & compilers.

abstract syntax tree ast

We will always try to put things into historical context so you understand why modern compilers work the way they do.

If you want to understand how computers translate high-level languages to instructions that the machine can execute, then buckle up! This is going to be a super cool journey of pure nerd fun!

73% of our students come back for another course

We don't offer discounts on our courses. Ever.

What students are saying

5.00
5 star
100.0%
4 star
0.0%
3 star
0.0%
2 star
0.0%
1 star
0.0%
"I always waanted to take some contact with this subject, so I am glad to finally find it."
12 Nov 2024
Dominik Rudnik
"I was familiar with this information, so I just skipped the parts that I know. I learned it during creating a VM, simple assembler and game on it for CHIP-8. Nevertheless the parts that I saw was very well explained as always in your courses ^^"
11 Nov 2024
Ednildo Silva
Ednildo Silva
"I love it! I have been searching for an introduction to compilers and interpreters, and I haven't found any college-level teaching like this one."
10 Nov 2024

Other similar courses

C++ 2D Game Engine Development

30 hours
  • Learn to make a simple 2D game engine using modern C++, SDL, ECS, and Lua.
raycasting texture c

Raycasting Engine Programming with C

18 hours
  • Write a raycasting engine with textures and sprites using the C programming language.

Game Physics Engine Programming

35 hours
  • Learn how to create a 2D rigid-body game physics engine from scratch with C++.