-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun_VM.py
31 lines (25 loc) · 913 Bytes
/
run_VM.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
from Scanner_Parser_Patito import PatitoParser, PatitoLexer
from Virtual_Machine import Virtual_Machine
files = ['main_VM.txt', 'test_elseif.txt']
while len(files) > 0:
quads = []
var_table = {}
cte_table = {}
lexer = PatitoLexer()
parser = PatitoParser(quads=quads, var_table=var_table, cte_table=cte_table)
f = files.pop()
with open(f, 'r') as file:
data = file.read()
# Parse input
try:
parser.parse(data)
except Exception as e:
print('Parsing error: ', e)
# Create a virtual machine and execute the quadruples
try:
vm = Virtual_Machine(quads, var_table, cte_table)
vm.execute()
# Print the memory after execution
# vm.print_memory()
except Exception as e:
print('Error runing program on Virtual Machine', e)