cclang/src/Interpreter/Interpreter.py

59 lines
1.8 KiB
Python
Raw Normal View History

from typing import Optional
from Interpreter.Validator import Validator
from Interpreter.Lexer import Lexer
2020-09-23 06:48:38 +02:00
# from Interpreter.Parser_Old import Parser
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)
2020-09-17 19:33:52 +02:00
def interpret(self, line_str: str) -> None:
"""
Interprets code line
:param line_str:
:return:
"""
tokens = []
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:
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:
# self.__validator.validate(self.__repo.AST)