aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/Token/TokenPlus.php
diff options
context:
space:
mode:
Diffstat (limited to 'src/NXP/Classes/Token/TokenPlus.php')
-rw-r--r--src/NXP/Classes/Token/TokenPlus.php10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/NXP/Classes/Token/TokenPlus.php b/src/NXP/Classes/Token/TokenPlus.php
index f9562e7..fe5a1d6 100644
--- a/src/NXP/Classes/Token/TokenPlus.php
+++ b/src/NXP/Classes/Token/TokenPlus.php
@@ -10,6 +10,8 @@
namespace NXP\Classes\Token;
+use NXP\Exception\IncorrectExpressionException;
+
/**
* @author Alexander Kiryukhin <alexander@symdev.org>
*/
@@ -41,12 +43,20 @@ class TokenPlus extends AbstractOperator
/**
* @param InterfaceToken[] $stack
+ *
* @return $this
+ *
+ * @throws \NXP\Exception\IncorrectExpressionException
*/
public function execute(&$stack)
{
$op2 = array_pop($stack);
$op1 = array_pop($stack);
+
+ if ($op1 === null || $op2 === null) {
+ throw new IncorrectExpressionException("Addition requires two operators");
+ }
+
$result = $op1->getValue() + $op2->getValue();
return new TokenNumber($result);