| @@ 23-63 (lines=41) @@ | ||
| 20 | * |
|
| 21 | * @author Sebastian Siemssen <[email protected]> |
|
| 22 | */ |
|
| 23 | class DivisionToken extends BaseToken implements OperatorTokenInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public static function getRegexPattern() |
|
| 29 | { |
|
| 30 | return '\/'; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | public function getPrecedence() |
|
| 37 | { |
|
| 38 | return 1; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * {@inheritdoc} |
|
| 43 | */ |
|
| 44 | public function getAssociativity() |
|
| 45 | { |
|
| 46 | return OperatorTokenInterface::ASSOCIATIVITY_LEFT; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * {@inheritdoc} |
|
| 51 | */ |
|
| 52 | public function execute(&$stack) |
|
| 53 | { |
|
| 54 | $a = array_pop($stack); |
|
| 55 | $b = array_pop($stack); |
|
| 56 | ||
| 57 | $result = (new BigNumber($b->getValue())) |
|
| 58 | ->divide($a->getValue()) |
|
| 59 | ->getValue(); |
|
| 60 | ||
| 61 | return new NumberToken($b->getOffset(), $result); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| @@ 23-63 (lines=41) @@ | ||
| 20 | * |
|
| 21 | * @author Sebastian Siemssen <[email protected]> |
|
| 22 | */ |
|
| 23 | class MinusToken extends BaseToken implements OperatorTokenInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public static function getRegexPattern() |
|
| 29 | { |
|
| 30 | return '\-'; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | public function getPrecedence() |
|
| 37 | { |
|
| 38 | return 0; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * {@inheritdoc} |
|
| 43 | */ |
|
| 44 | public function getAssociativity() |
|
| 45 | { |
|
| 46 | return OperatorTokenInterface::ASSOCIATIVITY_LEFT; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * {@inheritdoc} |
|
| 51 | */ |
|
| 52 | public function execute(&$stack) |
|
| 53 | { |
|
| 54 | $a = array_pop($stack); |
|
| 55 | $b = array_pop($stack); |
|
| 56 | ||
| 57 | $result = (new BigNumber($b->getValue())) |
|
| 58 | ->subtract($a->getValue()) |
|
| 59 | ->getValue(); |
|
| 60 | ||
| 61 | return new NumberToken($b->getOffset(), $result); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| @@ 23-64 (lines=42) @@ | ||
| 20 | * |
|
| 21 | * @author Sebastian Siemssen <[email protected]> |
|
| 22 | */ |
|
| 23 | class ModulusToken extends BaseToken implements OperatorTokenInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public static function getRegexPattern() |
|
| 29 | { |
|
| 30 | return '\%'; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | public function getPrecedence() |
|
| 37 | { |
|
| 38 | return 1; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * {@inheritdoc} |
|
| 43 | */ |
|
| 44 | public function getAssociativity() |
|
| 45 | { |
|
| 46 | return OperatorTokenInterface::ASSOCIATIVITY_LEFT; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * {@inheritdoc} |
|
| 51 | */ |
|
| 52 | public function execute(&$stack) |
|
| 53 | { |
|
| 54 | $a = array_pop($stack); |
|
| 55 | $b = array_pop($stack); |
|
| 56 | ||
| 57 | $result = (new BigNumber($b->getValue())) |
|
| 58 | ->mod($a->getValue()) |
|
| 59 | ->getValue(); |
|
| 60 | ; |
|
| 61 | return new NumberToken($b->getOffset(), $result); |
|
| 62 | } |
|
| 63 | ||
| 64 | } |
|
| 65 | ||
| @@ 23-63 (lines=41) @@ | ||
| 20 | * |
|
| 21 | * @author Sebastian Siemssen <[email protected]> |
|
| 22 | */ |
|
| 23 | class MultiplyToken extends BaseToken implements OperatorTokenInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public static function getRegexPattern() |
|
| 29 | { |
|
| 30 | return '\*'; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | public function getPrecedence() |
|
| 37 | { |
|
| 38 | return 1; |
|
| 39 | } |
|
| 40 | ||
| 41 | /** |
|
| 42 | * {@inheritdoc} |
|
| 43 | */ |
|
| 44 | public function getAssociativity() |
|
| 45 | { |
|
| 46 | return OperatorTokenInterface::ASSOCIATIVITY_LEFT; |
|
| 47 | } |
|
| 48 | ||
| 49 | /** |
|
| 50 | * {@inheritdoc} |
|
| 51 | */ |
|
| 52 | public function execute(&$stack) |
|
| 53 | { |
|
| 54 | $a = array_pop($stack); |
|
| 55 | $b = array_pop($stack); |
|
| 56 | ||
| 57 | $result = (new BigNumber($b->getValue())) |
|
| 58 | ->multiply($a->getValue()) |
|
| 59 | ->getValue(); |
|
| 60 | ||
| 61 | return new NumberToken($b->getOffset(), $result); |
|
| 62 | } |
|
| 63 | } |
|
| 64 | ||
| @@ 23-60 (lines=38) @@ | ||
| 20 | * |
|
| 21 | * @author Sebastian Siemssen <[email protected]> |
|
| 22 | */ |
|
| 23 | class PlusToken extends BaseToken implements OperatorTokenInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public static function getRegexPattern() |
|
| 29 | { |
|
| 30 | return '\+'; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | public function getPrecedence() { |
|
| 37 | return 0; |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * {@inheritdoc} |
|
| 42 | */ |
|
| 43 | public function getAssociativity() { |
|
| 44 | return OperatorTokenInterface::ASSOCIATIVITY_LEFT; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public function execute(&$stack) { |
|
| 51 | $a = array_pop($stack); |
|
| 52 | $b = array_pop($stack); |
|
| 53 | ||
| 54 | $result = (new BigNumber($b->getValue())) |
|
| 55 | ->add($a->getValue()) |
|
| 56 | ->getValue(); |
|
| 57 | ||
| 58 | return new NumberToken($b->getOffset(), $result); |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||
| @@ 23-60 (lines=38) @@ | ||
| 20 | * |
|
| 21 | * @author Sebastian Siemssen <[email protected]> |
|
| 22 | */ |
|
| 23 | class PowerToken extends BaseToken implements OperatorTokenInterface |
|
| 24 | { |
|
| 25 | /** |
|
| 26 | * {@inheritdoc} |
|
| 27 | */ |
|
| 28 | public static function getRegexPattern() |
|
| 29 | { |
|
| 30 | return '\^'; |
|
| 31 | } |
|
| 32 | ||
| 33 | /** |
|
| 34 | * {@inheritdoc} |
|
| 35 | */ |
|
| 36 | public function getPrecedence() { |
|
| 37 | return 3; |
|
| 38 | } |
|
| 39 | ||
| 40 | /** |
|
| 41 | * {@inheritdoc} |
|
| 42 | */ |
|
| 43 | public function getAssociativity() { |
|
| 44 | return OperatorTokenInterface::ASSOCIATIVITY_RIGHT; |
|
| 45 | } |
|
| 46 | ||
| 47 | /** |
|
| 48 | * {@inheritdoc} |
|
| 49 | */ |
|
| 50 | public function execute(&$stack) { |
|
| 51 | $a = array_pop($stack); |
|
| 52 | $b = array_pop($stack); |
|
| 53 | ||
| 54 | $result = (new BigNumber($b->getValue())) |
|
| 55 | ->pow($a->getValue()) |
|
| 56 | ->getValue(); |
|
| 57 | ||
| 58 | return new NumberToken($b->getOffset(), $result); |
|
| 59 | } |
|
| 60 | } |
|
| 61 | ||