From 729ffd0ea21292f122f56cb81ce1c1cd7f59e090 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Grodzi=C5=84ski?= Date: Tue, 1 Jul 2025 13:49:27 +0900 Subject: [PATCH] Renamed to repeat --- src/Compiler/ModuleBuilder.cpp | 8 ++-- src/Compiler/ModuleBuilder.h | 4 +- src/Parser/Parser.cpp | 8 ++-- src/Parser/Parser.h | 2 +- src/Parser/Statement/Statement.h | 2 +- src/Parser/Statement/StatementLoop.cpp | 39 ------------------- src/Parser/Statement/StatementRepeat.cpp | 39 +++++++++++++++++++ .../{StatementLoop.h => StatementRepeat.h} | 4 +- 8 files changed, 53 insertions(+), 53 deletions(-) delete mode 100644 src/Parser/Statement/StatementLoop.cpp create mode 100644 src/Parser/Statement/StatementRepeat.cpp rename src/Parser/Statement/{StatementLoop.h => StatementRepeat.h} (68%) diff --git a/src/Compiler/ModuleBuilder.cpp b/src/Compiler/ModuleBuilder.cpp index 88becf4..28a4c00 100644 --- a/src/Compiler/ModuleBuilder.cpp +++ b/src/Compiler/ModuleBuilder.cpp @@ -13,7 +13,7 @@ #include "Parser/Statement/StatementAssignment.h" #include "Parser/Statement/StatementReturn.h" #include "Parser/Statement/StatementExpression.h" -#include "Parser/Statement/StatementLoop.h" +#include "Parser/Statement/StatementRepeat.h" #include "Parser/Statement/StatementMetaExternFunction.h" #include "Parser/Statement/StatementBlock.h" @@ -54,8 +54,8 @@ void ModuleBuilder::buildStatement(shared_ptr statement) { case StatementKind::RETURN: buildReturn(dynamic_pointer_cast(statement)); break; - case StatementKind::LOOP: - buildLoop(dynamic_pointer_cast(statement)); + case StatementKind::REPEAT: + buildLoop(dynamic_pointer_cast(statement)); break; case StatementKind::META_EXTERN_FUNCTION: buildMetaExternFunction(dynamic_pointer_cast(statement)); @@ -138,7 +138,7 @@ void ModuleBuilder::buildReturn(shared_ptr statement) { } } -void ModuleBuilder::buildLoop(shared_ptr statement) { +void ModuleBuilder::buildLoop(shared_ptr statement) { shared_ptr initStatement = statement->getInitStatement(); shared_ptr bodyStatement= statement->getBodyBlockStatement(); shared_ptr preExpression = statement->getPreConditionExpression(); diff --git a/src/Compiler/ModuleBuilder.h b/src/Compiler/ModuleBuilder.h index 2f7b4f8..1a91fdf 100644 --- a/src/Compiler/ModuleBuilder.h +++ b/src/Compiler/ModuleBuilder.h @@ -27,7 +27,7 @@ class StatementVariable; class StatementAssignment; class StatementReturn; class StatementExpression; -class StatementLoop; +class StatementRepeat; class StatementMetaExternFunction; class StatementBlock; @@ -57,7 +57,7 @@ private: void buildAssignment(shared_ptr statement); void buildBlock(shared_ptr statement); void buildReturn(shared_ptr statement); - void buildLoop(shared_ptr statement); + void buildLoop(shared_ptr statement); void buildMetaExternFunction(shared_ptr statement); void buildExpression(shared_ptr statement); diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp index e52d777..7a2ae0a 100644 --- a/src/Parser/Parser.cpp +++ b/src/Parser/Parser.cpp @@ -16,7 +16,7 @@ #include "Parser/Statement/StatementExpression.h" #include "Parser/Statement/StatementMetaExternFunction.h" #include "Parser/Statement/StatementBlock.h" -#include "Parser/Statement/StatementLoop.h" +#include "Parser/Statement/StatementRepeat.h" #include "Parser/Statement/StatementInvalid.h" Parser::Parser(vector> tokens): tokens(tokens) { @@ -80,7 +80,7 @@ shared_ptr Parser::nextInBlockStatement() { if (statement != nullptr) return statement; - statement = matchStatementLoop(); + statement = matchStatementRepeat(); if (statement != nullptr) return statement; @@ -267,7 +267,7 @@ shared_ptr Parser::matchStatementReturn() { return make_shared(expression); } -shared_ptr Parser::matchStatementLoop() { +shared_ptr Parser::matchStatementRepeat() { if (!tryMatchingTokenKinds({TokenKind::REPEAT}, true, true)) return nullptr; @@ -328,7 +328,7 @@ shared_ptr Parser::matchStatementLoop() { tryMatchingTokenKinds({TokenKind::SEMICOLON}, false, true); - return make_shared(initStatement, preConditionExpression, postConditionExpression, dynamic_pointer_cast(bodyBlockStatement)); + return make_shared(initStatement, preConditionExpression, postConditionExpression, dynamic_pointer_cast(bodyBlockStatement)); } shared_ptr Parser::matchStatementExpression() { diff --git a/src/Parser/Parser.h b/src/Parser/Parser.h index 761d722..6ff976f 100644 --- a/src/Parser/Parser.h +++ b/src/Parser/Parser.h @@ -28,7 +28,7 @@ private: shared_ptr matchStatementBlock(vector terminalTokenKinds); shared_ptr matchStatementAssignment(); shared_ptr matchStatementReturn(); - shared_ptr matchStatementLoop(); + shared_ptr matchStatementRepeat(); shared_ptr matchStatementExpression(); shared_ptr matchStatementInvalid(string message = ""); diff --git a/src/Parser/Statement/Statement.h b/src/Parser/Statement/Statement.h index a0b5aa6..4c6289d 100644 --- a/src/Parser/Statement/Statement.h +++ b/src/Parser/Statement/Statement.h @@ -14,7 +14,7 @@ enum class StatementKind { FUNCTION, VARIABLE, ASSIGNMENT, - LOOP, + REPEAT, META_EXTERN_FUNCTION, INVALID }; diff --git a/src/Parser/Statement/StatementLoop.cpp b/src/Parser/Statement/StatementLoop.cpp deleted file mode 100644 index e29eca2..0000000 --- a/src/Parser/Statement/StatementLoop.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#include "StatementLoop.h" - -#include "Parser/Expression/Expression.h" -#include "Parser/Statement/StatementBlock.h" - -StatementLoop::StatementLoop(shared_ptr initStatement, shared_ptr preConditionExpression, shared_ptr postConditionExpression, shared_ptr bodyBlockStatement): -Statement(StatementKind::LOOP), initStatement(initStatement), preConditionExpression(preConditionExpression), postConditionExpression(postConditionExpression), bodyBlockStatement(bodyBlockStatement) { } - -shared_ptr StatementLoop::getInitStatement() { - return initStatement; -} - -shared_ptr StatementLoop::getPreConditionExpression() { - return preConditionExpression; -} - -shared_ptr StatementLoop::getPostConditionExpression() { - return postConditionExpression; -} - -shared_ptr StatementLoop::getBodyBlockStatement() { - return bodyBlockStatement; -} - -string StatementLoop::toString(int indent) { - string value; - for (int ind=0; indtoString(0), ", "; - if (preConditionExpression != nullptr) - value += preConditionExpression->toString(0) + ", "; - if (postConditionExpression != nullptr) - value += postConditionExpression->toString(0); - value += "):\n"; - value += bodyBlockStatement->toString(indent+1); - return value; -} \ No newline at end of file diff --git a/src/Parser/Statement/StatementRepeat.cpp b/src/Parser/Statement/StatementRepeat.cpp new file mode 100644 index 0000000..6f52ed9 --- /dev/null +++ b/src/Parser/Statement/StatementRepeat.cpp @@ -0,0 +1,39 @@ +#include "StatementRepeat.h" + +#include "Parser/Expression/Expression.h" +#include "Parser/Statement/StatementBlock.h" + +StatementRepeat::StatementRepeat(shared_ptr initStatement, shared_ptr preConditionExpression, shared_ptr postConditionExpression, shared_ptr bodyBlockStatement): +Statement(StatementKind::REPEAT), initStatement(initStatement), preConditionExpression(preConditionExpression), postConditionExpression(postConditionExpression), bodyBlockStatement(bodyBlockStatement) { } + +shared_ptr StatementRepeat::getInitStatement() { + return initStatement; +} + +shared_ptr StatementRepeat::getPreConditionExpression() { + return preConditionExpression; +} + +shared_ptr StatementRepeat::getPostConditionExpression() { + return postConditionExpression; +} + +shared_ptr StatementRepeat::getBodyBlockStatement() { + return bodyBlockStatement; +} + +string StatementRepeat::toString(int indent) { + string value; + for (int ind=0; indtoString(0), ", "; + if (preConditionExpression != nullptr) + value += preConditionExpression->toString(0) + ", "; + if (postConditionExpression != nullptr) + value += postConditionExpression->toString(0); + value += "):\n"; + value += bodyBlockStatement->toString(indent+1); + return value; +} \ No newline at end of file diff --git a/src/Parser/Statement/StatementLoop.h b/src/Parser/Statement/StatementRepeat.h similarity index 68% rename from src/Parser/Statement/StatementLoop.h rename to src/Parser/Statement/StatementRepeat.h index 00cd47d..399a8c8 100644 --- a/src/Parser/Statement/StatementLoop.h +++ b/src/Parser/Statement/StatementRepeat.h @@ -3,7 +3,7 @@ class Expression; class StatementBlock; -class StatementLoop: public Statement { +class StatementRepeat: public Statement { private: shared_ptr initStatement; shared_ptr preConditionExpression; @@ -11,7 +11,7 @@ private: shared_ptr bodyBlockStatement; public: - StatementLoop(shared_ptr initStatement, shared_ptr preConditionExpression, shared_ptr postConditionExpression, shared_ptr bodyBlockStatement); + StatementRepeat(shared_ptr initStatement, shared_ptr preConditionExpression, shared_ptr postConditionExpression, shared_ptr bodyBlockStatement); shared_ptr getInitStatement(); shared_ptr getPreConditionExpression(); shared_ptr getPostConditionExpression();