Add call stack to RuntimeException based errors
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
from smnp.ast.parser import parse
|
||||
from smnp.environment.factory import createEnvironment
|
||||
from smnp.error.runtime import RuntimeException
|
||||
from smnp.program.FileReader import readLines
|
||||
from smnp.runtime.evaluator import evaluate
|
||||
from smnp.token.tokenizer import tokenize
|
||||
@@ -9,18 +10,22 @@ class Interpreter:
|
||||
|
||||
@staticmethod
|
||||
def interpretFile(file, printTokens=False, printAst=False):
|
||||
lines = readLines(file)
|
||||
|
||||
tokens = tokenize(lines)
|
||||
if printTokens:
|
||||
print(tokens)
|
||||
|
||||
ast = parse(tokens)
|
||||
if printAst:
|
||||
ast.print()
|
||||
|
||||
environment = createEnvironment()
|
||||
|
||||
evaluate(ast, environment)
|
||||
try:
|
||||
lines = readLines(file)
|
||||
|
||||
return environment
|
||||
tokens = tokenize(lines)
|
||||
if printTokens:
|
||||
print(tokens)
|
||||
|
||||
ast = parse(tokens)
|
||||
if printAst:
|
||||
ast.print()
|
||||
|
||||
evaluate(ast, environment)
|
||||
|
||||
return environment
|
||||
except RuntimeException as e:
|
||||
e.environment = environment
|
||||
raise e
|
||||
Reference in New Issue
Block a user