-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathforwardparser.py
More file actions
57 lines (56 loc) · 1.32 KB
/
forwardparser.py
File metadata and controls
57 lines (56 loc) · 1.32 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def parse(string):
res = ""
for o in string:
try:
c = chr(o)
except:
pass
if o == 0x24:
res += "deriv("
elif o == 0x25:
res += "int("
elif o == 0x2B:
res += ","
elif 0x30 <= o <= 0x39:
res += c # digit
elif o == 0x3A:
res += "."
elif 0x41 <= o <= 0x5A:
res += c # letter
elif o == 0x70:
res += "+"
elif o == 0x71:
res += "-"
elif o == 0x82:
res += "*"
elif o == 0x83:
res += "/"
elif o == 0xBC:
res += "sqrt("
elif o == 0xBD:
res += "curt("
elif o == 0xBE:
res += "ln("
elif o == 0xBF:
res += "e^("
elif o == 0xC0:
res += "log("
elif o == 0xC1:
res += "10^("
elif o == 0xC2:
res += "sin("
elif o == 0xC3:
res += "arcsin("
elif o == 0xC4:
res += "cos("
elif o == 0xC5:
res += "arccos("
elif o == 0xC6:
res += "tan("
elif o == 0xC7:
res += "arctan("
elif o == 0xF0:
res += "^"
else:
print("unknown ord", o)
return res