summaryrefslogtreecommitdiff
path: root/read.pro
blob: a554a22b38b3b583afdaac074e7a35cfa3230efc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52


% functions for obtaining a line of input text and parsing
% it into a list of words

% prompt provides the user with a '>' prompt as well
% readList merely obtains and parses the input


prompt(L) :-
    write('> '),
    readList(L).


readList(L) :-
    readLine(X),
    wordList(L,X,[]), !.


readLine(L) :-
    get0(C),
    buildList(C,L).


buildList(10,[]) :- !.
buildList(C,[C|X]) :-
    get0(C2),
    buildList(C2,X).


wordList([X|Y]) --> word(X), whitespace, wordList(Y).
wordList([X]) --> whitespace, wordList(X).
wordList([X]) --> word(X).
wordList([X]) --> whitespace, word(X).


word(W) --> charList(X), {name(W,X)}.


charList([X|Y]) --> char(X), charList(Y).
charList([X]) --> char(X).


char(X) --> [X], {X>=33}.


whitespace --> whsp, whitespace.
whitespace --> whsp.


whsp --> [X], {X<33}.