Why study compilers? This question is worth asking, since compilers are non-trivial contraptions
and most of us probably won’t work directly on one of them during our careers.
While curiosity is always a good reason, there are practical reasons too:
Compilers are a collection of interesting and generalizable algorithms and programming patterns
that fit together nicely. This makes building a compiler
an excellent and fun software engineering exercise.
Understanding compilers gives you deep insight into why programming languages work the way they do,
and it’s good to know your daily tools well.
Understanding the problems and design choices faced by programming languages helps you
understand programming more deeply.
While creating an entirely new language and the associated tooling is usually not worth the effort,
sometimes it’s useful to write code analyses or extensions for existing languages. Knowing compilers helps you
do that effectively.
Course philosophy
This course aims to be straightforward, practical and hands-on.
It typically presents one good way of accomplishing a task,
and then asks you to try it in practice.
This means that, due to limited time, some theoretical breadth and depth has been sacrificed.
If you’re looking for more, there are many great books on compilers.
The text has some green links.
These reveal optional, non-essential content that
expands upon or contextualizes things.
Project setup
While you can complete the course project in any language you like,
our examples and instructions are for Python.
‼️ Test Gadget, the project’s automated testing and grading system,
will be made available on the last week of January.
To submit your completed project, run ./test-gadget.py submit.
Click here for details about this.
Test Gadget does not replace your own testing.
Test Gadget runs end-to-end tests, which start to pass only after you’ve completed
most of the project. Local unit testing along the way is highly recommended.
Additional instructions for MacOS and Windows
You can get pretty far with just MacOS or Windows, but near the end of the project you need to generate
machine code for x86-64 Linux and test it. While in principle you could test only with Test Gadget,
that would be very slow and extremely inflexible.
There are several ways to use an x86-64 Linux environment while developing on MacOS or Windows.
Here are instructions for a few of them.
Alternative project setup
If you want to write your compiler in a language other than Python,
you are very welcome to do so, but you need to replicate parts of the Python project template yourself.
If this interests you, look at these instructions.