Development method: Getting it to work
The tools that we use to "compile" and "run" our compiler and simulator
in nut are: nut31 and nsim31. Both are written in C. nut31
compiles the source in nut into an object code which is executable by
nsim31, the n-code virtual machine. The output from nut31 has the
default name "a.obj".
nsim31 reads the object code and run it. It also has the system
call that supports the compiler, for example "tokeniser", "read
stdin". Because some object needs the stdin so nsim31 does not
use stdin to name the object file. It reads, by default, the
object named "a.obj", so that stdin is free to be used by the use
program.
Example 1
let the source program be "nut.txt". To compile it:
c:>nut31
< nut.txt
The output will be "a.obj" which is the nut-compiler. When the
compiler is run, it reads input from stdin. Let "t2.txt" be the
source program to be compiled by nut-compiler.
c:>nsim31
< t2.txt
The nut-compiler outputs the result to stdout.
Example 2
We want to compile and run "quick.txt", the quicksort program.
c:>nut31
< quick.txt
It will output a.obj. Then run it by:
c:>nsim31
Example 3
We want to use nut-compiler to compile the program "t2.txt" and to run
it. First, we compile the nut-compiler:
c:>nut31
< nut.txt
Now the nut-compiler is in "a.obj". We run it to compile
"t2.txt". The output is stored in the file "t2.obj".
c:>nsim31
< t2.txt > t2.obj
To run t2.obj, we rename it to "a.obj".
c:>copy
t2.obj a.obj
and run it using nsim31:
c:>nsim31
Example 4
We use nut-compiler (nut.txt) to compile the program "t2.txt" and want
to run it using the nut-simulator (sim.txt).
First we compile the compiler and use it to compile "t2.txt".
c:>nut31
< nut.txt
c:>nsim31 < t2.txt >
t2.obj
Then we compile the simulator and use it to run "t2.obj". The
simulator gets its input from stdin.
c:>nut31
< sim.txt
c:>nsim31 < t2.obj
28 June 2006