本文整理汇总了Python中interpreter.Interpreter.load方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.load方法的具体用法?Python Interpreter.load怎么用?Python Interpreter.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.load方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import load [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()
示例2: main
# 需要导入模块: from interpreter import Interpreter [as 别名]
# 或者: from interpreter.Interpreter import load [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)