aboutsummaryrefslogtreecommitdiff
path: root/src/NXP/Classes/Token
diff options
context:
space:
mode:
Diffstat (limited to 'src/NXP/Classes/Token')
-rw-r--r--src/NXP/Classes/Token/TokenAnd.php53
-rw-r--r--src/NXP/Classes/Token/TokenDegree.php2
-rw-r--r--src/NXP/Classes/Token/TokenDivision.php2
-rw-r--r--src/NXP/Classes/Token/TokenEqual.php53
-rw-r--r--src/NXP/Classes/Token/TokenGreaterThan.php53
-rw-r--r--src/NXP/Classes/Token/TokenGreaterThanOrEqual.php53
-rw-r--r--src/NXP/Classes/Token/TokenLessThan.php53
-rw-r--r--src/NXP/Classes/Token/TokenLessThanOrEqual.php53
-rw-r--r--src/NXP/Classes/Token/TokenMinus.php2
-rw-r--r--src/NXP/Classes/Token/TokenMultiply.php2
-rw-r--r--src/NXP/Classes/Token/TokenOr.php53
-rw-r--r--src/NXP/Classes/Token/TokenPlus.php2
-rw-r--r--src/NXP/Classes/Token/TokenUnequal.php53
13 files changed, 429 insertions, 5 deletions
diff --git a/src/NXP/Classes/Token/TokenAnd.php b/src/NXP/Classes/Token/TokenAnd.php
new file mode 100644
index 0000000..dab4497
--- /dev/null
+++ b/src/NXP/Classes/Token/TokenAnd.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace NXP\Classes\Token;
+
+use NXP\Exception\IncorrectExpressionException;
+
+class TokenAnd extends AbstractOperator
+{
+ /**
+ * @return string
+ */
+ public static function getRegex()
+ {
+ return '&&';
+ }
+
+ /**
+ * @return int
+ */
+ public function getPriority()
+ {
+ return 100;
+ }
+
+ /**
+ * @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);
+ }
+}
diff --git a/src/NXP/Classes/Token/TokenDegree.php b/src/NXP/Classes/Token/TokenDegree.php
index 273183a..0d22f91 100644
--- a/src/NXP/Classes/Token/TokenDegree.php
+++ b/src/NXP/Classes/Token/TokenDegree.php
@@ -30,7 +30,7 @@ class TokenDegree extends AbstractOperator
*/
public function getPriority()
{
- return 3;
+ return 220;
}
/**
diff --git a/src/NXP/Classes/Token/TokenDivision.php b/src/NXP/Classes/Token/TokenDivision.php
index 4a8f8ce..328833b 100644
--- a/src/NXP/Classes/Token/TokenDivision.php
+++ b/src/NXP/Classes/Token/TokenDivision.php
@@ -31,7 +31,7 @@ class TokenDivision extends AbstractOperator
*/
public function getPriority()
{
- return 2;
+ return 180;
}
/**
diff --git a/src/NXP/Classes/Token/TokenEqual.php b/src/NXP/Classes/Token/TokenEqual.php
new file mode 100644
index 0000000..b0ac31e
--- /dev/null
+++ b/src/NXP/Classes/Token/TokenEqual.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace NXP\Classes\Token;
+
+use NXP\Exception\IncorrectExpressionException;
+
+class TokenEqual extends AbstractOperator
+{
+ /**
+ * @return string
+ */
+ public static function getRegex()
+ {
+ return '\=\=';
+ }
+
+ /**
+ * @return int
+ */
+ public function getPriority()
+ {
+ return 140;
+ }
+
+ /**
+ * @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);
+ }
+}
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);
+ }
+}
diff --git a/src/NXP/Classes/Token/TokenGreaterThanOrEqual.php b/src/NXP/Classes/Token/TokenGreaterThanOrEqual.php
new file mode 100644
index 0000000..aa4425f
--- /dev/null
+++ b/src/NXP/Classes/Token/TokenGreaterThanOrEqual.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace NXP\Classes\Token;
+
+use NXP\Exception\IncorrectExpressionException;
+
+class TokenGreaterThanOrEqual 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);
+ }
+}
diff --git a/src/NXP/Classes/Token/TokenLessThan.php b/src/NXP/Classes/Token/TokenLessThan.php
new file mode 100644
index 0000000..d289028
--- /dev/null
+++ b/src/NXP/Classes/Token/TokenLessThan.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace NXP\Classes\Token;
+
+use NXP\Exception\IncorrectExpressionException;
+
+class TokenLessThan 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);
+ }
+}
diff --git a/src/NXP/Classes/Token/TokenLessThanOrEqual.php b/src/NXP/Classes/Token/TokenLessThanOrEqual.php
new file mode 100644
index 0000000..5a2fba3
--- /dev/null
+++ b/src/NXP/Classes/Token/TokenLessThanOrEqual.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace NXP\Classes\Token;
+
+use NXP\Exception\IncorrectExpressionException;
+
+class TokenLessThanOrEqual 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);
+ }
+}
diff --git a/src/NXP/Classes/Token/TokenMinus.php b/src/NXP/Classes/Token/TokenMinus.php
index ad0b8e5..d8ac079 100644
--- a/src/NXP/Classes/Token/TokenMinus.php
+++ b/src/NXP/Classes/Token/TokenMinus.php
@@ -30,7 +30,7 @@ class TokenMinus extends AbstractOperator
*/
public function getPriority()
{
- return 1;
+ return 170;
}
/**
diff --git a/src/NXP/Classes/Token/TokenMultiply.php b/src/NXP/Classes/Token/TokenMultiply.php
index 0b1ecfb..762fb48 100644
--- a/src/NXP/Classes/Token/TokenMultiply.php
+++ b/src/NXP/Classes/Token/TokenMultiply.php
@@ -30,7 +30,7 @@ class TokenMultiply extends AbstractOperator
*/
public function getPriority()
{
- return 2;
+ return 180;
}
/**
diff --git a/src/NXP/Classes/Token/TokenOr.php b/src/NXP/Classes/Token/TokenOr.php
new file mode 100644
index 0000000..86a4e53
--- /dev/null
+++ b/src/NXP/Classes/Token/TokenOr.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace NXP\Classes\Token;
+
+use NXP\Exception\IncorrectExpressionException;
+
+class TokenOr extends AbstractOperator
+{
+ /**
+ * @return string
+ */
+ public static function getRegex()
+ {
+ return '\|\|';
+ }
+
+ /**
+ * @return int
+ */
+ public function getPriority()
+ {
+ return 90;
+ }
+
+ /**
+ * @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);
+ }
+}
diff --git a/src/NXP/Classes/Token/TokenPlus.php b/src/NXP/Classes/Token/TokenPlus.php
index a6e5036..494f786 100644
--- a/src/NXP/Classes/Token/TokenPlus.php
+++ b/src/NXP/Classes/Token/TokenPlus.php
@@ -30,7 +30,7 @@ class TokenPlus extends AbstractOperator
*/
public function getPriority()
{
- return 1;
+ return 170;
}
/**
diff --git a/src/NXP/Classes/Token/TokenUnequal.php b/src/NXP/Classes/Token/TokenUnequal.php
new file mode 100644
index 0000000..c8c5d1a
--- /dev/null
+++ b/src/NXP/Classes/Token/TokenUnequal.php
@@ -0,0 +1,53 @@
+<?php
+
+namespace NXP\Classes\Token;
+
+use NXP\Exception\IncorrectExpressionException;
+
+class TokenUnequal extends AbstractOperator
+{
+ /**
+ * @return string
+ */
+ public static function getRegex()
+ {
+ return '\!\=';
+ }
+
+ /**
+ * @return int
+ */
+ public function getPriority()
+ {
+ return 140;
+ }
+
+ /**
+ * @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);
+ }
+}