"""The interpreter""" from .parser import parse from .tokenize import tokenize class ParseError(Exception): pass def callIMP(chars): """ The entry point for everyone who wants to call IMP from within Python. The function either returns the value or None, if the call did not succeed. chars -- the string to evaluate returns -- the IMP environment | None """ if not chars: return None tokens = tokenize(chars) if not tokens: raise ParseError("tokens could not be generated") parsed = parse(tokens) if not parsed or not parsed.value: raise ParseError("tokens could not be parsed") ast = parsed.value env = {} ast.eval(env) return env