Welcome to an engaging journey into the world of compilers and interpreters! This course is designed to be a beginner-friendly introduction to compilers, where you will gradually learn to develop an interpreter for a simple scripting language.
Course Overview
Throughout this course, you will explore the following topics:
- Lexical analysis: Understanding the process of tokenizing source code.
- Syntax analysis: Delving into the structure of the language.
- Parsing algorithms: Implementing strategies to parse code effectively.
- Intermediate Representation (AST): Building Abstract Syntax Trees.
- Formal languages and grammars: Learning foundational theories.
- Backus-Naur Form (BNF) and syntax diagrams: Notating grammars concisely.
- Error detection and handling: Managing and correcting syntax errors.
- Code generation: Transforming high-level code into machine-executable form.
- Creating your own virtual machine (VM): Designing an environment for running bytecode.
- Bytecode generation: Producing efficient intermediate code.
- Type checking: Ensuring type accuracy in programs.
- LLVM IR: Understanding the Low-Level Virtual Machine Intermediate Representation.
- Basic code optimization: Improving code performance.
- ...and much more!
The Myth of Compilers
Compilers have long been perceived as a complex topic, often symbolized by "dragons," a notion perpetuated by the famous Dragon Book. Contrary to the myth, this course aims to demystify compilers, with a teaching approach tailored for beginners. Think of it as your first step into the world of compilers for those who have yet to write their own interpreters.
What We Will Create
Project Focus: Over the span of this course, you will develop a compiler for a simple programming language called Pinky. Named after its playful inspiration from Lua and ALGOL W, Pinky will serve as a perfect foundation for understanding key compiler concepts.
The course primarily utilizes Python, promoting a focus on compiler-specific principles while enhancing productivity. We also provide valuable insights into implementing these concepts in C for those interested.
Required Tools and Prerequisites
To get started, ensure you have the following:
- A command line interface
- A simple text editor
- A Python interpreter
These tools are cross-platform, so whether you are on Windows, macOS, or Linux, you can seamlessly follow along. While this course does not require any pre-existing knowledge, familiarity with basic programming concepts such as if-else statements, loops, and functions will greatly aid your understanding.