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
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
BADtoken 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.printlncalls. 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.
- Tokens.scala: stub for a file describing token types and tokens.
- Positional.scala: the positional trait
- Lexer.scala: stub for the
- Reporter.scala: the complete
Reportertrait. Feel free to improve it :)
- Compiler.scala: the main class for the compiler, that combines the other traits. Contains only a testing method for now.
- Main.scala: some code to help you test your lexer
- Factorial.java: an example MiniJava+ program.
Hand in your modified
Tokens.scala compressed in a
zip file through Moodle by Wednesday, October 8th, 8:15am.