Exercise 4.48: add parsing complex sentences

This commit is contained in:
Oliver Payne 2024-01-08 23:00:32 +00:00
parent b99442949d
commit 43d230f0e6
1 changed files with 13 additions and 7 deletions

View File

@ -6,15 +6,12 @@
(define adjectives '(adjective happy lazy))
(define connectives '(connective and but or))
;; output of parse
'(sentence (noun-phrase (article the) (noun cat))
(verb eats))
(define (parse-sentence)
(list 'sentence
(parse-noun-phrase)
(parse-word verbs)))
(define (parse-noun-phrase)
(list 'noun-phrase
(parse-word articles)
@ -48,11 +45,20 @@
(parse-word prepositions)
(parse-noun-phrase)))
(define (parse-sentence)
(list 'sentence
(define (parse-simple-sentence)
(list 'simple-sentence
(parse-noun-phrase)
(parse-verb-phrase)))
(define (parse-sentence)
(define (maybe-extend sentence)
(amb sentence
(maybe-extend (list 'compound-sentence
sentence
(parse-word connectives)
(parse-simple-sentence)))))
(maybe-extend (parse-simple-sentence)))
(define (parse-verb-phrase)
(define (maybe-extend verb-phrase)
(amb verb-phrase