Compilers and Interpreters: Assignment 4
November 28, 2010
In this assignment, you will build a compiler for the Mini-Triangle language
through the use of ANTLR. The language is as described in our textbook except for the following:
- Operators in expressions have different precedence. Also, there is a unary minus operator.
The syntax is already implemented in the files given to you.
- A program can contain a sequence of commands instead of a single command. This is also the way we've done it in the provided files.
You may obtain up to 10 points of extra credit by implementing extra features that
are not required in this assignment. Examples of what you could be doing:
- Meaningful error reporting and recovery
- Implement "new" and "dispose". This will require a grammar change, as these predefined procedures accept
two arguments and our grammar only allows one argument.
- Procedure and function declarations. This could be global with no parameters,
or could have nested declarations, have one parameter, or an arbitrary number.
- One dimensional arrays
- A new type (set, enum, one you invent)
A summary of what's already done in the version you receive:
- Syntactical analysis (MiniTriangle.g).
- Contextual analysis (Context.g and CodeGen.g) for variables and constants. The file Context.g was used for testing, but is not needed
in the final version, since all contextual analysis is redone in the code generation phase.
- A reasonable environment for code generation and a minimal amount of actual code generation (CodeGen.g).
- A java program that performs partial compilation (Main.java).
- A make file containing the sequence of commands to compile all the parts of the compiler and run the compiler
on a test program.
Some of the things you need to be doing:
- Setting up the standard environment by populating level 0 of the identification table. This should include
"true", "false", and the predefined procedures and functions that we can call from mini-Triangle. Currently, the identification
table only accepts variables and constants. You will need to generalize this.
- The constant declaration part is still incomplete: it does not emit a push command. You will also have to
decide what to do if the value of the constant is known at compile time.
- Fix the call to "eq" and to "ne" (the predefined functions require 3 arguments instead of 2).
- Generate code for all the commands, following code templates.
I have included a variable "currentFrameLevel" that keeps track of the procedure and function nesting.
Since Mini-Triangle does not allow declaring new procedures, this variable is always zero.
The variable "currentLevel" keeps track of the levels in the block structure of the programs, which is different.
Some of the included code is taken from the Triangle compiler available with
our textbook. If you include additional code from there, please attribute the sections to the proper source.
The code I included is not fully tested, so you may have to modify some it if you find something that does not
Due Saturday, December 11, midnight. In order to have enough time to grade,
late submission may or may not be considered.
If you plan a late submission, submit your partial work before the deadline.
To submit, E-mail (with CS 4352 Assignment 4 on the subject line)
to the instructor (longpre @ utep.edu):
- a compressed file with the directory containing all appropriate files
- a README file within this directory with:
- a summary of the work you've done
- anything that you have not implemented correctly yet, with an explanation
of what would need to be done.
- directions to compile and run your compiler (especially if different from
the provide make.bat file)
- a description of what you've done to deserve extra credit (if any)
- some Mini-Triangle programs you used to test your compiler