% Simple top-down parser
% parse(?Cat, ?S1, ?S2 )
% parse constituent of category Cat, using input string S1 and
% leaving string S2
% Covington (1994), NLP for Prolog Programmers, pp. 152-154

parse_s(List) :-            % extra predicate not defined in Covington
	parse(s,List,[]).


% Top-down Recognizer

parse(C,[Word|S],S) :-
	word(C,Word).

parse(C,S,S1) :-
	rule(C,Cs),
	parse_list(Cs,S,S1).

parse_list([C|Cs],S,S2) :-
	parse(C,S,S1),
	parse_list(Cs,S1,S2).

parse_list([],S,S).


rule(s,[np,vp]).
rule(np,[d,n]).
rule(d,[]).
rule(vp,[v,np]).
rule(vp,[v,np,pp]).
rule(pp,[p,np]).

word(d,the).
word(d,all).
word(d,every).
word(n,cat).
word(n,cats).
word(n,dog).
word(n,dogs).
word(n,elephant).
word(n,elephants).
word(p,near).
word(v,amuse).
word(v,amuses).
word(v,chase).
word(v,chases).
word(v,see).
word(v,sees).