(define sent [Input Proof] <- (vp (np [Input [[sent --> np vp] | Proof]])) _ -> (fail)) (define np [Input Proof] <- (n (det [Input [[np --> det n] | Proof]])) [Input Proof] <- (name [Input [[np --> name] | Proof]]) _ -> (fail)) (define name [["John" | Input] Proof] -> [Input [[name --> "John"] | Proof]] [["Bill" | Input] Proof] -> [Input [[name --> "Bill"] | Proof]] _ -> (fail)) (define det [["the" | Input] Proof] -> [Input [[det --> "the"] | Proof]] [["a" | Input] Proof] -> [Input [[det --> "a"] | Proof]] [["that" | Input] Proof] -> [Input [[det --> "that"] | Proof]] [["this" | Input] Proof] -> [Input [[det --> "this"] | Proof]] _ -> (fail)) (define n [["ball" | Input] Proof] -> [Input [[n --> "ball"] | Proof]] [["girl" | Input] Proof] -> [Input [[n --> "girl"] | Proof]] _ -> (fail)) (define vp [Input Proof] <- (np (vtrans [Input [[vp --> vtrans np] | Proof]])) [Input Proof] <- (vp [Input [[vp --> vintrans] | Proof]]) _ -> (fail)) (define vtrans [["kicks" | Input] Proof] -> [Input [[vtrans --> "kicks"] | Proof]] [["likes" | Input] Proof] -> [Input [[vtrans --> "likes"] | Proof]] _ -> (fail)) (define vintrans [["jumps" | Input] Proof] -> [Input [[vintrans --> "jumps"] | Proof]] _ -> (fail)) (define parse Sentence -> (let Parse (sent [Sentence []]) (if (parsed? Parse) (output_parse Parse) ungrammatical))) (define parsed? [[] _] -> true _ -> false) (define output_parse [_ Parse_Rules] -> (reverse Parse_Rules)) (parse ["the" "girl" "likes" "the" "ball"]) (parse ["the" "cat" "likes" "the" "girl"])