This is an undergraduate course in Computer Science.
Learn hands-on how to construct a self-compiling compiler in a non-trivial subset of C along with a DLX-based emulator as target and a linker for separate compilation, using nothing but a C compiler for bootstrapping. The course provides an undergraduate-level introduction to compiler construction, covering fundamental topics of compiler construction: scanning, parsing, type checking, error handling, register allocation, code generation, bootstrapping, separate compilation, and basic code optimization; considering fundamental programming language constructs and concepts: assignment, arithmetic and boolean expressions, arrays, records, pointers, conditionals, loops, modules, and procedures with parameters, return values, and local variables. At the end of the course you will be able to appreciate principled engineering of compilers but also know how to actually construct one from scratch and, as a consequence, through insights in programming language semantics that only a compiler can offer, become a fundamentally better programmer and computer scientist.
The course closely follows the textbook Compiler Construction by Niklaus Wirth but presents code examples written in a subset of C rather than Oberon.
4. Error Handling
6. Target Machine
7. Arithmetic Expressions
8. Arrays and Records
9. Conditionals and Loops
10. Boolean Expressions
12. Separate Compilation
13. Advanced Topics
Lecture notes and code examples: