-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.py
34 lines (30 loc) · 850 Bytes
/
parse.py
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
def read_sexp(filename):
terms = []
with open(filename) as f:
for line in f:
if line.startswith("#"):
continue
i = 0
s = 0
ret = line.strip()
while i < len(ret):
char = ret[i]
if char == '(':
terms.append(char)
s = i + 1
elif char == ')':
if 0 < s < i:
terms.append(ret[s:i])
s = 0
terms.append(char)
i += 1
if 0 < s < i:
terms.append(ret[s:i])
return terms
def test():
filename = "./data/dep0.txt" # gbk
# filename = "./data/dep0.s"
terms = read_sexp(filename)
print(terms)
if __name__ == '__main__':
test()