| 1 |
<?php |
| 2 |
/** |
| 3 |
* This file is part of the Peast package |
| 4 |
* |
| 5 |
* (c) Marco Marchiò <[email protected]> |
| 6 |
* |
| 7 |
* For the full copyright and license information refer to the LICENSE file |
| 8 |
* distributed with this source code |
| 9 |
*/ |
| 10 |
namespace Peast\Syntax\Node; |
| 11 |
|
| 12 |
/** |
| 13 |
* A node that represents a binary expression. |
| 14 |
* For example: a + b |
| 15 |
* |
| 16 |
* @author Marco Marchiò <[email protected]> |
| 17 |
*/ |
| 18 |
class BinaryExpression extends Node implements Expression |
| 19 |
{ |
| 20 |
/** |
| 21 |
* Map of node properties |
| 22 |
* |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
protected $propertiesMap = array( |
| 26 |
"left" => true, |
| 27 |
"operator" => false, |
| 28 |
"right" => true |
| 29 |
); |
| 30 |
|
| 31 |
/** |
| 32 |
* Operator |
| 33 |
* |
| 34 |
* @var string |
| 35 |
*/ |
| 36 |
protected $operator; |
| 37 |
|
| 38 |
/** |
| 39 |
* Left expression |
| 40 |
* |
| 41 |
* @var Expression|PrivateIdentifier |
| 42 |
*/ |
| 43 |
protected $left; |
| 44 |
|
| 45 |
/** |
| 46 |
* Right expression |
| 47 |
* |
| 48 |
* @var Expression |
| 49 |
*/ |
| 50 |
protected $right; |
| 51 |
|
| 52 |
/** |
| 53 |
* Returns the operator |
| 54 |
* |
| 55 |
* @return string |
| 56 |
*/ |
| 57 |
public function getOperator() |
| 58 |
{ |
| 59 |
return $this->operator; |
| 60 |
} |
| 61 |
|
| 62 |
/** |
| 63 |
* Sets the operator |
| 64 |
* |
| 65 |
* @param string $operator Operator |
| 66 |
* |
| 67 |
* @return $this |
| 68 |
*/ |
| 69 |
public function setOperator($operator) |
| 70 |
{ |
| 71 |
$this->operator = $operator; |
| 72 |
return $this; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Returns the left expression |
| 77 |
* |
| 78 |
* @return Expression|PrivateIdentifier |
| 79 |
*/ |
| 80 |
public function getLeft() |
| 81 |
{ |
| 82 |
return $this->left; |
| 83 |
} |
| 84 |
|
| 85 |
/** |
| 86 |
* Sets the left expression |
| 87 |
* |
| 88 |
* @param Expression|PrivateIdentifier $left Left expression |
| 89 |
* |
| 90 |
* @return $this |
| 91 |
*/ |
| 92 |
public function setLeft($left) |
| 93 |
{ |
| 94 |
$this->assertType($left, array("Expression", "PrivateIdentifier")); |
| 95 |
$this->left = $left; |
| 96 |
return $this; |
| 97 |
} |
| 98 |
|
| 99 |
/** |
| 100 |
* Returns the right expression |
| 101 |
* |
| 102 |
* @return Expression |
| 103 |
*/ |
| 104 |
public function getRight() |
| 105 |
{ |
| 106 |
return $this->right; |
| 107 |
} |
| 108 |
|
| 109 |
/** |
| 110 |
* Sets the right expression |
| 111 |
* |
| 112 |
* @param Expression $right Right expression |
| 113 |
* |
| 114 |
* @return $this |
| 115 |
*/ |
| 116 |
public function setRight(Expression $right) |
| 117 |
{ |
| 118 |
$this->right = $right; |
| 119 |
return $this; |
| 120 |
} |
| 121 |
} |