Typing rules are given in the accompanying PDF description.
It is important to read and understand the abstract syntax of mini-C, that is Pfile (parsed trees) and File (typed trees).
Once uncompressed (for instance with tar zxvf mini-c-java.tar.gz), you get a directory mini-c/. The library java-cup-11a-runtime.jar, provided in sub-directory lib/, must be added to the project (but recent versions of Eclipse and VSCode will do that automatically).
The provided code should compile out of the box. The main method is in file Main.java. It expects a file with extension .c on the command line, possibly with options --debug, --parse-only, and --type-only. If no file is given on the command line, the file test.c (included in the tarball) is used, to ease the tests.
If a lexical or syntax error is detected, it is reported and the program exits with code 1.
If the parsing is successful and option --parse-only is on the command line, then the program exits with code 0.
If a type error is detected, it is signaled using exception Error , with a suitable message string. This exception is caught in Main.java and displayed as
error: ... your message here ...and the program exits with code 1.
int main() { return 0; }
This means you only have to consider integer literals in expressions
and return statements.
syntax/bad/ rejected at parsing syntax/good/ accepted at parsing typing/bad/ rejected at type checking typing/good/ accepted at type checking
> make typing-tests javac -cp lib/java-cup-11a-runtime.jar -d bin src/mini_c/*.java cd ./tests ; \ ./test -2 ../mini-c Testing of ../mini-c 11 states, 374 transitions, table size 1562 bytes 1401 additional bytes used for bindings Part 2: Type-checking bad ................................. good ...... Typing : 39/39 : 100%