diff options
author | Alexander Kiryukhin <alexander@kiryukhin.su> | 2018-09-06 20:39:47 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-06 20:39:47 +0300 |
commit | 3011a1c55686ef5a0c7759ae1efcb2a71623ab9c (patch) | |
tree | c192d6dd2948e83122893ab67228141b271c2d22 /src | |
parent | 29d32a155f9956d1041a4420c19986565f695040 (diff) | |
parent | 855ca5dfc1a6d70d9872df4b0d7bea8ba3c4c040 (diff) |
Merge branch 'master' into getters_for_function_and_operators
Diffstat (limited to 'src')
-rw-r--r-- | src/NXP/Classes/Lexer.php | 4 | ||||
-rw-r--r-- | src/NXP/Classes/Token/TokenDegree.php | 4 | ||||
-rw-r--r-- | src/NXP/Classes/Token/TokenDivision.php | 2 | ||||
-rw-r--r-- | src/NXP/MathExecutor.php | 4 |
4 files changed, 5 insertions, 9 deletions
diff --git a/src/NXP/Classes/Lexer.php b/src/NXP/Classes/Lexer.php index b66ea87..e541732 100644 --- a/src/NXP/Classes/Lexer.php +++ b/src/NXP/Classes/Lexer.php @@ -99,13 +99,13 @@ class Lexer while ( count($stack) > 0 && ($stack[count($stack)-1] instanceof InterfaceOperator) && - ( + (( $token->getAssociation() == AbstractOperator::LEFT_ASSOC && $token->getPriority() <= $stack[count($stack)-1]->getPriority() ) || ( $token->getAssociation() == AbstractOperator::RIGHT_ASSOC && $token->getPriority() < $stack[count($stack)-1]->getPriority() - ) + )) ) { $output[] = array_pop($stack); } diff --git a/src/NXP/Classes/Token/TokenDegree.php b/src/NXP/Classes/Token/TokenDegree.php index 8488dcd..c31b66e 100644 --- a/src/NXP/Classes/Token/TokenDegree.php +++ b/src/NXP/Classes/Token/TokenDegree.php @@ -41,13 +41,13 @@ class TokenDegree extends AbstractOperator /** * @param InterfaceToken[] $stack - * @return $this + * @return TokenNumber */ public function execute(&$stack) { $op2 = array_pop($stack); $op1 = array_pop($stack); - $result = $op1->getValue() ^ $op2->getValue(); + $result = $op1->getValue() ** $op2->getValue(); return new TokenNumber($result); } diff --git a/src/NXP/Classes/Token/TokenDivision.php b/src/NXP/Classes/Token/TokenDivision.php index 479a4ec..f1c35ff 100644 --- a/src/NXP/Classes/Token/TokenDivision.php +++ b/src/NXP/Classes/Token/TokenDivision.php @@ -47,7 +47,7 @@ class TokenDivision extends AbstractOperator { $op2 = array_pop($stack); $op1 = array_pop($stack); - $result = $op1->getValue() / $op2->getValue(); + $result = $op2->getValue() != 0 ? $op1->getValue() / $op2->getValue() : 0; return new TokenNumber($result); } diff --git a/src/NXP/MathExecutor.php b/src/NXP/MathExecutor.php index 0c3d185..9e7ce25 100644 --- a/src/NXP/MathExecutor.php +++ b/src/NXP/MathExecutor.php @@ -91,10 +91,6 @@ class MathExecutor */ public function setVar($variable, $value) { - if (!is_numeric($value)) { - throw new \Exception("Variable value must be a number"); - } - $this->variables[$variable] = $value; return $this; |