from typing import Optional 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 from Models.AbstractSyntaxTree.AbstractSyntaxTree import AbstractSyntaxTree 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_str: str) -> None: """ Interprets code line :param line_str: :return: """ tokens = [] ast: Optional[AbstractSyntaxTree] = None if self.__repo.error is None: tokens = self.__lexer.tokenize(line_str) if self.__repo.error is None: ast = self.__parser.parse(tokens) """ print('#####\n') if ast is not None: for lib in ast.libraries: print('lib', lib.name) for cl in lib.classes: print('class', cl.name) for var in cl.variables: print('cl var', var.name) for func in cl.functions: print('func', func.name) for arg in func.args: print('func arg', arg.name) for var in func.variables: print('func var', var.name) for ins in func.instructions: print('ins', ins) """ # if self.__repo.is_error is None: # self.__validator.validate(self.__repo.AST)