Ejemplo n.º 1
0
 /**
  * @param string $source
  * @param string $input
  * @param int    $fetchMode
  *
  * @return array|string
  */
 public function run($source, $input = "", $fetchMode = Output::FETCH_ARRAY)
 {
     $this->parser->loadSource($source);
     if ($this->parser->getFlag("string_output") === true) {
         $fetchMode = Output::FETCH_STRING;
     }
     $appLoop = $this->parser->parse($this->optimize);
     $appInput = $this->parser->getInput();
     if (!empty($appInput)) {
         $input = $appInput;
     }
     $this->vm->init($input);
     $appLoop->execute($this->vm);
     return $this->vm->getOutput()->fetch($fetchMode);
 }
Ejemplo n.º 2
0
 public function testParser_mutableOperations_optimized()
 {
     $parser = new Parser("+++++>>++++>>++<<<<-----");
     $operations = $parser->parse();
     $this->assertInstanceOf("Brainfart\\Operations\\LoopOperation", $operations);
     $this->assertTrue($operations->getMaster());
     $operations = $operations->getOperations();
     $expected = array(new ChangeOperation(5), new MoveOperation(2), new ChangeOperation(4), new MoveOperation(2), new ChangeOperation(2), new MoveOperation(-4), new ChangeOperation(-5));
     foreach ($expected as $key => $value) {
         $class = get_class($value);
         $op = $operations[$key];
         $this->assertInstanceOf($class, $op);
         /** @noinspection PhpUndefinedMethodInspection */
         $this->assertEquals($value->getValue(), $op->getValue());
     }
 }