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 closely follows the textbook Compiler Construction by Niklaus Wirth but presents lecture notes and code examples written in a subset of C rather than Oberon. Lecture videos are available in the iTunes Store and on iTunes U and Vimeo, code is hosted on GitHub and build on drone.io, discussions are held on Piazza. We thank GitHub and drone.io for their generous support!
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.
Teams of 2-3 students will be asked to design their own source language (with formal grammar), and implement their own compiler, linker, and target machine in programming languages of their choice. Each compiler must be able to compile itself in a live demo at the end of the semester. Therefore, source languages are constrained to subsets of programming languages for which executable compilers are available (unless students choose to apply manual bootstrapping techniques). Moreover, source languages must be typed (basic types, arrays, and records) and feature at least a concept for parameterized local hiding such as procedures with arguments and a concept for global hiding such as modules supporting separate compilation. There will also be a final exam at the end of the semester.