cclang/src/Interpreter/Interpreter.py
2020-05-25 22:04:56 +02:00

36 lines
980 B
Python

from Interpreter.Validator import Validator
from Interpreter.Lexer import Lexer
from Interpreter.Parser import Parser
from Interpreter.Repo import Repo
from Interpreter.Utils import Utils
class Interpreter:
def __init__(self, repo: Repo, utils: Utils) -> None:
self.__repo = repo
self.__utils = utils
self.__lexer = Lexer(repo, utils)
self.__parser = Parser(repo, utils)
self.__validator = Validator(repo, utils)
def interpret(self, line_int: int, line_str: str) -> bool:
toks = []
ast = []
self.__utils.line_number = line_int
if self.__repo.error is None:
toks = self.__lexer.tokenize(line_str)
self.__repo.output_tokens(toks)
if self.__repo.error is None:
ast = self.__parser.parse(toks)
# self.__repo.output_ast(ast)
if self.__repo.error is None:
self.__validator.validate(ast)
return self.__repo.error is None