FOR STATEMENTS WORK!!!!!
This commit is contained in:
@@ -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"
|
||||
}
|
||||
}
|
||||
]
|
||||
|
||||
4
main.py
4
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__":
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user