50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
from Interpreter.Repo import Repo
|
|
from Interpreter.Utils import Utils
|
|
from Models.Interpreter.Error import Error
|
|
from Models.Interpreter.Token import Token
|
|
from Models.Nodes.Class import Class
|
|
from Models.Nodes.Func import Func
|
|
from Models.Nodes.Lib import Lib
|
|
|
|
|
|
class Parser:
|
|
|
|
def __init__(self, repo: Repo, utils: Utils) -> None:
|
|
self.__repo = repo
|
|
self.__utils = utils
|
|
|
|
self.__ast = []
|
|
|
|
def parse(self, toks: list) -> []:
|
|
self.__tokens = toks
|
|
self.__ast = []
|
|
# 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:
|
|
print(a_funcs.name, a_funcs.return_type, a_funcs.access)
|
|
|
|
print('___')
|
|
# print(self.__repo.ast, '\n')
|
|
|
|
return self.__ast
|
|
|
|
def __check(self) -> None:
|
|
for i in range(0, len(self.__tokens)):
|
|
tok = self.__tokens[i]
|
|
# print(tok.value, tok.type)
|