File dsl/ast/DslOperation.class.php
Last commit: Tue Jul 19 00:10:39 2022 +0200 Jan Dankert Fetched from upstream.
1 <?php 2 3 namespace dsl\ast; 4 5 use dsl\DslParserException; 6 use dsl\DslRuntimeException; 7 use dsl\DslToken; 8 use dsl\standard\NumberInstance; 9 use dsl\standard\ArrayInstance; 10 use dsl\standard\StringInstance; 11 12 class DslOperation implements DslStatement 13 { 14 private $operator; 15 private $left; 16 private $right; 17 18 /** 19 * DslOperation constructor. 20 * @param $operator 21 * @param $left 22 * @param $right 23 */ 24 public function __construct($operator, $left, $right) 25 { 26 $this->operator = $operator; 27 $this->left = new DslExpression( $left ); 28 $this->right = new DslExpression( $right ); 29 } 30 31 32 /** 33 * @throws DslRuntimeException 34 */ 35 public function execute(& $context ) { 36 37 $left = $this->left->execute( $context ); 38 $right = $this->right->execute( $context ); 39 40 switch( $this->operator ) { 41 case '+': 42 if ( is_string($left) ) 43 return $left . (string)$right; 44 if ($left instanceof ArrayInstance) 45 return $left->concat( $right ); 46 if ($left instanceof StringInstance) 47 return $left->__toString() . (string)$right; 48 if ($left instanceof NumberInstance) 49 return $left->toNumber() + intval($right); 50 else 51 return intval($left) + intval($right); 52 53 case '-': 54 return intval($left) - intval($right); 55 56 case '*': 57 return $left * $right; 58 59 case '/': 60 return $left / $right; 61 62 case '==': 63 return $left == $right; 64 case '!=': 65 return $left != $right; 66 case '<': 67 return $left < $right; 68 case '<=': 69 return $left <= $right; 70 case '>': 71 return $left > $right; 72 case '>=': 73 return $left >= $right; 74 75 case '||': 76 return $left || $right; 77 case '&&': 78 return $left && $right; 79 80 case '%': 81 return $left % $right; 82 83 case '!': 84 return ! $left; 85 86 default: 87 throw new DslRuntimeException('Unknown operator \''.$this->operator.'\''); 88 } 89 90 } 91 92 93 public function parse($tokens) 94 { 95 } 96 }
Downloaddsl/ast/DslOperation.class.php
History Tue, 19 Jul 2022 00:10:39 +0200 Jan Dankert Fetched from upstream. Sun, 26 Jun 2022 15:47:05 +0200 Jan Dankert Fetched from upstream. Sun, 26 Jun 2022 11:45:51 +0200 Jan Dankert Fetched from upstream. Mon, 6 Jun 2022 14:06:46 +0200 Jan Dankert First commit after fetching from upstream repo.