当前位置: 首页>>代码示例>>PHP>>正文


PHP Program::evaluate方法代码示例

本文整理汇总了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'));
 }
开发者ID:igorw,项目名称:ilias,代码行数:15,代码来源:ProgramTest.php

示例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)
{
开发者ID:igorw,项目名称:ilias,代码行数:30,代码来源:macro-expand.php


注:本文中的Program::evaluate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。