27 lines
847 B
Common Lisp
27 lines
847 B
Common Lisp
|
(in-package #:cl-forth)
|
||
|
|
||
|
;; For debugging purposes.
|
||
|
(defparameter *interpreter*
|
||
|
(make-instance 'interpreter))
|
||
|
|
||
|
(defun main ()
|
||
|
(let ((interp *interpreter*)
|
||
|
(input ""))
|
||
|
(format t "Welcome to CL-Forth! Type your commands below (type 'exit' to quit).~%")
|
||
|
(loop
|
||
|
(format t "CL-FORTH) ")
|
||
|
(finish-output)
|
||
|
(setf input (read-line))
|
||
|
(if (string= input "exit")
|
||
|
(progn
|
||
|
(format t "Exiting CL-Forth. Goodbye!~%")
|
||
|
(return))
|
||
|
(progn
|
||
|
(handler-case
|
||
|
(interpret interp input)
|
||
|
(unknown-word-error (e)
|
||
|
(format t "Error: Unknown word '~a'~%" (token-of e)))
|
||
|
(stack-underflow (e)
|
||
|
(declare (ignore e))
|
||
|
(format t "Error: Stack underflow - cannot pop from an empty stack.~%"))))))))
|