;;; animals.scm: code to start you with defining a grammar for the 
;;;              animals frame system.
;;; 
;;;              Accepts:
;;;              (bozo is a elephant)
;;;              (bozo s color is black)
;;;             
;;;              You'll need to extend the definitions here so it can deal
;;;              with all the inputs shown in the problem set



;;; specialised vocabulary for this application
(define vocabulary-word 
  (define-tree 
    '(branch (elephant rtn 'elephant)
	     (animal rtn 'animal)
             (bozo rtn 'bozo)
             (fred rtn 'fred)
	     (color rtn 'color)
	     (black rtn 'black)
	     (white rtn 'white)
	     (pink rtn 'pink)
	     (red rtn 'red)
	     (size rtn 'size)
	     (small rtn 'small)
	     (medium rtn 'medium)
	     (large rtn 'large)
	     )))


(define main (define-tree 
  '(branch	      
         
    ;; ... IS A ....
    ((vocabulary-word --> word1) is (determiner) (vocabulary-word --> word2)
				 if-end-rtn
				 (define-instance word1 word2))
   
    ;; ... S ... IS ....
    ((vocabulary-word --> word1) s (vocabulary-word --> word2)
				 is (vocabulary-word --> word3)
				 if-end-rtn
				 (define-class-default word1 word2 word3))

    ;; WHAT IS FOO s ATTRIBUTE
    (what is (vocabulary-word --> o) s (vocabulary-word --> attr)
	  if-end-rtn (format #t "~a s ~a is ~a"
			     o
			     attr
			     (get-property o attr)))

    ;; WHAT IS THE ATTR OF FOO
    (what is the (vocabulary-word --> attr) of (vocabulary-word --> o)
	  if-end-rtn (format #t "~a s ~a is ~a"
			     o
			     attr
			     (get-property o attr)))
    
    ;; IS FOO s ATT1 ATT2
    (is (vocabulary-word --> o) s (vocabulary-word --> att1)
	(vocabulary-word --> att2)
	if-end-rtn (format #t "~a"
			   (eq? (get-property o att1) att2)))

    
    ;; EVERY .... IS A ....
    (every (vocabulary-word --> o) is (determiner) 
	   (vocabulary-word --> c)
	   if-end-rtn
	   (define-class c o))

    ;; EACH FOO HAS A ATTR OBJ
    (each (vocabulary-word --> o) has a (vocabulary-word --> attr)
	  (vocabulary-word --> item)
	  if-end-rtn
	  (format #t "~a"
		  (list-search-positive
		   (get-keys-and-values (get-class o))
		   (lambda (pair)
		     (eq? attr (cadr pair))))))
    

    ;; -- Not Recognised --
   (stop if-end-rtn 'quit)
   (rtn (format #t "~%Sorry, I do not understand")
	#f))))


