public function visitExpressionNode(ExpressionNode $node)
    {
        $operator = $node->getOperator();
        $left = $node->getLeft();
        $right = $node->getRight();

        switch ($operator) {
            case '+':
                $leftValue = $left->accept($this);
                $rightValue = $this->parenthesize($right, $node);

                return "$leftValue+$rightValue";

            case '-':
                if ($right) {
                    // Binary minus

                    $leftValue = $left->accept($this);
                    $rightValue = $this->parenthesize($right, $node);

                    return "$leftValue-$rightValue";
                } else {
                    // Unary minus

                    $leftValue = $this->parenthesize($left, $node);

                    return "-$leftValue";
                }

            case '*':
            case '/':

                $leftValue = $this->parenthesize($left, $node, '', false);
                $rightValue = $this->parenthesize($right, $node, '', true);

                return "$leftValue$operator$rightValue";

            case '^':
                $leftValue = $this->parenthesize($left, $node, '', true);
                $rightValue = $this->parenthesize($right, $node, '', false);

                return "$leftValue$operator$rightValue";
        }
    }
public function visitExpressionNode(ExpressionNode $node)
    {
        $operator = $node->getOperator();
        $left = $node->getLeft();
        $right = $node->getRight();

        switch ($operator) {
            case '+':
                $leftValue = $left->accept($this);
                $rightValue = $this->parenthesize($right, $node);

                return "$leftValue+$rightValue";

            case '-':
                if ($right) {
                    // Binary minus

                    $leftValue = $left->accept($this);
                    $rightValue = $this->parenthesize($right, $node);

                    return "$leftValue-$rightValue";
                } else {
                    // Unary minus

                    $leftValue = $this->parenthesize($left, $node);

                    return "-$leftValue";
                }

            case '*':
            case '/':

                $leftValue = $this->parenthesize($left, $node, '', false);
                $rightValue = $this->parenthesize($right, $node, '', true);

                return "$leftValue$operator$rightValue";

            case '^':
                $leftValue = $this->parenthesize($left, $node, '', true);
                $rightValue = $this->parenthesize($right, $node, '', false);

                return "$leftValue$operator$rightValue";
        }
    }
public function visitExpressionNode ( ExpressionNode $ node ) { $ operator = $ node -> getOperator ( ) ; $ left = $ node -> getLeft ( ) ; $ right = $ node -> getRight ( ) ; switch ( $ operator ) { case '+' : $ leftValue = $ left -> accept ( $ this ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node ) ; return "$leftValue+$rightValue" ; case '-' : if ( $ right ) { // Binary minus $ leftValue = $ left -> accept ( $ this ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node ) ; return "$leftValue-$rightValue" ; } else { // Unary minus $ leftValue = $ this -> parenthesize ( $ left , $ node ) ; return "-$leftValue" ; } case '*' : case '/' : $ leftValue = $ this -> parenthesize ( $ left , $ node , '' , false ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node , '' , true ) ; return "$leftValue$operator$rightValue" ; case '^' : $ leftValue = $ this -> parenthesize ( $ left , $ node , '' , true ) ; $ rightValue = $ this -> parenthesize ( $ right , $ node , '' , false ) ; return "$leftValue$operator$rightValue" ; } }
Generate ASCII output code for an ExpressionNode

Create a string giving ASCII output representing an ExpressionNode `(x op y)`
where `op` is one of `+`, `-`, `*`, `/` or `^`


@retval string
@param ExpressionNode $node AST to be typeset
Generate ASCII output code for an ExpressionNode