read_in([W|Ws]) :- get0(C), readword(C,W,C1), restsent(W,C1,Ws). /* Given a word and the character after it, read in the rest of the sentence */ restsent(W,10,[]) :- !. restsent(W,_,[]) :- lastword(W), !. restsent(W,C,[W1|Ws]) :- readword(C,W1,C1), restsent(W1,C1,Ws). /* Read in a single word, given an initial character (C), and remembering what character came after the word */ readword(C,W,C1) :- single_char(C,W), !, get0(C1). readword(C,W,C2) :- in_word(C,NewC), !, get0(C1), restword(C1,Cs,C2), name(W,[NewC|Cs]). readword(C,W,C2) :- get0(C1), readword(C1,W,C2). /* When in a word, get the rest of it */ restword(C,[NewC|Cs],C2) :- in_word(C,NewC), !, get0(C1), restword(C1,Cs,C2). restword(C,[],C). /* These are single character words */ single_char(44,','). single_char(61,'='). single_char(59,';'). single_char(34,'"'). single_char(39,X) :- name(X,[39]). single_char(58,':'). single_char(40,'('). single_char(41,')'). single_char(63,'?'). single_char(33,'!'). /* These characters can be inside a word. The second clause lowers upper case letters */ in_word(C,C) :- C>96, C<123. in_word(C,L) :- C>64, C<91, L is C+32. in_word(C,C) :- C>34, C<40. in_word(C,C) :- C>45, C<58. in_word(60,60). in_word(42,42). in_word(62,62). in_word(64,64). in_word(C,C) :- C>92, C<97. in_word(90,90). in_word(45,45). /* These terminate a sentence */ lastword('\').