-
Notifications
You must be signed in to change notification settings - Fork 0
/
tt.py
111 lines (111 loc) · 2.52 KB
/
tt.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
STACKONE = []
STACKTWO = []
STACKTHREE = []
LOG = []
CHLOG = []
A = 0
B = 0
C = 0
DEPTH = 0
CODE = 0
LINE = 0
CHAR = 0
TMPCMD = 0
CMD = 0
DASH = 0
def Push(stack,number):
stack.append(number)
def SPop(stack):
if len(stack) == 0:
stack.append(0)
return stack.pop()
import linecache
import os,sys
linecache.clearcache()
#A = os.getcwd()
#print('Choose a Triple Threat program file in: ' + A)
#CODE = input("File name: ")
#CODE = A+"/"+CODE
#print(CODE)
CODE = sys.argv[1]
LINE=1
while 1 == 1:
TMPCMD = linecache.getline(CODE, LINE)
CMD = TMPCMD[CHAR:CHAR+2]
if DEPTH == 0:
if CMD == '11':
Push(STACKONE,0)
if CMD == '22':
Push(STACKTWO,1)
if CMD == '33':
A = SPop(STACKTHREE)
if CMD == '12':
A = SPop(STACKONE)
Push(STACKTWO,A)
if CMD == '23':
if len(STACKTWO) == 0:
C = input('> ')
A = int(C)
STACKTWO.append(A)
A = SPop(STACKTWO)
Push(STACKTHREE,A)
if CMD == '31':
A = SPop(STACKTHREE)
Push(STACKONE,A)
Push(STACKONE,A)
if CMD == '13':
A = SPop(STACKONE)
B = SPop(STACKTHREE)
C = A+B
Push(STACKTHREE,C)
if CMD == '21':
A = SPop(STACKONE)
B = SPop(STACKTWO)
C = A-B
Push(STACKONE,C)
if CMD == '32':
A = SPop(STACKTHREE)
B = SPop(STACKTWO)
Push(STACKTWO,A)
print(B)
if CMD == '10':
A = SPop(STACKONE)
if A == 0:
DEPTH=DEPTH+1
else:
Push(LOG,LINE)
Push(CHLOG,CHAR)
if CMD == '30':
A = SPop(STACKTHREE)
if A != 0:
B = SPop(LOG)
Push(LOG,B)
LINE = B
C = SPop(CHLOG)
Push(CHLOG,C)
CHAR = C
else:
B = SPop(LOG)
C = SPop(CHLOG)
if CMD == '00':
break
if CMD == '':
break
else:
if CMD == '10':
DEPTH=DEPTH+1
if CMD == '30':
DEPTH=DEPTH-1
if CMD == '00':
DEPTH=0
break
if CMD == '':
DEPTH=0
break
DASH = TMPCMD[CHAR+2:CHAR+3]
if DASH == "-":
CHAR=CHAR+3
else:
CHAR=0
LINE = LINE + 1
#print('End of program.')