Implemented interpreter, almost fully documented

This commit is contained in:
hellerve
2015-07-08 16:38:49 +02:00
parent a96a5fe1f7
commit 9d4406907a
6 changed files with 137 additions and 22 deletions

View File

@@ -1,2 +1,27 @@
def callIMP(chars):
"""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