-
20:00
In this session, we'll go over the construction of a compiler frontend for small programming languages and try to build one for your choice of language. We'll have a set of tiny languages, e.g. arithmetic, boolean expressions, pipes etc. and you'll get to choose one of your liking. Then we'll go over the various parts of a compiler frontend, starting from lexical analysis and ending with intermediate code generation.
Schedule:
Introduction to compilers We'll talk about how a compiler is structured and then will focus on the frontend part. This will be a very brief introduction. We'll also talk about language grammars and a common way to write them - the Backus-Naur Form (BNF).
Choosing a language to implement Next, we'll choose a language from a set available for everyone, or if you are feeling adventurous, you can choose your own! We'll discuss the basic form and semantics of the language and will write the BNF for the language. We'll use ANTLR, an open-source parser generator tool to automatically generate lexers and parsers for our languages.
Implement semantic analysis Once we have our parsers, we'll do some analysis of example programs. We'll throw check some types, some obvious mistakes like divide-by-zero and throw some errors.
Interpreting/Code generation As the last and the crucial step, we'll choose one of the following paths:
- Write an interpreter that runs the program
- Generate LLVM intermediate representation of the program Both the paths eventually will make it possible to run programs in your chosen mini language.
In the end, you'll have a working compiler (or interpreter!) which you can extend as you wish. Come, hack on mini compilers!
What you will need:
- Laptop
- ANTLR installed (we'll go through the installation once)
- Your programming language of choice to implement the compiler (from the list of available targets listed here: https://www.antlr.org/download.html)