-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfori.py
More file actions
75 lines (72 loc) · 2.29 KB
/
fori.py
File metadata and controls
75 lines (72 loc) · 2.29 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
from re import sub
# BTW docker.txt and out.txt are tests
# This whole project is still in development, so don't use it yet!!
def main(a):
b = a.split(" ")
b[0] = sub(b[0], "FOR", b[0])
b[3] = b[3].replace("range(", "")
b[3] = b[3].replace(")", "")
b[3] = b[3].replace(",", " TO ")
b[3] = b[3].replace(":", "")
b[2] = sub(b[2], "<-", b[2])
b[4] = b[4].replace(")", "")
b[4] = b[4].replace(":", "")
j = f"STEP {b[1]}+=1"
c = b + [j]
t = list(map(lambda s: s.strip(), c))
return t
def whileloop(a):
if a.count("==")==1:
c = a.replace(":", "")
c = c.replace("==", " ")
c = c.split(" ")
c[0] = sub(c[0], "WHILE", c[0])
d = c + ["DO"]
t = list(map(lambda s: s.strip(), d))
f = "=="
return f"{t[0]} {t[1]}{f}{t[2]} {t[3]}\n"
elif a.count(">=")==1:
c = a.replace(":", "")
c = c.replace(">=", " ")
c = c.split(" ")
c[0] = sub(c[0], "WHILE", c[0])
d = c + ["DO"]
t = list(map(lambda s: s.strip(), d))
f = ">="
return f"{t[0]} {t[1]}{f}{t[2]} {t[3]}\n"
elif a.count("<=")==1:
c = a.replace(":", "")
c = c.replace("<=", " ")
c = c.split(" ")
c[0] = sub(c[0], "WHILE", c[0])
d = c + ["DO"]
t = list(map(lambda s: s.strip(), d))
f = "<="
return f"{t[0]} {t[1]}{f}{t[2]} {t[3]}\n"
elif a.count("!=")==1:
c = a.replace(":", "")
c = c.replace("!=", " ")
c = c.split(" ")
c[0] = sub(c[0], "WHILE", c[0])
d = c + ["DO"]
t = list(map(lambda s: s.strip(), d))
f = "!="
return f"{t[0]} {t[1]}{f}{t[2]} {t[3]}\n"
elif a.count(">")==1 and a.count(">=")!=1:
c = a.replace(":", "")
c = c.replace(">", " ")
c = c.split(" ")
c[0] = sub(c[0], "WHILE", c[0])
d = c + ["DO"]
t = list(map(lambda s: s.strip(), d))
f = ">"
return f"{t[0]} {t[1]}{f}{t[2]} {t[3]}\n"
elif a.count("<")==1 and a.count("<=")!=1:
c = a.replace(":", "")
c = c.replace("<", " ")
c = c.split(" ")
c[0] = sub(c[0], "WHILE", c[0])
d = c + ["DO"]
t = list(map(lambda s: s.strip(), d))
f = "<"
return f"{t[0]} {t[1]}{f}{t[2]} {t[3]}\n"