Homework week 3
1) nut-compiler has not been finished. There are no "let",
"enum" and
string. Extend nut-compiler (nut.txt) to include them. You
can have a
look at "nut3-compiler.txt" for a guide, or you can look at the C
source in "nut31/compile" directory, nut.c.
2) (bonus) n-code object can be made "relocatable", i.e. not
dependent on the
absolute location in the memory. This can be achieved by
"linearising"
the n-code tree. The simplest form is the "prefix" form.
See the
following example:
source
(+ 2 3)
becomes readable n-code:
(+ lit.2 lit.3)
which is stored in the memory (say starts at 6)
2 1 16 3 0
4 1 16 2 2
6 1 6 0 4
this object is not relocatable, it embeds the absolute location in the
"next" link. A list can be represented by prefixing it with its
length, no "next" link is necessary.
(+ lit.2 lit.3)
becomes
3 + lit.2 lit.3
another example:
(+ lit.2 (+ lit.3 lit.4))
becomes
3 + lit.2 3 + lit.3 lit.4
This representation can be converted into an n-code tree (at any
location).
Write a program to output n-code object in linear form to a file and
read it back into the memory properly at a different location.
You can
use "prList" to print the readable n-code out to check it.
22 June 2006