protected function handleExpression($node)
    {
        if ($node instanceof FunctionNode) throw new ParenthesisMismatchException($node->getOperator());
        if ($node instanceof SubExpressionNode) throw new ParenthesisMismatchException($node->getOperator());

        if (!$this->simplifyingParser) return $this->naiveHandleExpression($node);

        if ($node->getOperator() == '~') {

            $left = $this->operandStack->pop();
            if ($left === null) {
                throw new SyntaxErrorException();
            }

            if ($left instanceof NumberNode) {
                return new NumberNode(-$left->getValue());
            }

            if ($left instanceof IntegerNode) {
                return new IntegerNode(-$left->getValue());
            }

            if ($left instanceof RationalNode) {
                return new RationalNode(-$left->getNumerator(), $left->getDenominator());
            }

            $node->setOperator('-');
            $node->setLeft($left);

            return $this->nodeFactory->simplify($node);
        }

        $right = $this->operandStack->pop();
        $left = $this->operandStack->pop();
        if ($right === null || $left === null) {
            throw new SyntaxErrorException();
        }

        $node->setLeft($left);
        $node->setRight($right);

        return $this->nodeFactory->simplify($node);
    }
protected function handleExpression($node)
    {
        if ($node instanceof FunctionNode) throw new ParenthesisMismatchException($node->getOperator());
        if ($node instanceof SubExpressionNode) throw new ParenthesisMismatchException($node->getOperator());

        if (!$this->simplifyingParser) return $this->naiveHandleExpression($node);

        if ($node->getOperator() == '~') {

            $left = $this->operandStack->pop();
            if ($left === null) {
                throw new SyntaxErrorException();
            }

            if ($left instanceof NumberNode) {
                return new NumberNode(-$left->getValue());
            }

            if ($left instanceof IntegerNode) {
                return new IntegerNode(-$left->getValue());
            }

            if ($left instanceof RationalNode) {
                return new RationalNode(-$left->getNumerator(), $left->getDenominator());
            }

            $node->setOperator('-');
            $node->setLeft($left);

            return $this->nodeFactory->simplify($node);
        }

        $right = $this->operandStack->pop();
        $left = $this->operandStack->pop();
        if ($right === null || $left === null) {
            throw new SyntaxErrorException();
        }

        $node->setLeft($left);
        $node->setRight($right);

        return $this->nodeFactory->simplify($node);
    }
protected function handleExpression ( $ node ) { if ( $ node instanceof FunctionNode ) throw new ParenthesisMismatchException ( $ node -> getOperator ( ) ) ; if ( $ node instanceof SubExpressionNode ) throw new ParenthesisMismatchException ( $ node -> getOperator ( ) ) ; if ( ! $ this -> simplifyingParser ) return $ this -> naiveHandleExpression ( $ node ) ; if ( $ node -> getOperator ( ) == '~' ) { $ left = $ this -> operandStack -> pop ( ) ; if ( $ left === null ) { throw new SyntaxErrorException ( ) ; } if ( $ left instanceof NumberNode ) { return new NumberNode ( - $ left -> getValue ( ) ) ; } if ( $ left instanceof IntegerNode ) { return new IntegerNode ( - $ left -> getValue ( ) ) ; } if ( $ left instanceof RationalNode ) { return new RationalNode ( - $ left -> getNumerator ( ) , $ left -> getDenominator ( ) ) ; } $ node -> setOperator ( '-' ) ; $ node -> setLeft ( $ left ) ; return $ this -> nodeFactory -> simplify ( $ node ) ; } $ right = $ this -> operandStack -> pop ( ) ; $ left = $ this -> operandStack -> pop ( ) ; if ( $ right === null || $ left === null ) { throw new SyntaxErrorException ( ) ; } $ node -> setLeft ( $ left ) ; $ node -> setRight ( $ right ) ; return $ this -> nodeFactory -> simplify ( $ node ) ; }
Populate node with operands.

@param Node $node
@retval Node
@throws SyntaxErrorException
Populate node with operands .