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


Python Interpreter.execute方法代码示例

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


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

示例1: main

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import execute [as 别名]
def main():
    # Inputs for interpreter and generator
    grammar = {'[':_push_state, ']':_pop_state,
               'F':_forwards, 'L':_left, 'R':_right,
              }
    rules   = {'T':'F[LT][RT]'}
    data = 'T'
    generations = 5

    # Create a generator
    g = Generator(data, rules)
    data = g.nth_generation(generations)

    # Create and set up interpreter
    i = Interpreter(grammar)
    i.use_memory = True # Use the interpreter's memory, 
                        #  i.e. pass the interpreter as the 
                        # first argument to every callback in the grammar

    # Initialise a turtle
    t = turtle.Turtle()
    t.hideturtle()
    t.left(90)

    # Load required items into interpreter memory
    i.load('turtle', t) # Load in a turtle
    i.load('state', []) # Load in an empty list for turtle's state stack

    i.execute(data)
    
    turtle.exitonclick()
开发者ID:Sourceless,项目名称:lindenmayer,代码行数:33,代码来源:example_turtle.py

示例2: main

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import execute [as 别名]
def main():
    grammar = { '>':_inc_pointer,
                '<':_dec_pointer,
                '+':_inc_data,
                '-':_dec_data,
                '.':_output,
                ',':_input,
                '[':_if_zero_jump_forward,
                ']':_if_nonzero_jump_back
              }
    data =  '++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.' # 'Hello world'

    i = Interpreter(grammar)
    i.use_memory = True
    i.load('tape',[0])
    i.load('ptr',0)
    i.load('loop',0)
    i.execute(data)
开发者ID:Sourceless,项目名称:lindenmayer,代码行数:20,代码来源:example_brainfuck.py

示例3: __init__

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import execute [as 别名]

#.........这里部分代码省略.........
        else:
            return False
        return True

    def setTransferStage(self, transferHeader):
        """Set the transfer stage to process by the vm."""

        if "transfer" in transferHeader:
            self.transferStage = TRANSFER_STAGE.CHUNKER
            self.tokenizer = TransferWordTokenizer()
            # Set chunker mode, by default 'lu'.
            if "chunk" in transferHeader:
                self.chunkerMode = CHUNKER_MODE.CHUNK
            else:
                self.chunkerMode = CHUNKER_MODE.LU
        elif "interchunk" in transferHeader:
            self.transferStage = TRANSFER_STAGE.INTERCHUNK
            self.tokenizer = ChunkWordTokenizer()
        elif "postchunk" in transferHeader:
            self.transferStage = TRANSFER_STAGE.POSTCHUNK
            self.tokenizer = ChunkWordTokenizer(solveRefs=True, parseContent=True)

    def tokenizeInput(self):
        """Call to the tokenizer to divide the input in tokens."""

        self.words, self.superblanks = self.tokenizer.tokenize(self.input)

    def initializeVM(self):
        """Execute code to initialize the VM, e.g. default values for vars."""

        self.PC = 0
        self.status = VM_STATUS.RUNNING
        while self.status == VM_STATUS.RUNNING and self.PC < len(self.code):
            self.interpreter.execute(self.code[self.PC])

    def getSourceWord(self, pos):
        """Get the part of a source word needed for pattern matching, depending
           on the transfer stage."""

        if self.transferStage == TRANSFER_STAGE.CHUNKER:
            return self.words[pos].source.lu
        elif self.transferStage == TRANSFER_STAGE.INTERCHUNK:
            word = self.words[pos].chunk
            return word.attrs["lem"] + word.attrs["tags"]
        else:
            return self.words[pos].chunk.attrs["lem"]

    def getNextInputPattern(self):
        """Get the next input pattern to analyze, lowering the lemma first."""

        try:
            pattern = self.getSourceWord(self.nextPattern)
            tag = pattern.find("<")
            pattern = pattern[:tag].lower() + pattern[tag:]
            self.nextPattern += 1
        except IndexError:
            return None

        return pattern

    def getUniqueSuperblank(self, pos):
        """Get the superblank at pos avoiding duplicates."""

        try:
            if pos != self.lastSuperblank:
                self.lastSuperblank = pos
开发者ID:ggm,项目名称:vm-for-transfer,代码行数:70,代码来源:vm.py

示例4: BytecodeGenerator

# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import execute [as 别名]
            #     print 'x', node

            if not self.clean:
                self.bytecode.append(("POP_STACK", None))

        if self.main:
            self.bytecode.append(("END", None))

        return self.bytecode


to_bytecode = lambda xs: BytecodeGenerator()(xs)

if __name__ == "__main__":
    from pprint import pprint

    with open("example.js") as fobj:
        instructions = parse(fobj.read())

    bcg = BytecodeGenerator(True)

    bytecode = bcg(instructions)
    # pprint(bytecode)

    from interpreter import Interpreter

    ip = Interpreter()
    ip.execute(bytecode)

    # print 'locals', ip.namespace.locals
开发者ID:jaheba,项目名称:jyps,代码行数:32,代码来源:bc.py


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