Labs 02

This assignment is the first part of the MiniJava+ compiler project. Make sure you read the general project overview page first. Please also send Philippe an email as soon as possible stating who are the (two) members of your group.

Test case corpus (due in one week)

Write two small MiniJava+ programs per person (four per group) to constitute a corpus of test cases that we will use throughout the compiler project. We will check that all benchmarks are correct MiniJava+ programs and distribute the test suite. The programs don't have to be particularly complex, but it is in your own interest to write interesting ones, as you will use them to test your implementation of the various steps of the project.

Your programs should be written in a single .java file each. Please make sure that you can compile and run them using with javac and java (although this won't guarantee you that your code was written using the MiniJava+ subset of Java only).

(edit: note that this is a required deliverable, but it will not be graded)


Write the lexer for MiniJava+. We provide you with a test program to check your implementation. Here are some details you should pay attention to:

  • Make sure you recognize keywords as their own token type. while, for instance, should be lexed as the token type WHILE, not as an identifier representing an object called “while”.
  • Make sure you correctly register the position of all tokens.
  • In general, it is good to output as many errors as possible (this helps whoever uses your compiler). For instance, if your lexer encounters an invalid character, it can output an error message, skip it, and keep on lexing the rest of the input. It shouldn't then go on about parsing the tokens, but this will potentially allow it to catch more errors later on. Use the special BAD token type to mark errors and keep lexing as long as possible.
  • It is up to you to decide how you want to treat the special case of System.out.println calls. We suggest you don't try to treat the whole qualified name as a single token, but that you rather leave it to a later stage to recognize the sequence of 5 tokens as having a special meaning (as we believe this is easier). You're free to lex them as a single token if you wish, though.


Here are some classes and stubs. Mind the package names when you insert them into your project.


Hand in your modified Lexer.scala and Tokens.scala compressed in a zip file through Moodle by Wednesday, October 8th, 8:15am.