Hide menu

TDDB44 Compiler Construction

Laboratory Assignments

Laboratory Organization

The laboratory exercises are performed in groups of two students, 8 groups per laboratory. The lab material is quite extensive and will not be presented on these web pages. See the course literature section on the start page.

To be able to solve the laboratory assignments on time you must be well prepared for every laboratory exercise. Past experience has shown that the amount of work involved is often underestimated.

There are 7 separate parts of the compiler to complete in 11x2 hours in the computer laboratories.

The Laboratory Compendium

The TDDB44 Laboratory compendium is available at Bokakademin.

The aim of this laboratory assignment is to implement a compiler for a simple imperative language (DIESEL) in C++, using modern tools to help generate parts of the code. The work is estimated to take about 80 hours (based on statistics from 1998). The compiler is to be written in the following order and to comprise the following parts:

  1. Scanner - manages lexical analysis.
  2. Symtab - administrates the symbol table.
  3. Parser - manages syntactic analysis, builds internal form.
  4. Semantics - checks static sematics.
  5. Optimizer - optimizes the internal form.
  6. Quadruples - generates quadruples from the internal form.
  7. Codegen - expands quadruples to assembler.

The parser, semantic, quads and codegen parts are the ones likely to take the most time, so try to get the scanner and symbol table labs done the first week. Skeleton code will be provided for all the labs, and in most cases you will simply keep on adding code to what you wrote in the previous lab. The skeleton contains declarations of central data-structures and support routines; in other words, a lot of the boring work has already been done for you. The aim is to let you concentrate on the essential details.

xxgdb can be recommended for fault-finding; it is window-based and very useful. There are other debuggers available as well.

The compendium starts by describing DIESEL 4.0 in the way it would be presented to a fictitious user. Then an overview of the compiler follows which hopefully gives an idea of what the various phases do. After this come the various parts of the lab work, where each phase is described in a section of its own. These are usually introduced by some theory from the lectures, which it is generally a good idea to read up on before starting the lab work. When a phase has been completed and tested, report to the assistant and then continue with the next one.

In addition to the Laboratory Compendium you might need the GNU Flex and Bison guides as quick references (at least for the first 3 labs).

GNU Flex Guide [PS] [PDF] [HTML]
GNU Bison Guide [PS] [PDF] [HTML]


The deadline for the labs is the end of the lecture period 2017-12-20. Check when your lab assistant takes vacation in good time before the last scheduled lab in case you want to hand in the labs after that lab (2017-12-19).

While it will still be possible to submit your lab report to your lab assistant afterwards, we then cannot guarantee that your lab points will be counted as a 2017 result, as we have to prioritize the correction of the exam.

After correction of the exams, your lab assistant will be busy with other courses and work. If you have only 1 or 2 labs remaining, it might be possible to correct the labs; but if the lab assistant does not have time, you may need to wait until the next time the course is given.

Page responsible: Mahder Gebremedhin
Last updated: 2017-10-30