-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
82 lines (65 loc) · 1.91 KB
/
main.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
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
76
77
78
79
80
81
82
import my_parser as P
import my_lexer as L
import code_generator as CG
import time
nom_du_jeu = "RISC_UVSQ"
NB_CASE = 1000
def exec_res(code):
ca = 0
ca0 = 0
CO = 0
R0 = 0
MEM = list()
taille_prog = len(code)
while ca < NB_CASE:
MEM.append(None)
ca = ca + 1
print("--- Python (approx) Conversion ---")
while CO < taille_prog:
# print("CO " + str(CO))
#
# lst = dir()
# for i in lst:
# if i[:1] == 'R':
# print("> {} = {}".format(i, eval(i)))
print(code[CO])
if 'JUMP' not in code[CO] and 'BNEZ' not in code[CO]:
exec(code[CO])
CO = CO + 1
else:
if 'JUMP' in code[CO]:
J = code[CO].split(" ")
CO = CO + (int(eval(J[1])) + int(J[2]))
elif 'BNEZ' in code[CO]:
B = code[CO].split(" ")
if eval(B[2]) != 0:
CO = int(CO) + (int(eval(B[1])) + int(B[3])/2)
CO = int(CO)
# print("> R4 = {}".format(R4))
# print("> CO : {}".format(CO))
# print("> B[2] " + str(eval(B[2])))
else:
CO = CO + 1
#time.sleep(1)
print("--- --- ---\n\n")
lst = dir()
for i in lst:
if i[:1] == 'R':
print("{} = {}".format(i, eval(i)))
print("--- WORD(s) IN MEMORY ---")
for n in MEM:
if n is not None:
print("MEM[{}] = {}".format(ca0, n))
ca0 = ca0 + 1
if __name__ == "__main__":
path = input("Entrez le chemin du fichier à compiler :")
listParse = list()
try:
listParse = P.parse(path)
except FileNotFoundError:
print("Le fichier n'a pas été trouvé.")
#print(listParse)
lexemList = L.lexe(listParse)
#print(lexemList)
code = CG.codeGen(lexemList)
exec_res(code)