Institutt for Informatikk
Universitetet i Bergen
INF 225 - Innføring i Programoversettelse - H04

Project Part 3: Code Generation

This part can be solved and handed in groups of two.


In this last exercise, you are going to write a compiler to produce executable code for the Batu Virtual Machine (BVM) Of course, you will have to employ the scanner and parser from previous exercises.


You have to hand in your answers no later than Monday 29th November 2004 at 12:00 am.

Contents of hand in

The answers handed in must include:

The answers are to be mailed to Magnus Hoff (, no later than the specified deadline. Answers handed in after deadline will NOT be considered.

The program

The program should read C- source code from stdin and write a program file for BVM to stdout. If error occurs during compilation, error messages must be written to stderr. Diagnostics may also be written to stderr.

If you cannot manage to complete the compiler, you may reduce the problem to avoid writing many similar blocks of code. Start to write small C- programs that only uses simple program constructions, and make sure that the compiler works for them. Still we do require you to include a variety of functionality, at least one aritmetical operation (e.g. +), one relation (e.g. <), if and while statements, assignment, and function calls with one parameter. All missing features and bugs must be documented. We do not accept undocumented flaws. Remember an example using but the implemented features.


In the exercise description of the last year and the description of the Batu instructions you find the necessary informations.

Error messages

You don't need to optimize your code. But, you are likely to find plenty of examples of your compilers doing really stupid things, so don't hesitate to optimise.