play with self interpreter
the executable code for A interpreter is a.exe. It is a full
interpreter of A-language implemented in C. When it starts,
the "self-interpreter" written in K itself is loaded (file: lib.k,
data.k, base.k, eval.k). The "self-interpreter" is started with
the command (run). The following "screen dump" shows an example
session with the interpreter.
C:\prabhas> a
;; start the
interpreter
...
;; message from interpreter
eval
;; loading "self-interpreter"
eval2
evalExp
evalPrint
run
-> (+ 2 (* 3
4))
;; user input
14
;; computer reply
-> (define sq (x)(* x
x)) ;; define a function
sq
;; computer reply
-> (sq
5)
;; use a newly defined function
25
->(run)
;; start self-interpreter
-> (+ 2 (* 3 4))
( + 2 ( * 3 4 ) )
;; parsing the input
A6
#2
A8
#3
#4
;; machine code
14
;; result of executing code
-> (define sq (x)(* x
x)) ;; define a function
( define sq ( x ) ( * x x )
) ;; parsing
A8
L1
L1
;; machine code
sq
-> quit
;; stop self-interpreter
quit 0
;; computer report stopping
self-interpreter
-> quit
;; stop interpreter
C:\prabhas>
To try it, download the package "mcode.zip" and goto the directory
"self-k". All programs in A-language are there including the
executable a.exe. For the source of interpreter in C, goto the
directory "c".
last update 18 November 2004