本文整理汇总了Python中Interpreter.Interpreter.interpret方法的典型用法代码示例。如果您正苦于以下问题:Python Interpreter.interpret方法的具体用法?Python Interpreter.interpret怎么用?Python Interpreter.interpret使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Interpreter.Interpreter
的用法示例。
在下文中一共展示了Interpreter.interpret方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from Interpreter import Interpreter [as 别名]
# 或者: from Interpreter.Interpreter import interpret [as 别名]
class InterpreterVisitor:
def __init__(self, environment):
self.environment = environment
self.interpreter = Interpreter()
def visitNode(self, ast):
self.interpreter.interpret(ast, self.environment)
if ast._next is not None:
ast._next.int_visit(self)
示例2: main
# 需要导入模块: from Interpreter import Interpreter [as 别名]
# 或者: from Interpreter.Interpreter import interpret [as 别名]
def main():
# parse arguments
arg_parser = argparse.ArgumentParser(
description="Compiler for the functional programming language zlang"
)
arg_parser.add_argument('files', nargs="+", help="input files")
arg_parser.add_argument('-n', '--native', help="Prints abstract syntax tree")
args = arg_parser.parse_args()
# interpreter
interpreter = Interpreter()
# load native
if args.native:
interpreter.loadNative(args.native)
# load modules
for file in args.files:
interpreter.loadModule(file)
interpreter.interpret()
示例3: Output
# 需要导入模块: from Interpreter import Interpreter [as 别名]
# 或者: from Interpreter.Interpreter import interpret [as 别名]
output = Output()
factory = AstFactory(output)
parser = Parser(token_array, output, factory)
#print 'parse start'
parser.parse()
#print 'parse success'
if parser.get_error_message() != '':
print parser.get_error_message()
exit()
symbol_table = factory.get_symbol_table()
ast_root = factory.get_ast_root()
#print 'interpret start'
if symbol_table and ast_root:
interpreter = Interpreter(symbol_table, ast_root)
interpreter.interpret()
#if the argument is -x, it will run the improved code generator
elif sys.argv[1] == '-x':
input_string = ''
new_line = ''
#if the second argument doesn't exist.
if len(sys.argv) == 2:
while new_line != 'stop\n':
try:
input_string += new_line
new_line = raw_input() + '\n'
except (EOFError, KeyboardInterrupt):
break
#print input_string
示例4: main
# 需要导入模块: from Interpreter import Interpreter [as 别名]
# 或者: from Interpreter.Interpreter import interpret [as 别名]
def main():
interpreter = Interpreter("1 * 7 * 4")
result = interpreter.interpret();
print(result)
print(result == 28)