Exercise 4.48: add parsing of adjectives

This commit is contained in:
Oliver Payne 2024-01-05 23:07:07 +00:00
parent dfd65eed08
commit b99442949d
1 changed files with 13 additions and 1 deletions

View File

@ -4,6 +4,8 @@
(define articles '(article the a))
(define adjectives '(adjective happy lazy))
;; output of parse
'(sentence (noun-phrase (article the) (noun cat))
(verb eats))
@ -40,6 +42,7 @@
(define prepositions '(prep for to in by with))
(define (parse-prepositional-phrase)
(list 'prep-phrase
(parse-word prepositions)
@ -58,10 +61,11 @@
(parse-prepositional-phrase)))))
(maybe-extend (parse-word verbs)))
;; Extend this to allow an adjective between the article and noun.
(define (parse-simple-noun-phrase)
(list 'simple-noun-phrase
(parse-word articles)
(parse-word nouns)))
(parse-adjective-phrase)))
(define (parse-noun-phrase)
(define (maybe-extend noun-phrase)
@ -71,6 +75,14 @@
(parse-prepositional-phrase)))))
(maybe-extend (parse-simple-noun-phrase)))
;; An adjective phrase is any number of adjectives followed by a
;; simple noun.
(define (parse-adjective-phrase)
(amb (list (parse-word nouns))
(cons
(parse-word adjectives)
(parse-adjective-phrase))))
;; Exercise 4.45: Output of (parse '(the professor lectures to the student in the class with the cat))