stack, _, dictionary = run(text, stack, dictionary)
except UnknownSymbolError as sym:
print('Unknown:', sym)
- except StackUnderflowError:
- print('Not enough values on stack.')
+ except StackUnderflowError as e:
+ print(e) # 'Not enough values on stack.'
except NotAnIntError:
print('Not an integer.')
except NotAListError as e:
(a1 --)
"""
- (a1, s23) = stack
+ try:
+ (a1, s23) = stack
+ except ValueError:
+ raise StackUnderflowError('Cannot pop empty stack.')
return s23
([a1 ...0] -- [...0])
"""
- ((a1, s0), s23) = stack
- return (s0, s23)
+ try:
+ s0, stack = stack
+ except ValueError:
+ raise StackUnderflowError
+ if not isinstance(s0, tuple):
+ raise NotAListError('Not a list.')
+ try:
+ _, s1 = s0
+ except ValueError:
+ raise StackUnderflowError('Cannot take rest of empty list.')
+ return (s1, stack)
def rolldown(stack):