Пример #1
0
 function it_passes_output_from_the_tokeniser_to_the_parser(Tokeniser $tokeniser, Parser $parser, Evaluator $evaluator)
 {
     $input = '(+ 1 2)';
     $inputAsTokens = array('(', '+', '1', '2', ')');
     $parserOutput = array('+', '1', 2);
     $tokeniser->parse($input)->shouldBeCalled();
     $tokeniser->parse($input)->willReturn($inputAsTokens);
     $parser->parse($inputAsTokens)->shouldBeCalled()->willReturn($parserOutput);
     $evaluator->evaluate($parserOutput)->shouldBeCalled();
     $evaluator->setPhilInterpreter(Argument::type("\\Pogotc\\Phil\\Phil"))->shouldBeCalled();
     $this->run($input);
 }
Пример #2
0
 /**
  * @param $ast
  */
 private function evaluateFunction($ast)
 {
     if ($ast[0] == 'fn') {
         $functionName = $this->generateAnonymousFunctionName();
         $functionArgs = $ast[1];
         $functionBody = $ast[2];
     } else {
         $functionName = $ast[1];
         $functionArgs = $ast[2];
         $functionBody = $ast[3];
     }
     $this->scope[$functionName] = function () use($functionArgs, $functionBody) {
         $args = func_get_args();
         $localScope = $this->scope->getArrayCopy();
         foreach ($functionArgs as $idx => $namedArg) {
             $localScope[$namedArg] = $args[$idx];
         }
         $funcEvaluator = new Evaluator($localScope);
         return $funcEvaluator->evaluate($functionBody);
     };
     return $this->scope[$functionName];
 }