aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/Calculator.php
diff options
context:
space:
mode:
authorBruce Wells <phpfui@users.noreply.github.com>2018-09-12 21:21:25 +0300
committerGitHub <noreply@github.com>2018-09-12 21:21:25 +0300
commit12d41b160bbf8c26601819fcc1f7628c48bc7a00 (patch)
treec50b777d06d9e9eeff6aeb59005c389ddf9a552b /src/NXP/Classes/Calculator.php
parent855ca5dfc1a6d70d9872df4b0d7bea8ba3c4c040 (diff)
parent4a672cfd94c07e1821227f27fd1edd2217685136 (diff)
Merge pull request #1 from NeonXP/master
Merge from upstream master
Diffstat (limited to 'src/NXP/Classes/Calculator.php')
-rw-r--r--src/NXP/Classes/Calculator.php8
1 files changed, 6 insertions, 2 deletions
diff --git a/src/NXP/Classes/Calculator.php b/src/NXP/Classes/Calculator.php
index 41e0d9f..bfa7015 100644
--- a/src/NXP/Classes/Calculator.php
+++ b/src/NXP/Classes/Calculator.php
@@ -13,6 +13,7 @@ namespace NXP\Classes;
use NXP\Classes\Token\InterfaceOperator;
use NXP\Classes\Token\TokenFunction;
use NXP\Classes\Token\TokenNumber;
+use NXP\Classes\Token\TokenString;
use NXP\Classes\Token\TokenVariable;
use NXP\Exception\IncorrectExpressionException;
use NXP\Exception\UnknownVariableException;
@@ -32,15 +33,18 @@ class Calculator
*/
public function calculate($tokens, $variables)
{
- $stack = array();
+ $stack = [];
foreach ($tokens as $token) {
if ($token instanceof TokenNumber) {
array_push($stack, $token);
}
+ if ($token instanceof TokenString) {
+ array_push($stack, $token);
+ }
if ($token instanceof TokenVariable) {
$variable = $token->getValue();
if (!array_key_exists($variable, $variables)) {
- throw new UnknownVariableException();
+ throw new UnknownVariableException($variable);
}
$value = $variables[$variable];
array_push($stack, new TokenNumber($value));