-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadlineF.pl
48 lines (42 loc) · 1.06 KB
/
readlineF.pl
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
readlineF(File) :-
see(File),
repeat,
inputline(L),
L = [end_of_file],
!,
seen.
inputline(L) :-
buildlist(L, []),
reverse(L, L1),
writeout(L1),
!.
writeout([]).
writeout([end_of_file]).
writeout(L) :-
write('Sentence: '),
write(L),
nl.
buildlist(L, OldL) :-
findword(Word, []),
(
(Word = [], L = OldL);
(Word = [end_of_file], L = [end_of_file]);
(Word = [sep], buildlist(L, OldL));
(Word = [termin|Word1], name(S, Word1), L = [S|OldL]);
(name(S, Word), buildlist(L, [S|OldL]))
).
findword(Word, OldWord) :-
get0(X),
(
(terminator(X), Word = [termin|OldWord]);
(separator(X), ((OldWord = [], Word = [sep]); Word = OldWord));
(X < 0, Word = [end_of_file]);
(append(OldWord, [X], New), findword(Word, New))
).
separator(10). /* end of line */
separator(32). /* space*/
separator(44). /* comma */
separator(58). /* colon */
terminator(46). /* full stop */
terminator(33). /* exclamation mark */
terminator(63). /* question mark */