Institutt for Informatikk
Universitetet i Bergen
INF 225 - Innføring i Programoversettelse - H04
The compulsory exercises in I225 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 13th.
A recursive-descent parser should be implemented in Java using an abstract syntax tree.
Deadline October 18th.
- Code Generation.
A code generator for BVM should be implemented.
Deadline November 22nd.
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 gcc(1) would issue a
warning, but you don't have to check for this.
- 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.
(There is also FLex which generates C code from a format similar to
that of JLex or FLex++ which generates C++ code, respectively.)
More information about Jlex can be found in the Handouts folder on the course page.
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).