Resembles stack operations of original C version, tested with calculator example