; cf_grammar.lm
; grammar.lsp
; D. Gibbon
; 10 April 1988 / 10 Nov 2001
; LISP2 class material
(define *eg1* '(man saw woman))
(define *eg2* '(man saw woman near man))
(define *eg3* '(the man saw the woman near this man))
(define *count* 0)
(define (nl)
(display ##0a))
(define (member? sym set)
(pair? (member sym set)))
(define *initial* 's)
(define (productions)
'( (s np vp)
(s np vp pp)
(np n)
(np det n)
(np n pp)
(np det n pp)
(vp v)
(vp v np)
(vp v pp)
(vp v np pp)
(pp p np)
))
(define (match word term)
(eq? term
(category word)))
(define (category word)
(cadr
(assoc
'cat
(cdr
(assoc
word
(lexicon))))))
(define (lexicon)
'( (the (cat det))
(this (cat det))
(man (cat n))
(woman (cat n))
(saw (cat v))
(visited (cat v))
(with (cat p))
(near (cat p))))
(define (terminal sym)
(member? sym
'(det n v p)))
(define (nonterminal sym)
(member? sym
'(s np vp pp)))