Enable importing other source files
This commit is contained in:
3
smnp/program/FileReader.py
Normal file
3
smnp/program/FileReader.py
Normal file
@@ -0,0 +1,3 @@
|
||||
def readLines(file):
|
||||
with open(file, 'r') as source:
|
||||
return [line.rstrip('\n') for line in source.readlines()]
|
||||
0
smnp/program/__init__.py
Normal file
0
smnp/program/__init__.py
Normal file
26
smnp/program/interpreter.py
Normal file
26
smnp/program/interpreter.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from smnp.ast.parser import parse
|
||||
from smnp.environment.factory import createEnvironment
|
||||
from smnp.program.FileReader import readLines
|
||||
from smnp.runtime.evaluator import evaluate
|
||||
from smnp.token.tokenizer import tokenize
|
||||
|
||||
|
||||
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)
|
||||
|
||||
return environment
|
||||
Reference in New Issue
Block a user