本文整理汇总了PHP中Program::evaluate方法的典型用法代码示例。如果您正苦于以下问题:PHP Program::evaluate方法的具体用法?PHP Program::evaluate怎么用?PHP Program::evaluate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Program
的用法示例。
在下文中一共展示了Program::evaluate方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: evaluateShouldTokenizeAndParseCode
/** @test */
public function evaluateShouldTokenizeAndParseCode()
{
$lexer = $this->getMock('Igorw\\Ilias\\Lexer');
$lexer->expects($this->once())->method('tokenize')->with('2')->will($this->returnValue(['2']));
$reader = $this->getMock('Igorw\\Ilias\\Reader');
$reader->expects($this->once())->method('parse')->with(['2'])->will($this->returnValue([2]));
$builder = $this->getMock('Igorw\\Ilias\\FormTreeBuilder');
$builder->expects($this->once())->method('parseAst')->with([2])->will($this->returnValue([new Form\LiteralForm(2)]));
$walker = $this->getMock('Igorw\\Ilias\\Walker');
$walker->expects($this->once())->method('expand')->with($this->isInstanceOf('Igorw\\Ilias\\Environment'), $this->isInstanceOf('Igorw\\Ilias\\Form\\Form'))->will($this->returnArgument(1));
$env = $this->getMock('Igorw\\Ilias\\Environment');
$program = new Program($lexer, $reader, $builder, $walker);
$this->assertSame(2, $program->evaluate($env, '2'));
}
示例2: buildForms
// example call:
// php examples/macro-expand.php
// "(defmacro when (condition a b c) (list 'if condition (list 'begin a b c)))"
// "(when (> x 10) 1 2 3)"
namespace Igorw\Ilias;
require __DIR__ . '/../vendor/autoload.php';
if ($argc < 3) {
echo "Usage: php examples/macro-expand.php MACROS CODE\n";
exit(1);
}
list($_, $macros, $code) = $argv;
$program = new Program(new Lexer(), new Reader(), new FormTreeBuilder(), new Walker());
$env = Environment::standard();
$program->evaluate($env, $macros);
$expandedForms = expand($env, $code);
foreach ($expandedForms as $expanded) {
echo encode($expanded->getAst()) . "\n";
}
function buildForms($code)
{
$lexer = new Lexer();
$reader = new Reader();
$builder = new FormTreeBuilder();
$tokens = $lexer->tokenize($code);
$ast = $reader->parse($tokens);
return $builder->parseAst($ast);
}
function expand(Environment $env, $code)
{