% file: predlogi
% authors: Fernando C.N. Pereira and David H.D. Warren
% this program translates a sentences into predicate logic
% query1: s(P, [john,lives], [])?
% query2: s(P, [a,man,lives], [])?
% query3: s(P, [every,man,lives], [])?
% query4: s(P, [a,woman,that,lives,loves,john], [])?

:- op(500,xfy,&).
:- op(600,xfy,->).
dcg!
s(P) --> np(X,P1,P), vp(X,P1).

np(X,P1,P) --> det(X,P2,P1,P), noun(X,P3), rc(X,P3,P2).
np(X,P,P) --> pn(X).

vp(X,P) --> tv(X,Y,P1), np(Y,P1,P).
vp(X,P) --> iv(X,P).

rc(X,P1,(P1&P2)) --> [that], vp(X,P2).
rc(_,P,P) --> [].

det(X,P1,P2, all(X,(P1->P2))) --> [every].
det(X,P1,P2, exists(X,(P1&P2))) --> [a].

noun(X,man(X)) --> [man].
noun(X,woman(X)) --> [woman].

pn(john) --> [john].

tv(X,Y,loves(X,Y)) --> [loves].

iv(X,lives(X)) --> [lives].

