:- module(read, [prompt/1, readList/1]). % 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), buildLine(C,L). buildLine(10,[]) :- !. buildLine(C,[C|X]) :- get0(C2), buildLine(C2,X). wordList([X|Y]) --> word(X), whitespace, wordList(Y). wordList([X]) --> whitespace, wordList(X). wordList([X]) --> word(X). wordList([X]) --> word(X), whitespace. 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}.