aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes
diff options
context:
space:
mode:
authorAlexander Kiryukhin <alexander@kiryukhin.su>2018-09-06 20:41:13 +0300
committerGitHub <noreply@github.com>2018-09-06 20:41:13 +0300
commit7b657db13f0b76432ca0039e45f4b8f5e09879c2 (patch)
tree954c50f2644212742442e0027efb081620d2a109 /src/NXP/Classes
parenta969571772a9761f67672b229741f209f5391560 (diff)
parentaa1a092a9e231e8f923ab40365dff092c2908903 (diff)
Merge branch 'master' into dev
Diffstat (limited to 'src/NXP/Classes')
-rw-r--r--src/NXP/Classes/Lexer.php4
-rw-r--r--src/NXP/Classes/Token/TokenDegree.php4
-rw-r--r--src/NXP/Classes/Token/TokenDivision.php2
-rw-r--r--src/NXP/Classes/TokenFactory.php22
4 files changed, 27 insertions, 5 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/Classes/TokenFactory.php b/src/NXP/Classes/TokenFactory.php
index 07b9ea8..85c4a62 100644
--- a/src/NXP/Classes/TokenFactory.php
+++ b/src/NXP/Classes/TokenFactory.php
@@ -51,6 +51,18 @@ class TokenFactory
$this->functions[$name] = array($places, $function);
}
+
+ /**
+ * get functions
+ *
+ * @return array containing callback and places indexed by
+ * function name
+ */
+ public function getFunctions()
+ {
+ return $this->functions;
+ }
+
/**
* Add operator
* @param string $operatorClass
@@ -69,6 +81,16 @@ class TokenFactory
}
/**
+ * Get registered operators
+ *
+ * @return array of operator class names
+ */
+ public function getOperators()
+ {
+ return $this->operators;
+ }
+
+ /**
* Add variable
* @param string $name
* @param mixed $value