#!/usr/bin/env io Stack := List clone Stack evalToken := method(token, if(token == "", return) // a bug in String split? num := token asNumber if(num, push(num), applyOperator(token)) ) Stack top := method(at(count - 1)) Stack applyOperator := method(op, if(Number hasSlot(op), if(count < 2, Error raise("pop", "Stack underflow")) num2 := pop; num1 := pop push(num1 perform(op, num2)), Error raise("operator", "Unknown operator: " + op) ) ) while(line := File standardInput readLine, tokens := line split(" ", "\t") try( tokens foreach(i, token, Stack evalToken(token)) if(Stack top, write(Stack top, "\n")) ) catch(Exception, e, write(e description, "\n") ) )