Institutt for Informatikk
Universitetet i Bergen
INF 225 - Introduction to program translation - H09
The compulsory exercises in INF225 form a large project with a complete
compiler for C- as the final goal. Each individual exercise is one
step towards the final goal.
Part 1 is to be solved and handed in individually.
Part 2 and 3 are highly recommended to be done by groups of two students
A scanner should be implemented using Jlex. Deadline September 15th 12:00.
A recursive-descent parser should be implemented in Java using an abstract syntax tree.
Deadline October 20th 12:00.
A code generator for BVM should be implemented.
Deadline November 23th 12:00.
You are going to write a compiler for C- which is described in the
text book, with a few changes:
- Nested comments should be allowed.
- Identifiers can contain numbers, but must contain at least one letter.
- A comment works as a white space. The line "void/*...*/main(void)" is thus allowed.
We also make a couple of specifications:
- Local variables shadowing formal parameters are allowed, i.e.
you may declare a function with a formal parameter and a local
variable of the same name, with the result that the formal parameter
is of no use whatsoever. In such a case, a warning should be issued.
- Void variables, void arrays, and void parameters are not allowed.
(A void parameter list is of course allowed.)
- Identifiers may not be overloaded within the same scope, i.e.,
the same identifier cannot be used both for a function and for a global
variable. (You may of course declare local variables with the same
identifier as a variable or function in an outer scope.)
JLex is a tool for generating lexical parsers or scanners. JLex
reads source files in its own format and outputs java code which
may be used in larger programs like your compiler.
We will use a free software version that you can get here JFlex
Jar (java archive)
is a program to pack a bunch of class files into a single file.
To make a jar file of all classes in the current directory you can run
jar cf scanner.jar *.class
and to run the Scanner class from this file, you type
java -cp scanner.jar Scanner
Jar can do several other things as well, see the man page jar(1).