2020-09-23 19:38:14 +02:00
|
|
|
from typing import Optional
|
|
|
|
|
2020-05-22 22:08:37 +02:00
|
|
|
from Interpreter.Validator import Validator
|
|
|
|
from Interpreter.Lexer import Lexer
|
2020-09-23 06:48:38 +02:00
|
|
|
# from Interpreter.Parser_Old import Parser
|
2020-05-22 22:08:37 +02:00
|
|
|
from Interpreter.Parser import Parser
|
|
|
|
from Interpreter.Repo import Repo
|
|
|
|
from Interpreter.Utils import Utils
|
2020-09-23 19:38:14 +02:00
|
|
|
from Models.AbstractSyntaxTree.AbstractSyntaxTree import AbstractSyntaxTree
|
2020-05-22 22:08:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
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-09-17 19:33:52 +02:00
|
|
|
def interpret(self, line_str: str) -> None:
|
|
|
|
"""
|
|
|
|
Interprets code line
|
|
|
|
:param line_str:
|
|
|
|
:return:
|
|
|
|
"""
|
|
|
|
tokens = []
|
2020-09-23 19:38:14 +02:00
|
|
|
ast: Optional[AbstractSyntaxTree] = None
|
2020-09-17 19:33:52 +02:00
|
|
|
|
|
|
|
if self.__repo.is_error is None:
|
|
|
|
tokens = self.__lexer.tokenize(line_str)
|
|
|
|
|
|
|
|
if self.__repo.is_error is None:
|
2020-09-23 19:38:14 +02:00
|
|
|
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)
|
|
|
|
"""
|
2020-09-17 19:33:52 +02:00
|
|
|
|
|
|
|
# if self.__repo.is_error is None:
|
2020-09-23 19:38:14 +02:00
|
|
|
# self.__validator.validate(self.__repo.AST)
|