pereira@sri-unix.UUCP (08/15/83)
/* READIN.PL : Read in a sentence into a list of words UTILITY Lawrence Updated: 30 march 81 */ %%% Compile this module %%% READIN requires no other modules /* EXPORT */ :- public read_in/1. /* MODES */ :- mode read_in(?). :- mode initread(-). :- mode readrest(+,-). :- mode word(-,?,?). :- mode words(-,?,?). :- mode alphanum(+,-). :- mode alphanums(-,?,?). :- mode digits(-,?,?). :- mode digit(+). :- mode lc(+,-). read_in(P):-initread(L),words(P,L,[]),!. initread([K1,K2|U]):-get(K1),get0(K2),readrest(K2,U). readrest(46,L) :- !, possiblythere(46,L). readrest(63,L) :- !, possiblythere(63,L). readrest(33,L) :- !, possiblythere(33,L). readrest(K,[K1|U]):-K=<32,!,get(K1),readrest(K1,U). readrest(K1,[K2|U]):-get0(K2),readrest(K2,U). possiblythere(C,Rest) :- repeat, get0(Next), Next =\= 32, ( Next =:= 31, !, Rest = [] ; Rest = [Next|More], readrest(Next,More) ). words([V|U]) --> word(V),!,blanks,words(U). words([]) --> []. word(U1) --> [K],{lc(K,K1)},!,alphanums(U2),{name(U1,[K1|U2])}. word(N) --> [K],{digit(K)},!,digits(U),{name(N,[K|U])}. word(V) --> [K],{name(V,[K])}. alphanums([K1|U]) --> [K],{alphanum(K,K1)},!,alphanums(U). alphanums([]) --> []. alphanum(K,K1):-lc(K,K1). alphanum(K,K):-digit(K). digits([K|U]) --> [K],{digit(K)},!,digits(U). digits([]) --> []. blanks--> [K],{K=<32},!,blanks. blanks --> []. digit(K):-K>47,K<58. lc(K,K1):-K>64,K<91,!,K1 is K\/8'40. lc(K,K):-K>96,K<123.