while loops work!

This commit is contained in:
SpookyDervish
2025-10-15 18:44:15 +11:00
parent 549f650b54
commit 9f6fff9977
7 changed files with 155 additions and 86 deletions

View File

@@ -1,48 +1,6 @@
{
"type": "Program",
"statements": [
{
"FunctionStatement": {
"type": "FunctionStatement",
"name": {
"type": "IdentifierLiteral",
"value": "add"
},
"return_type": "Int",
"parameters": [
{
"type": "FunctionParameter",
"name": "a",
"value_type": "Int"
},
{
"type": "FunctionParameter",
"name": "b",
"value_type": "Int"
}
],
"body": {
"type": "BlockStatement",
"statements": [
{
"type": "ReturnStatement",
"return_value": {
"type": "InfixExpression",
"left_node": {
"type": "IdentifierLiteral",
"value": "a"
},
"operator": "+",
"right_node": {
"type": "IdentifierLiteral",
"value": "b"
}
}
}
]
}
}
},
{
"FunctionStatement": {
"type": "FunctionStatement",
@@ -56,34 +14,72 @@
"type": "BlockStatement",
"statements": [
{
"type": "ExpressionStatement",
"expr": {
"type": "CallExpression",
"function": {
"type": "AssignmentStatement",
"name": {
"type": "IdentifierLiteral",
"value": "a"
},
"value": {
"type": "IntegerLiteral",
"value": 0
},
"value_type": "Int"
},
{
"type": "WhileStatement",
"condition": {
"type": "InfixExpression",
"left_node": {
"type": "IdentifierLiteral",
"value": "print"
"value": "a"
},
"arguments": [
"operator": "<",
"right_node": {
"type": "IntegerLiteral",
"value": 10
}
},
"body": {
"type": "BlockStatement",
"statements": [
{
"type": "StringLiteral",
"value": "apples %i"
"type": "ExpressionStatement",
"expr": {
"type": "CallExpression",
"function": {
"type": "IdentifierLiteral",
"value": "print"
},
"arguments": [
{
"type": "StringLiteral",
"value": "a = %i\\n"
},
{
"type": "IdentifierLiteral",
"value": "a"
}
]
}
},
{
"type": "CallExpression",
"function": {
"type": "ReassignStatement",
"ident": {
"type": "IdentifierLiteral",
"value": "add"
"value": "a"
},
"arguments": [
{
"right_value": {
"type": "InfixExpression",
"left_node": {
"type": "IdentifierLiteral",
"value": "a"
},
"operator": "+",
"right_node": {
"type": "IntegerLiteral",
"value": 1
},
{
"type": "IntegerLiteral",
"value": 2
}
]
}
}
]
}
@@ -91,8 +87,8 @@
{
"type": "ReturnStatement",
"return_value": {
"type": "IntegerLiteral",
"value": 0
"type": "IdentifierLiteral",
"value": "a"
}
}
]