<html><head><meta name="color-scheme" content="light dark"></head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">% Left-corner parser for Prolog, with oracle, including predicate for
% arc-eager as well as arc-standard parsing.
%
% Written by: Matthew W. Crocker
% Date: 28 April 2000

% Operator to be used in phrase structure rules.

:- op(1100, xfx, '---&gt;').

% Main predicate for running the test sentences.
do(S) :-
				test(S,Sentence),
    write(Sentence),nl,
    parse([],Sentence).

% Done
parse([s],[]) :- write('[]'),nl.

% Reduce
parse([Y,X|Rest],String) :-
    (LHS ---&gt; X,Y),
				write([LHS|Rest]),nl,
    parse([LHS|Rest],String).

% Shift
parse(Stack,[Word|Rest]) :-
    (Cat ---&gt; [Word]),
    write(Stack),nl,
    parse([Cat|Stack],Rest).

% Grammar

s ---&gt; np, vp.
np ---&gt; possnp, np.
np ---&gt; det, n.
np ---&gt; np, rc.
det ---&gt; np, poss.
rc ---&gt; rpro, sgap.
sgap ---&gt; np, vt.
vp ---&gt; vt, np.
vp ---&gt; vs, s.
vp ---&gt; vpart, part.

% Lexicon

det ---&gt; [the].
rpro ---&gt; [that].
poss ---&gt; [s].
part ---&gt; [down].

n ---&gt; [man].
n ---&gt; [dog].
n ---&gt; [cat].
n ---&gt; [mouse].
n ---&gt; [book].
n ---&gt; [bowl].

vt ---&gt; [read].
vt ---&gt; [chased].
vt ---&gt; [bit].

vs ---&gt; [knows].
vs ---&gt; [believes].
vs ---&gt; [said].

vpart ---&gt; [fell].

% Test sentences

test(easy,[the,man,read,the,book]).
test(centre,[the, man, that, the, dog, that, the, cat, chased, bit, read, the, book]).
test(right,[the, man, believes, the, dog, knows, the, cat, said, the, mouse, read, the, book]).
test(left,[the,man,s,dog,s,bowl,fell,down]).







</pre></body></html>