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
lab 5.
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")
the arguments,
by calling itself recursively with the two sub-trees of the nodes
as arguments.
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
be evaluated.
Report
There are two ways to pass this lab.
Ideally you should do this:
- Write down a short description of your results.
- Show your results and discuss them with the teacher.
You will get feedback directly, so you can fix any problems
with your solution.
- Then hand in a brief lab report in Blackboard,
including your source code and the collaboration and LLM statements
described below.
But as an alternative, you can instead do this.
- Don't show your results to the teacher.
- Hand in a more elaborate lab report in Blackboard,
including your source code and the collaboration and LLM statements
described below.
- Wait for feedback from the teacher.
- Repeat until your report passes.
About sources and collaboration:
-
Each group (which normally consists of one or two students)
must make its own solution to each assignment,
and submit or present it, but it is not forbidden to collaborate or ask other students for help.
However, in that case you must clearly state who you have collaborated with.
Each solution must include the name of everyone who contributed to the work,
Collaboration is thus perfectly fine, but must be clearly stated.
-
You must add an LLM statement to the lab report,
where you state if and how you have used large language models,
and some experiences from that.
Was the LLM helpful, and in what way?
Did it help your learning, or maybe in some way hinder it?
-
All sources (such as books, web pages, colleagues and LLMs)
used in the solution of the assignment must be stated.
|
Thomas Padron-McCarthy
(thomas.padron-mccarthy@oru.se)
August 28, 2025