-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtokenizer.pl
More file actions
40 lines (37 loc) · 1.13 KB
/
Copy pathtokenizer.pl
File metadata and controls
40 lines (37 loc) · 1.13 KB
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
tokenize_file(Filename, TokenList):-
open(Filename, read, Stream),
get0(Stream, T),
read_word(Stream,T,InputList),
removeSpaces(InputList, NoSpaceList),
atom_codes(TokenString, NoSpaceList),
!, atomic_list_concat(TokenList, ' ',TokenString).
read_word(_, -1,[]).
read_word(_, end_of_file,[]).
read_word(Stream,Char, [Char|Content]):-
get0(Stream, Val),
read_word(Stream, Val, Content).
removeSpaces([], []).
removeSpaces([9|Tail], [32|NewList]):-
!, removeS(Tail, New),
!, removeSpaces(New, NewList).
removeSpaces([10|Tail], [32|NewList]):-
!, removeS(Tail, New),
!, removeSpaces(New, NewList).
removeSpaces([13|Tail], [32|NewList]):-
!, removeS(Tail, New),
!, removeSpaces(New, NewList).
removeSpaces([32|Tail], [32|NewList]):-
!, removeS(Tail,New),
!, removeSpaces(New, NewList).
removeSpaces([Head|Tail], [Head|NewList]):-
!, removeSpaces(Tail, NewList).
removeS([],[]).
removeS([9|Tail],NewList):-
!, removeS(Tail, NewList).
removeS([10|Tail],NewList):-
!, removeS(Tail, NewList).
removeS([13|Tail],NewList):-
!, removeS(Tail, NewList).
removeS([32|Tail],NewList):-
!, removeS(Tail,NewList).
removeS([Head|Tail],[Head|Tail]).