blob: 4888b73125b14268ac22e7a0ea86847629882efa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
<?php
namespace exTpl;
/**
* ArithExpression represents an arithmetic operator.
*/
class ArithExpression extends BinaryExpression
{
/**
* Returns the value of this expression.
*
* @param Context $context symbol table
*/
public function value(Context $context): mixed
{
$left = $this->left->value($context);
$right = $this->right->value($context);
return match ($this->operator) {
'+' => $left + $right,
'-' => $left - $right,
'*' => $left * $right,
'/' => $left / $right,
'%' => $left % $right,
'~' => $left . $right,
};
}
}
|