/* file: /230/pl/timeflies.pl */ /* natural language parsing with difference lists */ s(S,S0) :- np(d(S,S1)), vp(d(S1,S0)), print(S1), nl. np(d(S,S0)) :- a(d(S,S1)), n(d(S1,S0)). np(d(S,S0)) :- n(d(S,S1)), n(d(S1,S0)). /* noun cluster */ np(N) :- n(N). vp(d(S,S0)) :- v(d(S,S1)), pp(d(S1,S0)). vp(d(S,S0)) :- v(d(S,S1)), np(d(S1,S0)). vp(V) :- v(V). pp(d(S,S0)) :- p(d(S,S1)), np(d(S1,S0)). n(d([time|S],S)). n(d([flies|S],S)). n(d([arrow|S],S)). v(d([like|S],S)). v(d([flies|S],S)). a(d([an|S],S)). p(d([like|S],S)). q :- s([time, flies, like, an, arrow],[]). q1(X) :- s([time, X, like, an, arrow],[]). /* the sentence is ambiguous (but the second meaning is tricky) */