File modules/dsl/ast/DslOperation.class.php

Last commit: Tue Jul 19 00:10:00 2022 +0200	Jan Dankert	New: Scripting language: Ignore Keyword "new"; Support for Calling object constructors; Splitting objects into an instance and a wrapper.
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 }
Download modules/dsl/ast/DslOperation.class.php
History Tue, 19 Jul 2022 00:10:00 +0200 Jan Dankert New: Scripting language: Ignore Keyword "new"; Support for Calling object constructors; Splitting objects into an instance and a wrapper. Fri, 1 Jul 2022 18:09:05 +0200 Jan Dankert New: Bugfixes and much more string and array functions for the DSL. Sun, 26 Jun 2022 15:46:54 +0200 Jan Dankert Fix: Another, little better, hack for parameterless functions. Shunting yard seems to be unable to handle empty parentheses. Sat, 25 Jun 2022 14:26:33 +0200 Jan Dankert New: Many Enhancements for the internal script language: More access to the data structure of pages, folders, templates, ... Sun, 29 May 2022 16:56:40 +0200 Jan Dankert New: DSL with support for functions with return values, full arithmetic, object properties Sun, 29 May 2022 01:13:27 +0200 Jan Dankert New: DSL with support for functions