KOI: Lab Exercise 6
This exercise is about a (comparatively)
simple way to build an interpreter,
by executing the syntax trees.
Executing syntax trees
Write an interpreter that executes the syntax trees from
One way is to write a recursive function,
called for example execute,
that takes a pointer to a tree node as argument.
This function should examine the type field
in the node, and, depending on the type of node,
perform the proper action.
For example, if the type of node is '+',
your function should first evaluate (that is, "calculate the value of")
by calling itself recursively with the two sub-trees of the nodes
Then it should perform the addition,
and finally return the result.
Control structures, such as the if statement,
can be handled in a similar way,
except that sometimes some arguments should not
Show your results and discuss them with the teacher,
The e-mail should contain clear and full explanations of what you have done.
Include well-chosen and commented test runs with input and output.
Send your e-mail in plain text format,
not as HTML or Word documents
or with unnecessary attachments.
Include relevant source code, with any changes clearly marked.
Except for this report, you should also send all
the source code that is required to compile the program,
as a Zip file or equivalent.
January 12, 2004