示例#1
0
class Interpreter(object):
    def __init__(self, code):
        self.code = code
        self.context = ContextDictionary()
        self.context["print"] = PrintFunction()
        self.context["range"] = RangeFunction()

    def execute(self):
        self.parse()
        for node in self.ast:
            node.calculate(self.context)

    def parse(self):
        self.parser = Parser()
        self.ast = self.parser.parse(self.code)
示例#2
0
 def parse(self):
     self.parser = Parser()
     self.ast = self.parser.parse(self.code)