From 707e22029d8bcfc93918eaca27905d14e376d3b5 Mon Sep 17 00:00:00 2001 From: Clément Lafont Date: Mon, 13 Jan 2020 18:09:18 +0100 Subject: Left bracket and minus fix (#55) * Left bracket and minus fix (#54) * Add test for left bracket and minus fix #55 --- src/NXP/Classes/Token/TokenMinus.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/NXP/Classes/Token/TokenMinus.php b/src/NXP/Classes/Token/TokenMinus.php index d8ac079..b4b04e3 100644 --- a/src/NXP/Classes/Token/TokenMinus.php +++ b/src/NXP/Classes/Token/TokenMinus.php @@ -53,8 +53,12 @@ class TokenMinus extends AbstractOperator $op2 = array_pop($stack); $op1 = array_pop($stack); - if ($op1 === null || $op2 === null) { - throw new IncorrectExpressionException("Subtraction requires two operators"); + if ($op2 === null) { + throw new IncorrectExpressionException("Subtraction requires right operator"); + } + + if (!$op1) { + $op1 = new TokenNumber(0); } $result = $op1->getValue() - $op2->getValue(); -- cgit v1.2.3