def test_apply_9():
    code = '''
        [set a 1]
        [set b 2]
        [+ a c]
        '''
    ensure(apply(code) == 3, 'test apply 8')
Beispiel #2
0
    def load_module(self, script):
        src = open(script).read()
        parser = MemeParser(src)
        try:
            ast,_ = parser.apply("start")
        except Exception as err:
            print(err.formatError(''.join(parser.input.data)))
            sys.exit(1)

        print "---- AST ----"
        print ast
        print "//---- AST ----"
        self.current_module = _create_compiled_module({"filepath": script,
                                                       "ast": ast,
                                                       "parent_module":"memetalk/kernel",
                                                       "@tag":"a compiled module"})

        self.env_id_table = []
        self.env_idx = 0
        self.functions = []
        self.fun_literals = []

        self.loading_class = False

        loader = Loader([ast])
        loader.i = self
        loader.apply("load_module")
        return self.current_module
def test_apply_8():
    code8 = '''
        [set a 1]
        [set b 2]
        [+ a b]
        '''
    ensure(apply(code8) == 3, 'test apply 8')
def test_apply_6():
    code6 = """
        [if true
            [log "成功"]
            [log "没成功"]
        ]
    """
    # log('code6', tokenizer(code6))
    ensure(apply(code6) is None, 'test apply 6')
def statement_wrapper():
    doper = {'+': add, '-': red, '*': mul, '/': div, '^': power}
    states = raw_input(">>")
    result = pr.apply(states, darg=doper)
    if (result == None):
        print("<< Undefined")
    else:
        full = "<< ", str(result)
        print(full)
    return
def test_apply_7():
    code7 = """
        [function [add a b]
            [if [> a b]
                [- a b]
                [+ a b]
            ]
        ]
        [add 1 3]
    """
    ensure(apply(code7) == 4, 'test apply 7')
def test_apply_1():
    code1 = "[+ 1 2]         ; 表达式的值是 3"
    # log('code1', tokenizer(code1))
    ensure(apply(code1) == 3, 'test apply 1')
def test_apply_5():
    code5 = '[if [> 2 1] 3 4]; 表达式的值是 3'
    # log('code5', tokenizer(code5))
    ensure(apply(code5) == 3, 'test apply 5')
def test_apply_4():
    code4 = '[+ 1 [- 2 3]]   ; 表达式的值是 0, 相当于普通语法的 1 + (2 - 3)'
    # log('code4', tokenizer(code4))
    ensure(apply(code4) == 0, 'test apply 4')
def test_apply_3():
    code3 = '[log "hello"]   ; 输出 hello, 表达式的值是 null(关键字 表示空)'
    # log('code3', tokenizer(code3))
    ensure(apply(code3) is None, 'test apply 3')
def test_apply_2():
    code2 = "[* 2 3 4]       ; 表达式的值是 24"
    # log('code2', tokenizer(code2))
    ensure(apply(code2) == 24, 'test apply 2')