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


Python Interpreter.environment方法代码示例

本文整理汇总了Python中freeode.interpreter.Interpreter.environment方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.environment方法的具体用法?Python Interpreter.environment怎么用?Python Interpreter.environment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在freeode.interpreter.Interpreter的用法示例。


在下文中一共展示了Interpreter.environment方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_expression_evaluation_5

# 需要导入模块: from freeode.interpreter import Interpreter [as 别名]
# 或者: from freeode.interpreter.Interpreter import environment [as 别名]
def test_expression_evaluation_5(): #IGNORE:C01111
    msg = \
    '''
    Test expression evaluation (returning of partially evaluated expression 
    when accessing variables)
    '''
    #skip_test(msg)
    print msg

    from freeode.ast import RoleVariable, NodeFuncCall
    from freeode.interpreter import (IModule, IFloat, ExecutionEnvironment, 
                                     Interpreter, istype)
    import freeode.simlparser as simlparser
    from freeode.util import func #, aa_make_tree
    
    #parse the expression
    ps = simlparser.Parser()
    ex = ps.parseExpressionStr('a + 2*2')
#    print
#    print 'AST (parser output): -----------------------------------------------------------'
#    print aa_make_tree(ex)
    
    #create module where name lives
    mod = IModule()
    #create attribute 'a' with no value
    val_2 = IFloat()
    val_2.__siml_role__ = RoleVariable
    mod.a = val_2
#    print
#    print 'Module where variable is located: --------------------------------------------'
#    print aa_make_tree(mod)
    
    #create environment for lookup of variables (stack frame)
    env = ExecutionEnvironment()
    env.global_scope = mod
    
    #interpret the expression
    intp = Interpreter()
    intp.environment = env
    res = intp.eval(ex)
#    print
#    print 'Result object - should be an unevaluated expression: --------------------------------------------------------------'
#    print aa_make_tree(res)
    assert isinstance(res, NodeFuncCall)
    assert res.function is func(IFloat.__add__)
    assert istype(res, IFloat)
开发者ID:eike-welk,项目名称:freeode,代码行数:48,代码来源:test_interpreter_1.py


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