From 9b25f36eb35c7bcb47ab5641e100b7a3a6d0f282 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 25 May 2020 21:05:52 +0200 Subject: [PATCH] fixes --- doc/test.bl | 10 +++++----- src/Interpreter/Interpreter.py | 4 ++++ src/Interpreter/Lexer.py | 1 - src/Interpreter/Parser.py | 10 ++++++++++ src/Interpreter/Repo.py | 10 ++++++++++ src/Main.py | 4 +++- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/doc/test.bl b/doc/test.bl index c217c03..bfa3c4f 100644 --- a/doc/test.bl +++ b/doc/test.bl @@ -13,8 +13,8 @@ lib Main { var testEmpty: emptyType = empty; var testNum: number = 3.0; var testBool_2: bool = 3 > 1; - var testTest: Test = Test(); - testTest.outp(); + # var testTest: Test = Test(); + # testTest.outp(); output('Hello World'); output(66); output(3 + 3); @@ -28,9 +28,9 @@ lib Main { test1234(range(0, 10)); } - # public func test1234(param: list): list { - public func test1234(): void - { + public func test1234(param: list): list { + # public func test1234(): void + # { /*for i in range(0, length(param)) { output(i); }*/ diff --git a/src/Interpreter/Interpreter.py b/src/Interpreter/Interpreter.py index bfc7525..eec1d60 100644 --- a/src/Interpreter/Interpreter.py +++ b/src/Interpreter/Interpreter.py @@ -21,9 +21,13 @@ class Interpreter: if self.__repo.error is None: toks = self.__lexer.tokenize(line_str) + self.__repo.output_tokens(toks) + if self.__repo.error is None: self.__parser.parse(toks) + self.__repo.output_ast() + if self.__repo.error is None: self.__validator.validate() diff --git a/src/Interpreter/Lexer.py b/src/Interpreter/Lexer.py index 4592a89..51c28ef 100644 --- a/src/Interpreter/Lexer.py +++ b/src/Interpreter/Lexer.py @@ -134,5 +134,4 @@ class Lexer: if line[i - 1] == '*' and c == '/': self.__ml_comment = False - # self.__repo.output_tokens(self.__toks) return self.__toks diff --git a/src/Interpreter/Parser.py b/src/Interpreter/Parser.py index ef16ca4..4995d2b 100644 --- a/src/Interpreter/Parser.py +++ b/src/Interpreter/Parser.py @@ -74,6 +74,16 @@ class Parser: else: return Token('EOL', 'EOL') + def __add_ast(self, tok: Token) -> None: + if self.__lib is not None and self.__class is None and self.__func is None: + self.__lib.ast.append(tok) + + elif self.__lib is not None and self.__class is not None and self.__func is None: + self.__class.ast.append(tok) + + elif self.__lib is not None and self.__class is not None and self.__func is not None: + self.__func.ast.append(tok) + def __is_scope_started(self) -> bool: return self.__is_start_lib or self.__is_start_class or self.__is_start_func diff --git a/src/Interpreter/Repo.py b/src/Interpreter/Repo.py index 4fabc7b..4d1b921 100644 --- a/src/Interpreter/Repo.py +++ b/src/Interpreter/Repo.py @@ -58,3 +58,13 @@ class Repo: print(outp_toks) # print('\n') + + def output_ast(self) -> None: + if len(self.ast) > 0: + outp_toks = [] + for tok in self.ast: + outp_toks.append({tok.value: tok.type}) + # print({tok.value: tok.type}) + + print(outp_toks) + # print('\n') diff --git a/src/Main.py b/src/Main.py index 3338739..a43d8f9 100644 --- a/src/Main.py +++ b/src/Main.py @@ -15,9 +15,11 @@ class Main: def console(self) -> None: print('sh-edraft.de basic language interpreter:') + i = 0 cont = True while cont: - cont = self.__interpreter.interpret(input('> ')) + cont = self.__interpreter.interpret(i+1, input('> ')) + i += 1 def files(self, file: str) -> None: if os.path.isfile(file):