diff options
Diffstat (limited to 'lib/exTpl/BooleanExpression.php')
| -rw-r--r-- | lib/exTpl/BooleanExpression.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/lib/exTpl/BooleanExpression.php b/lib/exTpl/BooleanExpression.php new file mode 100644 index 0000000..0e18df0 --- /dev/null +++ b/lib/exTpl/BooleanExpression.php @@ -0,0 +1,31 @@ +<?php + +namespace exTpl; + +/** + * BooleanExpression represents a boolean operator. + */ +class BooleanExpression extends BinaryExpression +{ + /** + * Returns the value of this expression. + * + * @param Context $context symbol table + */ + public function value(Context $context): bool + { + $left = $this->left->value($context); + $right = $this->right->value($context); + + return match ($this->operator) { + T_IS_EQUAL => $left == $right, + T_IS_NOT_EQUAL => $left != $right, + '<' => $left < $right, + T_IS_SMALLER_OR_EQUAL => $left <= $right, + '>' => $left > $right, + T_IS_GREATER_OR_EQUAL => $left >= $right, + T_BOOLEAN_AND => $left && $right, + T_BOOLEAN_OR => $left || $right, + }; + } +} |
