-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuilders.py
49 lines (37 loc) · 1.01 KB
/
builders.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from pprint import pprint
from tokenizer import TokenType
def parenthesis2list(tokens):
total = []
n = 0
while n < len(tokens):
i = tokens[n]
if i.value == "(":
n += 1
newtoks = parenthesis2list(tokens[n:])
total.append(newtoks)
while i.value != ")":
i = tokens[n]
n += 1
# n += len(newtoks)
elif i.value == ")":
return total
else:
total.append(i)
n += 1
return total
def negative_numbers(tokens):
i = 0
while i < len(tokens):
p = tokens[i]
if p.type == TokenType.OPERATOR and \
tokens[i+1].type == TokenType.NUMBER and \
p.value == "-":
ntok = p
ntok.end = tokens[i+1].end
ntok.value = p.value + tokens[i+1].value
ntok.type = TokenType.NUMBER
tokens[i] = ntok
del tokens[i+1]
break
i += 1
return tokens