2020-05-22 22:08:37 +02:00
|
|
|
from Interpreter.Repo import Repo
|
|
|
|
from Interpreter.Utils import Utils
|
2020-05-24 17:56:15 +02:00
|
|
|
from Models.Interpreter.Error import Error
|
2020-05-23 13:40:51 +02:00
|
|
|
from Models.Interpreter.Token import Token
|
2020-05-25 22:04:56 +02:00
|
|
|
from Models.Nodes.Class import Class
|
|
|
|
from Models.Nodes.Func import Func
|
|
|
|
from Models.Nodes.Lib import Lib
|
2020-05-22 22:08:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Parser:
|
|
|
|
|
|
|
|
def __init__(self, repo: Repo, utils: Utils) -> None:
|
|
|
|
self.__repo = repo
|
|
|
|
self.__utils = utils
|
|
|
|
|
2020-05-25 22:04:56 +02:00
|
|
|
self.__ast = []
|
2020-05-24 17:56:15 +02:00
|
|
|
|
2020-05-25 22:04:56 +02:00
|
|
|
def parse(self, toks: list) -> []:
|
2020-05-24 17:56:15 +02:00
|
|
|
self.__tokens = toks
|
2020-05-25 22:04:56 +02:00
|
|
|
self.__ast = []
|
2020-05-24 17:56:15 +02:00
|
|
|
# output
|
|
|
|
if len(toks) > 0:
|
|
|
|
tokens = []
|
|
|
|
for t in toks:
|
|
|
|
tokens.append({t.value: t.type})
|
|
|
|
|
|
|
|
# print(tokens)
|
|
|
|
|
|
|
|
self.__check()
|
|
|
|
|
|
|
|
# output
|
|
|
|
if len(self.__repo.ast) > 1:
|
|
|
|
print('___')
|
|
|
|
for a_lib in self.__repo.ast:
|
|
|
|
print(a_lib.name)
|
|
|
|
for a_class in a_lib.ast:
|
|
|
|
print(a_class.name, a_class.access)
|
|
|
|
for a_funcs in a_class.ast:
|
2020-05-25 16:36:44 +02:00
|
|
|
print(a_funcs.name, a_funcs.return_type, a_funcs.access)
|
2020-05-24 17:56:15 +02:00
|
|
|
|
|
|
|
print('___')
|
|
|
|
# print(self.__repo.ast, '\n')
|
|
|
|
|
2020-05-25 22:04:56 +02:00
|
|
|
return self.__ast
|
2020-05-25 20:32:46 +02:00
|
|
|
|
2020-05-25 22:04:56 +02:00
|
|
|
def __check(self) -> None:
|
|
|
|
for i in range(0, len(self.__tokens)):
|
|
|
|
tok = self.__tokens[i]
|
|
|
|
# print(tok.value, tok.type)
|