diff --git a/debug/ast.json b/debug/ast.json index edc4ef0..315ee80 100644 --- a/debug/ast.json +++ b/debug/ast.json @@ -14,29 +14,29 @@ "type": "BlockStatement", "statements": [ { - "type": "AssignmentStatement", - "name": { - "type": "IdentifierLiteral", - "value": "a" + "type": "ForStatement", + "var_declaration": { + "type": "AssignmentStatement", + "name": { + "type": "IdentifierLiteral", + "value": "x" + }, + "value": { + "type": "IntegerLiteral", + "value": 1 + }, + "value_type": "Int" }, - "value": { - "type": "IntegerLiteral", - "value": 0 - }, - "value_type": "Int" - }, - { - "type": "WhileStatement", "condition": { "type": "InfixExpression", "left_node": { "type": "IdentifierLiteral", - "value": "a" + "value": "x" }, - "operator": "<", + "operator": "<=", "right_node": { "type": "IntegerLiteral", - "value": 10 + "value": 20 } }, "body": { @@ -53,33 +53,14 @@ "arguments": [ { "type": "StringLiteral", - "value": "a = %i\\n" + "value": "i = %i\\n" }, { "type": "IdentifierLiteral", - "value": "a" + "value": "x" } ] } - }, - { - "type": "ReassignStatement", - "ident": { - "type": "IdentifierLiteral", - "value": "a" - }, - "right_value": { - "type": "InfixExpression", - "left_node": { - "type": "IdentifierLiteral", - "value": "a" - }, - "operator": "+", - "right_node": { - "type": "IntegerLiteral", - "value": 1 - } - } } ] } @@ -88,7 +69,7 @@ "type": "ReturnStatement", "return_value": { "type": "IdentifierLiteral", - "value": "a" + "value": "x" } } ] diff --git a/main.py b/main.py index b287b44..aaec4f1 100644 --- a/main.py +++ b/main.py @@ -10,9 +10,9 @@ import llvmlite.binding as llvm from ctypes import CFUNCTYPE, c_int, c_float LEXER_DEBUG: bool = False -PARSER_DEBUG: bool = True +PARSER_DEBUG: bool = False COMPILER_DEBUG: bool = False -RUN_CODE: bool = False +RUN_CODE: bool = True if __name__ == "__main__": diff --git a/plasma_parser.py b/plasma_parser.py index 5eca5c8..a5cad8c 100644 --- a/plasma_parser.py +++ b/plasma_parser.py @@ -202,6 +202,7 @@ class Parser: assign_stmt.ident = stmt.name assign_stmt.right_value = self.__parse_expression(PrecedenceType.P_LOWEST) + while not self.__current_token_is(TokenType.SEMICOLON) and not self.__current_token_is(TokenType.EOF): self.__next_token() @@ -355,7 +356,7 @@ class Parser: stmt.action = self.__parse_assignment_statement() - print(stmt.action.json()) + self.__next_token() @@ -376,6 +377,7 @@ class Parser: left_expr: Expression = prefix_func() while not self.__peek_token_is(TokenType.SEMICOLON) and precedence.value < self.__peek_precedence().value: + infix_func: Callable | None = self.infix_parse_functions.get(self.peek_token.type) if infix_func is None: return left_expr diff --git a/tests/test.pla b/tests/test.pla index e71bd54..7ad864a 100644 --- a/tests/test.pla +++ b/tests/test.pla @@ -1,6 +1,6 @@ main = Func(): Int { - for (x: Int = 1; x <= 20; x = x + 1) { - print("i = %i\n", x) + for (x: Int = 1; x <= 20; x = x + 1;) { + $print("i = %i\n", x) } return x;