2020-05-22 22:08:37 +02:00
|
|
|
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)
|
|
|
|
|
2020-05-25 20:32:46 +02:00
|
|
|
def interpret(self, line_int: int, line_str: str) -> bool:
|
2020-05-22 22:08:37 +02:00
|
|
|
toks = []
|
2020-05-25 20:32:46 +02:00
|
|
|
|
|
|
|
self.__utils.line_number = line_int
|
2020-05-22 22:08:37 +02:00
|
|
|
if self.__repo.error is None:
|
2020-05-25 20:32:46 +02:00
|
|
|
toks = self.__lexer.tokenize(line_str)
|
2020-05-22 22:08:37 +02:00
|
|
|
|
2020-05-25 21:05:52 +02:00
|
|
|
self.__repo.output_tokens(toks)
|
|
|
|
|
2020-05-22 22:08:37 +02:00
|
|
|
if self.__repo.error is None:
|
|
|
|
self.__parser.parse(toks)
|
|
|
|
|
2020-05-25 21:05:52 +02:00
|
|
|
self.__repo.output_ast()
|
|
|
|
|
2020-05-22 22:08:37 +02:00
|
|
|
if self.__repo.error is None:
|
|
|
|
self.__validator.validate()
|
|
|
|
|
|
|
|
return self.__repo.error is None
|