private function process() { //echo "Processing postfix notation:\n\n"; $tempStack = new Stack(); while ($token = $this->rpnNotation->dequeue()) { if ($token instanceof Number) { $tempStack->push($token); } elseif ($token instanceof Operator || $token instanceof Funct) { /** @var $token Operator|Funct */ if ($tempStack->count() < $token->numOfArgs()) { throw new Exception(sprintf('Required %d arguments, %d given.', $token->numOfArgs(), $tempStack->count())); } $arg = $tempStack->popMultiple($token->numOfArgs()); $tempStack->push($token->execute(array_reverse($arg))); } } return $tempStack->pop()->value; }