ASSIGNMENT #10
Due Friday, December 12, 2003, 5:00 P. M.
1
Design and implement an interpreter for MicroC# programs.
The interpreter should traverse the syntax tree and execute the statements of
the program.
Your implementation
should exactly follow the
denotational semantics of MicroC#.
The interpreter will consist of the following components:
- 1.
Construct a set of interpretation routines for each general root symbol in
the syntax trees. For example, you need a routine to interpret the
if statement, one for arithmetic operators, etc. Each
interpretation routine will perform the actions specified in the semantics.
For example, an if statement will evaluate the condition
and then either the then or else part depending on
whether the condition
is true.
- 2.
Some run-time type checking will be required, for example to distinguish list
types from integers and to check the number of parameters being passed in
functions. All such type checking is fully specified in the
semantics. In the case
of any errors, your interpreter need only print an appropriate error message
and halt.
- 3.
In the course of executing a program, output is printed by that program.
You may output this directly as it is generated.
- 4.
In summary, your output should consist of the source program, local symbol
tables and syntax trees for each function (printed with that function would
be acceptable), and final output of the program being interpreted.
If you implement your interpreter
correctly, you should get the same output as the executable code produced by
the C# compiler (csc)
gives
for the test programs (although the C# compiler will compile programs
which your interpreter will not).
Suggestion:
Develop this incrementally over the following steps.
-
Make your interpreter work first for expressions without statements or
function calls.
-
Next handle statements.
-
Then handle expressions calling functions without parameters,
including recursion.
-
Lastly implement the function calls which involve parameter passing.