aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/Token/TokenGreaterThan.php
diff options
context:
space:
mode:
authorfranksl <info@streamlake.com>2019-11-26 17:00:24 +0300
committerBruce Wells <brucekwells@gmail.com>2019-11-26 17:00:24 +0300
commit29c5b5006ccb5cb308b9467ca25813b29be8cfc6 (patch)
tree88cafa1f3fe84e1db662470851a68947973cadda /src/NXP/Classes/Token/TokenGreaterThan.php
parentb8456057af1bcaad362ccb5ef55e8c696dd63e11 (diff)
Logicandcompare (#50)
* TokenFactory: allowing multicharacter tokens * Added logical and compare operators: <, <=, >, >=, ==, !=, ||, && * Fixed operator priorities * Error messages fixes * Fixed operators priority The priorities are assigned by following the php language standard (https://www.php.net/manual/en/language.operators.precedence.php) I've assigned precedence in steps of 10 units by following the linked page: 230 clone new 220 ** 210 ++ -- ~ (int) (float) (string) (array) (object) (bool) @ 200 instanceof 190 ! 180 * / % 170 + - . 160 << >> 150 < <= > >= 140 == != === !== <> <=> 130 & 120 ^ 110 | 100 && 90 || 80 ?? 70 ? : 60 = += -= *= **= /= .= %= &= |= ^= <<= >>= 50 yield from 40 yield 30 and 20 xor 10 or * Added if() function * Cache key fix There are cases where the cache key creation raised an error, for example while evaluating the expression "if(cos(2), cos(2), 0)", because the if() function was passing a float to the MathExecutor:execute() method.
Diffstat (limited to 'src/NXP/Classes/Token/TokenGreaterThan.php')
-rw-r--r--src/NXP/Classes/Token/TokenGreaterThan.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/NXP/Classes/Token/TokenGreaterThan.php b/src/NXP/Classes/Token/TokenGreaterThan.php
new file mode 100644
index 0000000..51a5aca
--- /dev/null
+++ b/src/NXP/Classes/Token/TokenGreaterThan.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace NXP\Classes\Token;
+
+use NXP\Exception\IncorrectExpressionException;
+
+class TokenGreaterThan extends AbstractOperator
+{
+ /**
+ * @return string
+ */
+ public static function getRegex()
+ {
+ return '>';
+ }
+
+ /**
+ * @return int
+ */
+ public function getPriority()
+ {
+ return 150;
+ }
+
+ /**
+ * @return string
+ */
+ public function getAssociation()
+ {
+ return self::LEFT_ASSOC;
+ }
+
+ /**
+ * @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("> requires two operators");
+ }
+
+ $result = $op1->getValue() > $op2->getValue();
+
+ return new TokenNumber($result);
+ }
+}