%	Parses simple sentences such as 'the giraffe eats the apple'

sent(X, Y) :- np(X, U), vp(U, Y).

np(X, Y) :- det(X, U), noun(U, Y).

vp(X, Y) :- iverb(X, Y).
vp(X, Y) :- tverb(X, U), np(U, Y).

det([the, ..Y], Y).
det([a, ..Y], Y).

noun([giraffe, ..Y], Y).
noun([apple, ..Y], Y).

iverb([dreams, ..Y], Y).

tverb([dreams, ..Y], Y).
tverb([eats, ..Y], Y).

parse(X) :-
	sent(X, []), !,
	write(right), nl.
parse(X) :- write(wrong), nl.

check :-
	inlist(X),
	parse(X),
	check.

inlist(X) :- ratom(Y), next(Y, X).

next(., []) :- !.
next(X, [X, ..Y]) :- inlist(Y).
