protected function handleSubExpression()
    {
        // Flag, checking for mismatching parentheses
        $clean = false;

        // Pop operators off the operatorStack until its empty, or
        // we find an opening parenthesis, building subexpressions
        // on the operandStack as we go.
        while ($popped = $this->operatorStack->pop()) {

            // ok, we have our matching opening parenthesis
            if ($popped instanceof SubExpressionNode) {
                $clean = true;
                break;
            }

            $node = $this->handleExpression($popped);
            $this->operandStack->push($node);

        }

        // Throw an error if the parenthesis couldn't be matched
        if (!$clean) {
            throw new ParenthesisMismatchException();
        }


        // Check to see if the parenthesis pair was in fact part
        // of a function application. If so, create the corresponding
        // FunctionNode and push it onto the operandStack.
        $previous = $this->operatorStack->peek();
        if ($previous instanceof FunctionNode) {
            $node = $this->operatorStack->pop();
            $operand = $this->operandStack->pop();
            $node->setOperand($operand);
            $this->operandStack->push($node);
        }
    }
protected function handleSubExpression()
    {
        // Flag, checking for mismatching parentheses
        $clean = false;

        // Pop operators off the operatorStack until its empty, or
        // we find an opening parenthesis, building subexpressions
        // on the operandStack as we go.
        while ($popped = $this->operatorStack->pop()) {

            // ok, we have our matching opening parenthesis
            if ($popped instanceof SubExpressionNode) {
                $clean = true;
                break;
            }

            $node = $this->handleExpression($popped);
            $this->operandStack->push($node);

        }

        // Throw an error if the parenthesis couldn't be matched
        if (!$clean) {
            throw new ParenthesisMismatchException();
        }


        // Check to see if the parenthesis pair was in fact part
        // of a function application. If so, create the corresponding
        // FunctionNode and push it onto the operandStack.
        $previous = $this->operatorStack->peek();
        if ($previous instanceof FunctionNode) {
            $node = $this->operatorStack->pop();
            $operand = $this->operandStack->pop();
            $node->setOperand($operand);
            $this->operandStack->push($node);
        }
    }
protected function handleSubExpression ( ) { // Flag, checking for mismatching parentheses $ clean = false ; // Pop operators off the operatorStack until its empty, or // we find an opening parenthesis, building subexpressions // on the operandStack as we go. while ( $ popped = $ this -> operatorStack -> pop ( ) ) { // ok, we have our matching opening parenthesis if ( $ popped instanceof SubExpressionNode ) { $ clean = true ; break ; } $ node = $ this -> handleExpression ( $ popped ) ; $ this -> operandStack -> push ( $ node ) ; } // Throw an error if the parenthesis couldn't be matched if ( ! $ clean ) { throw new ParenthesisMismatchException ( ) ; } // Check to see if the parenthesis pair was in fact part // of a function application. If so, create the corresponding // FunctionNode and push it onto the operandStack. $ previous = $ this -> operatorStack -> peek ( ) ; if ( $ previous instanceof FunctionNode ) { $ node = $ this -> operatorStack -> pop ( ) ; $ operand = $ this -> operandStack -> pop ( ) ; $ node -> setOperand ( $ operand ) ; $ this -> operandStack -> push ( $ node ) ; } }
Handle a closing parenthesis, popping operators off the
operator stack until we find a matching opening parenthesis.

@throws ParenthesisMismatchException
Handle a closing parenthesis popping operators off the operator stack until we find a matching opening parenthesis .