Hello world! 1
Welcome to WordPress. This is your first post. Edit or delete it, then start blogging!
ADD = 1
PUSH = 2
PRINT = 3
stack = []
program = ( (5, PUSH), (10, PUSH), (ADD,), (PRINT,), )
for line in program:
if line[-1] is PUSH:
stack.append(line[0])
elif line[-1] is PRINT:
print stack.pop()
elif line[-1] is ADD:
t = stack.pop() + stack.pop()
stack.append(t)