BinaryNode example

class BinaryNodeTest extends AbstractNodeTestCase
{
    use ExpectDeprecationTrait;

    public static function getEvaluateData(): array
    {
        $array = new ArrayNode();
        $array->addElement(new ConstantNode('a'));
        $array->addElement(new ConstantNode('b'));

        return [
            [true, new BinaryNode('or', new ConstantNode(true)new ConstantNode(false))],
            [true, new BinaryNode('||', new ConstantNode(true)new ConstantNode(false))],
            [false, new BinaryNode('and', new ConstantNode(true)new ConstantNode(false))],
            [false, new BinaryNode('&&', new ConstantNode(true)new ConstantNode(false))],

            [0, new BinaryNode('&', new ConstantNode(2)new ConstantNode(4))],
            [6, new BinaryNode('|', new ConstantNode(2)new ConstantNode(4))],
            [6, new BinaryNode('^', new ConstantNode(2)new ConstantNode(4))],

            [true, new BinaryNode('<', new ConstantNode(1)new ConstantNode(2))],
            [true, new BinaryNode('<=', new ConstantNode(1)new ConstantNode(2))],
            [true, new BinaryNode('<=', new ConstantNode(1)new ConstantNode(1))],

            [

    public function parseExpression(int $precedence = 0)
    {
        $expr = $this->getPrimary();
        $token = $this->stream->current;
        while ($token->test(Token::OPERATOR_TYPE) && isset($this->binaryOperators[$token->value]) && $this->binaryOperators[$token->value]['precedence'] >= $precedence) {
            $op = $this->binaryOperators[$token->value];
            $this->stream->next();

            $expr1 = $this->parseExpression(self::OPERATOR_LEFT === $op['associativity'] ? $op['precedence'] + 1 : $op['precedence']);
            $expr = new Node\BinaryNode($token->value, $expr$expr1);

            $token = $this->stream->current;
        }

        if (0 === $precedence) {
            return $this->parseConditionalExpression($expr);
        }

        return $expr;
    }

    
'true',
            ],
            [
                new Node\ConstantNode(null),
                'null',
            ],
            [
                new Node\UnaryNode('-', new Node\ConstantNode(3)),
                '-3',
            ],
            [
                new Node\BinaryNode('-', new Node\ConstantNode(3)new Node\ConstantNode(3)),
                '3 - 3',
            ],
            [
                new Node\BinaryNode('*',
                    new Node\BinaryNode('-', new Node\ConstantNode(3)new Node\ConstantNode(3)),
                    new Node\ConstantNode(2)
                ),
                '(3 - 3) * 2',
            ],
            [
                new Node\GetAttrNode(new Node\NameNode('foo')new Node\ConstantNode('bar', true)new Node\ArgumentsNode(), Node\GetAttrNode::PROPERTY_CALL),
                
Home | Imprint | This part of the site doesn't use cookies.