Пример #1
0
 protected function doInterpret(IContext $ctx, $l, $r)
 {
     if ($r == 0) {
         throw new DivisionByZero('Деление на 0');
     }
     $ctx->set($this, $l / $r);
 }
Пример #2
0
 function interpret(IContext $ctx)
 {
     $foo = $ctx->getFunction($this->name) ?: (isset(self::$list[$this->name]) ? self::$list[$this->name] : null);
     if (!$foo) {
         throw new FunctionNotFoundException("Function {$this->name} not found");
     }
     $values = array_map(function ($e) use($ctx) {
         $e->interpret($ctx);
         return $ctx->get($e);
     }, $this->arguments);
     $ctx->set($this, call_user_func_array($foo, $values));
 }
Пример #3
0
 public function testFunc()
 {
     $fl = new I\FL('twice(3.14)');
     $this->assertEquals($fl->evaluate(), '6.28');
     $fl = new I\FL('PI()');
     $this->assertEquals($fl->evaluate(), pi());
     $fl = new I\FL('sum(cos(0), 2, 3, twice(2), 5)');
     $this->assertEquals($fl->evaluate(), '15');
     $fl = new I\FL('sum(cos(0), 2, 3, twice(2), 5)');
     $ctx = new I\IContext();
     $ctx->regFunction('sum', function () {
         return implode('', func_get_args());
     });
     $this->assertEquals($fl->evaluate($ctx), '12345');
 }
Пример #4
0
 protected function doInterpret(IContext $ctx, $l, $r)
 {
     $ctx->set($this, pow($l, $r));
 }
Пример #5
0
 function interpret(IContext $context)
 {
     $context->set($this, $this->value);
 }