Computer Science 5641
Compiler Design
Project Part 5 - An Interpreter (60 points)
Due Friday, December 17, 2004, 4pm, NO LATE PROGRAMS!!
Introduction
As the last part of your project you will build an interpreter for
the code produced from project part 4.
The interpreter should be called only if no errors are detected in previous
steps.
Execution Rules
Execution should follow the following rules:
- Program execution should start be declaring all global variables and
then calculating any expression values for those variables.
- All variables should be initialized to 0 if no initialization expression
is supplied.
- After all variables are initialized the function main should be called.
- After main is finished the return value of the function main should be
reported.
- Errors should be detected in the following cases:
- Division by zero is attempted.
- A function call in an expression has no return value.
- The return value (if any) of a function call in a statement is ignored.
- +, -, *, and / operations work as in C++.
- The comparsion operators (==, !=, <, >, <=, >=) produce
an integer value of 1 of the condition is true and 0 if false.
- The && and || are short circuit and and or operators. Short circuit
means that the second operator is checked only if needed.
- The ! operator performs a not on integer values (if the value is
non-zero the result is 0 and if the value is zero the result is 1).
- Assignment statements are executed by determining the value of the
right-hand side expression and then storing it in the variable on the
left-hand side.
- A << prints out an string representation of the value of the expression.
- A >> statement applied to a variable attempts to read in a variable
of the appropriate type.
- An if statement determines the integer value of the condition, if it
is non-zero the statement following the condition is executed, if zero
the statement following the else (if any) is executed.
- A while statement is a loop where the condition value is determined,
and if the value is non-zero the statement is executed and then this
process is repeated.
What To Turn In
Turn in documented versions of all of your code (including test code).
Also document your test cases and show results from your code on each
test file.
You will likely need to construct many test files in order to fully
exercise your code.
You should also write a team report on this part of the project and in
addition submit a short individual report from each member of the team.