summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-03-15 17:11:03 +1100
committerJed Barber <jjbarber@y7mail.com>2014-03-15 17:11:03 +1100
commit677d2a38117bbcc0d7599e5a2f556c3ff3d1f58b (patch)
treefa800100d161f872c9717784f6884224dc6fe412
Input functions to get a list of words
-rw-r--r--read.pro52
1 files changed, 52 insertions, 0 deletions
diff --git a/read.pro b/read.pro
new file mode 100644
index 0000000..a554a22
--- /dev/null
+++ b/read.pro
@@ -0,0 +1,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}.
+