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)
def parse(self): self.parser = Parser() self.ast = self.parser.parse(self.code)