Institutt for Informatikk
Universitetet i Bergen
INF 225 - Introduction to program translation - H05

Project Part 3 - Code Generation

This part is highly recommended to be solved in groups of two, but each student is to hand in his/hers own program!


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 your own scanner and parser from previous exercises.


Deadline for hand-in is no later than Monday 28th November 2005 at 12:00 am.

Contents of hand-in

The answers handed in must include:

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

The program

The program is to read source code for a C- program, and write a program file for BVM to stdout. If errors occur 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 file using the implemented features.

Suggested command line syntax


  Java -cp mycompiler.jar Compile inputfile.c-
  Java -cp mycompiler.jar Parse inputfile.c-
  Java -cp mycompiler.jar Scan inputfile.c-

The Batu Virtual Machine (BVM)

Error messages




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



More hints