(load "utils.l")
(load "atn.l")
(load "nets.l")
(load "dict.l")

;; "parse" sits in a loop reading in sentences via "read-in."  If it
;; gets "quit." it stops.  Otherwise it pretty prints the "atn" of
;; the senetence, i.e. the parse tree.

(defun parse ()
  (prog ()
    loop
    (format t "~%% ")
    (let ((form (read-in)))
      (cond ((equal form '(quit |.|)) (return 't))
	    (t (eval `(pp ,(atn form))) (go 'loop))))))

;; "read-in" reads one word at a time, exploding it and checking to see
;; if is the last word of the sentence (it has a final punctuation on it).
;; If so it outputs a list of the word and the punctuation.  Otherewise
;; it creates a list who's car is the word and who's cdr is the value
;; of another "read-in."

(defun read-in ()
  (let* ((word (read)) (expl (explode word)) (end (last expl)))
    (cond ((eq word nil) nil)
	  ((intersectp end '(|.| |!| |?|))
	   (list (implode (butlast expl)) end))
	  (t (cons (implode expl) (read-in))))))
    
