How to use Nut tools


nut32.exe is a compiler that take an input source file in Nut and compile it and output an object code (intermediate code).  Use run "cmd" and type the following command:
>  nut32  < source.txt

The screen will display the intermediate code.  The output file is "a.obj".  In a.obj, it contains the actual intermediate code (we will not get into the detail of this code) and the symbol table.  This can be use to check the correctness of the output.
> nsim32 a.obj

Now to run the object code, we use "nsim32.exe".  It takes an nut-object file and execute it. 
Our example shows how the tokeniser work.  The file is named "test-tok.txt".  We will compile and run it on an input (nut-source) text file (ex-ch2.txt).
Here is the flow (and how it looks on the command screen):
> nut32 < test-tok.txt      ;;  compile the test-tok program

E:\prabhas\bag\teaching\proglang\nut\ex>nut32 < test-tok.txt
!=
(fun.2.2 (if (= get.1 get.2 )lit.0 lit.1 ))
nop
(fun.0.0 (lit.0 ))
print
(fun.1.1 (sys.1 get.1 ))
printc
(fun.1.1 (sys.2 get.1 ))
space
(fun.0.0 (sys.2 lit.32 ))
nl
(fun.0.0 (sys.2 lit.10 ))
exit
(fun.0.0 (sys.13 ))
prstr
(fun.1.1 (while (ldx.1 lit.0 )(do (call.23 (ldx.1 lit.0 ))(put.1 (+ get.1 lit.1
)))))
tok
tokenise
(fun.0.0 (do (st.0 (sys.3 ))(call.21 )))
testtok
(fun.0.0 (do (call.33 )(while (call.18 (ldy.0 lit.0 )lit.127 )(do (call.30 ld.0
)(call.25 )(call.33 )))))
main
(fun.0.0 (do (sys.11 )(call.34 )))

E:\prabhas\bag\teaching\proglang\nut\ex>

run a.obj which read the input from stdin, file ex-ch2.txt

E:\prabhas\bag\teaching\proglang\nut\ex>nsim32 a.obj < ex-ch2.txt
( def print ( a ) ( ) ( sys 1 a ) ) ( def sq ( x ) ( ) ( * x x ) ) ( def main (
) ( a ) ( print ( sq 20 ) ) )
E:\prabhas\bag\teaching\proglang\nut\ex>

Happy playing Nut !

last update 1 June 2009