-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemulator.py
57 lines (51 loc) · 1.98 KB
/
emulator.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
# Importing necessary modules
# MOHAMED NASRAOUI
from datetime import datetime
from interpreter import Interpreter
import readline
# Initializing variables
running = True
verbose = False
current_time = datetime.now().strftime("%b %-d %Y, %H:%M:%S:%f")
print("NAS processor emulator 1.0 ({})\nType 'help' for more information.".format(current_time))
# Main loop for user interaction
while running == True:
cmd = input("NAS::").lower()
# Exiting the emulator
if cmd=="exit" :
print("Exiting...")
running = False
# Displaying help information
elif cmd=="help":
print("NAS Processor Emulator Help:")
print("--------------------------------------------------")
print("Commands available:")
print(" HELP\t\tDisplay this help message.")
print(" EXIT\t\tExit the emulator.")
print(" CONFIG\tChange current configuration.")
print(" RUN\t\tLoad and execute instructions from a source file.")
print()
print("Instructions in source file:")
print(" Each line of the source file should contain an instruction to be executed.")
print(" Instructions must be compatible with the NAS processor's instruction set.")
print(" Follow the syntax given in the file help.nas.")
# Configuring emulator settings
elif cmd=="config":
ans = input("Enable verbose ?(Y\\n)").lower()
if ans=="y":
verbose = True
print("Verbose mode enabled !")
else :
verbose = False
print("Verbose mode disabled !")
# Running instructions from a source file
elif cmd=="run" :
code = input("\tSource file to emulate : ")
try:
with open(code, 'r') as file:
pass
except Exception:
print(">>>EmulatorError: File Not Found")
else:
interpreter = Interpreter(code, verbose)
interpreter.run()