-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprog4_2.py
More file actions
37 lines (28 loc) · 801 Bytes
/
Copy pathprog4_2.py
File metadata and controls
37 lines (28 loc) · 801 Bytes
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
import sys
from StackMachine import StackMachine
print("Assignment #4-2, Alexander Pearson-Goulart, pearsongoulart@gmail.com")
stack = StackMachine()
f = open(sys.argv[1])
lines = f.readlines()
f.close()
lines[0].split() ## tokenizes a string
tokenized_lines = []
for l in lines:
tokenized_lines.append(l.split())
for line in tokenized_lines:
if len(line) == 1:
if line[0] == "add":
stack.add()
elif line[0] == "sub":
stack.sub()
elif line[0] == "mul":
stack.mul()
elif line[0] == "div":
stack.div()
elif line[0] == "mod":
stack.mod()
elif line[0] == "pop":
print(stack.pop())
elif len(line) == 2:
if line[0] == "push":
stack.push(line[1])