-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomplack
executable file
·88 lines (79 loc) · 2.53 KB
/
complack
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
83
84
85
86
87
#!/bin/python
from constants import *
import settings as s
import subroutines as subroutine
from handleFunctions import *
import sys
if __name__ == "__main__":
try:
file = open(sys.argv[1])
code = file.read()
code = code.splitlines()
except:
print("Usage:")
print("python", sys.argv[0], "complack.sse")
exit(1)
s.init()
code = s.cleanCode(code)
s.mapCode(code)
if s.debug == True:
for i in range(0, len(code)):
print(i, code[i])
print()
while s.point < len(code):
l = code[s.point].strip()
line = l.split()
ins = line[0]
if s.debug == True:
print("Instruction:", l)
print("Pointer:", s.point)
print("Stack:", s.stack)
try:
if l[0] == commentary:
s.point += 1
elif ins == iInput:
handleInput(line[1])
elif ins == iOutput:
handleOutput(line[1], line[2])
elif ins == iPush:
handleStackPush(line[1])
elif ins == iPop:
handleStackPop(line[1])
elif ins == iIncrease:
handleIncrease(line)
elif ins == iDecrease:
handleDecrease(line)
elif ins == iSet:
handleSet(line)
elif ins == iPrintStack:
handlePrintStack(line[1])
elif ins == iGoto:
handleGoto(line[1])
elif ins == iSwitchStack:
handleStackSwitch(line[1])
# Conditional branching
elif ins == cEqual:
handleIf(line, cEqual)
elif ins == cNotEqual:
handleIf(line, cNotEqual)
elif ins == cBigger:
handleIf(line, cBigger)
elif ins == cSmaller:
handleIf(line, cSmaller)
# Subroutines
elif ins == iGoSub:
subroutine.handleSubroutine(line[1])
elif ins == subInit:
subroutine.handleInitSubroutine(code)
elif ins == subEnd:
subroutine.handleEndSubroutine()
elif ins == iExit:
s.point = len(code)
elif ins == label:
s.point += 1
else:
print("Instruction", ins, "not found", "at line", s.point)
exit(1)
except IndexError:
print("Incorrect use of instruction", ins , "at line", s.point)
exit(1)