22
24
25 :- mode initread(-). 26 :- mode readrest(+,-). 27 :- mode word(-,?,?). 28 :- mode words(-,?,?). 29 :- mode alphanum(+,-). 30 :- mode alphanums(-,?,?). 31 :- mode digits(-,?,?). 32 :- mode digit(+). 33 :- mode lc(+,-). 34
35 :- public read_in/1. 36
38
39read_in(P):-initread(L),words(P,L,[]),!,to_nl.
40
41initread([K1,K2|U]):-get(K1),get0(K2),readrest(K2,U).
42
43readrest(46,[]):-!.
44readrest(63,[]):-!.
45readrest(33,[]):-!.
46readrest(K,[K1|U]):-K=<32,!,get(K1),readrest(K1,U).
47readrest(K1,[K2|U]):-get0(K2),readrest(K2,U).
48
49words([V|U]) --> word(V),!,blanks,words(U).
50words([]) --> [].
51
52word(U1) --> [K],{lc(K,K1)},!,alphanums(U2),{name(U1,[K1|U2])}.
53word(nb(N)) --> [K],{digit(K)},!,digits(U),{name(N,[K|U])}.
54word(V) --> [K],{name(V,[K])}.
55
56alphanums([K1|U]) --> [K],{alphanum(K,K1)},!,alphanums(U).
57alphanums([]) --> [].
58
59alphanum(95,95) :- !.
60alphanum(K,K1):-lc(K,K1).
61alphanum(K,K):-digit(K).
62
63digits([K|U]) --> [K],{digit(K)},!,digits(U).
64digits([]) --> [].
65
66blanks--> [K],{K=<32},!,blanks.
67blanks --> [].
68
69digit(K):-K>47,K<58.
70
71lc(K,K1):-K>64,K<91,!,K1 is K\/8'40.
72lc(K,K):-K>96,K<123.
73
74to_nl :-
75 repeat,
76 get0(10), !