Docsity

CS405 Assignment 8: Developing a Matrix Interpreter, Assignments of Programming Languages

Toggle sidebar
bg1
CS405 Assignment 8
Due Dec 10, 2004 (hard deadline)
Design and implement an interpreter for the matrix programs. The interpreter should
traverse the syntax tree and execute the statements of the program. 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,
if statement -to evaluate the condition and then either to skip the if-part or
to interpret the if-part depending on whether the condition is true one for
arithmetic operators, etc.
arithmetic expression- to calculate based on matrix arithmetic# and return
the result.
call –to interpret the syntax tree associated with the procedure
assignment - update the value for the left-hand side valuable (after
evaluating the right-hand side) in the corresponding symbol table (local or
global, dependent on the scope of the left-hand side variable)
….
2. Type-checking-- Interpretation process is performed over the syntax tree directly, as
opposed to compilation process, where program execution is performed after executable
code is generated. Therefore, we need to integrate the type-checking process into the
interpretation process, to be specific--
for an assignment statement, the left-hand side type should be the same as the
type of the result returned in the right-hand side expression.#
for arithmetic operator, only int, vector, matrix type operand can be involved,
otherwise there should throw an error:
for +, -,* the associated data type should be the same, and the resultant expression
type is of the same type—there is one except with *, where integer could be
associated with vector (matrix) too , and the resultant type in this case is vector
(matrix). For vector or matrix type, type checking also involves to check the
consistency of dimension size as is noted in the bottom.
for relational expression, both operand should be int type.
…--think about any other type checking wherever you feel necessary.
In the case of any errors, your interpreter need only print an appropriate error message
and halt.
pf3

Partial preview of the text

Download CS405 Assignment 8: Developing a Matrix Interpreter and more Assignments Programming Languages in PDF only on Docsity!

CS405 Assignment 8 Due Dec 10, 2004 (hard deadline) Design and implement an interpreter for the matrix programs. The interpreter should traverse the syntax tree and execute the statements of the program. 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,  if statement -to evaluate the condition and then either to skip the if-part or to interpret the if-part depending on whether the condition is true one for arithmetic operators, etc.  arithmetic expression- to calculate based on matrix arithmetic#^ and return the result.  call –to interpret the syntax tree associated with the procedure  assignment - update the value for the left-hand side valuable (after evaluating the right-hand side) in the corresponding symbol table (local or global, dependent on the scope of the left-hand side variable)  ….
  2. Type-checking-- Interpretation process is performed over the syntax tree directly, as opposed to compilation process, where program execution is performed after executable code is generated. Therefore, we need to integrate the type-checking process into the interpretation process, to be specific--  for an assignment statement, the left-hand side type should be the same as the type of the result returned in the right-hand side expression.#  for arithmetic operator, only int, vector, matrix type operand can be involved, otherwise there should throw an error: for +, -,* the associated data type should be the same, and the resultant expression type is of the same type—there is one except with *, where integer could be associated with vector (matrix) too , and the resultant type in this case is vector (matrix). For vector or matrix type, type checking also involves to check the consistency of dimension size as is noted in the bottom.  for relational expression, both operand should be int type.  …--think about any other type checking wherever you feel necessary. In the case of any errors, your interpreter need only print an appropriate error message and halt.
  1. The final output of program interpretation process are the global variable and their value..
  2. In summary, your output should consist of the source program, the output as required in previous assignment (assign7) and the evaluated value for the global variables. 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.