Lab Project of Compilers - FIB UPC, 2025

The lab project will consist of building a compiler for an simplified imperative language named ASL (standing for A Simple Language).

The project will consist of:

  • Writting a grammar for the language, and use ANTLR4 to generate a parser in C++

  • Writting a semantic check module (in C++) that performs semantic analysis (i.e. variable type checking) on the tree produced by the parser on a given input program.

  • Writting a code generation module (in C++) that generates low-level code for the input program. We will generate simple 3-address code that will run on a custom virtual machine called tVM (standing for t-code Virtual Machine).

In order to do the work, you will have some help:

  • You will be using ANTLR-4, a powerful tool that will make it much easier to build your compiler.

  • You will be provided with a basic working compiler (with just assignment instructions and sum operations) which you will need to complete until your ASL compiler is finished.

  • You will also be provided with some auxiliary modules to help manage the data structures required to build the compiler.

  • Finally, you will be provided with a list of ASL programs to incrementally test your compiler.

Warning

Auxiliary modules may change from one course to the next. If you are re-taking the course, your lab project may not work with this year modules. Exams will be compiled with current versions, so if you want to re-use code from last year, make sure you adapt it to be compatible with the latest versions of the auxiliary modules.

Here you will find further documentation about:

You can also download the required code (also available at /assig/$USER/cl/files/CL-lab.tgz in FIB labs):

Project Evaluation

Although the project is to be carried out in teams of two people, the evaluation will be individual.

The project will be evaluated in two exams (one mid-term, the other final). Each exam will consist of implemeting an extension to the language supported by compiler developed along the course.

Exams from previous years are available for practicing.