Renamed to repeat

This commit is contained in:
Rafał Grodziński
2025-07-01 13:49:27 +09:00
parent 505eb7eca7
commit 729ffd0ea2
8 changed files with 53 additions and 53 deletions

View File

@@ -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> statement) {
case StatementKind::RETURN:
buildReturn(dynamic_pointer_cast<StatementReturn>(statement));
break;
case StatementKind::LOOP:
buildLoop(dynamic_pointer_cast<StatementLoop>(statement));
case StatementKind::REPEAT:
buildLoop(dynamic_pointer_cast<StatementRepeat>(statement));
break;
case StatementKind::META_EXTERN_FUNCTION:
buildMetaExternFunction(dynamic_pointer_cast<StatementMetaExternFunction>(statement));
@@ -138,7 +138,7 @@ void ModuleBuilder::buildReturn(shared_ptr<StatementReturn> statement) {
}
}
void ModuleBuilder::buildLoop(shared_ptr<StatementLoop> statement) {
void ModuleBuilder::buildLoop(shared_ptr<StatementRepeat> statement) {
shared_ptr<Statement> initStatement = statement->getInitStatement();
shared_ptr<StatementBlock> bodyStatement= statement->getBodyBlockStatement();
shared_ptr<Expression> preExpression = statement->getPreConditionExpression();

View File

@@ -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<StatementAssignment> statement);
void buildBlock(shared_ptr<StatementBlock> statement);
void buildReturn(shared_ptr<StatementReturn> statement);
void buildLoop(shared_ptr<StatementLoop> statement);
void buildLoop(shared_ptr<StatementRepeat> statement);
void buildMetaExternFunction(shared_ptr<StatementMetaExternFunction> statement);
void buildExpression(shared_ptr<StatementExpression> statement);

View File

@@ -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<shared_ptr<Token>> tokens): tokens(tokens) {
@@ -80,7 +80,7 @@ shared_ptr<Statement> Parser::nextInBlockStatement() {
if (statement != nullptr)
return statement;
statement = matchStatementLoop();
statement = matchStatementRepeat();
if (statement != nullptr)
return statement;
@@ -267,7 +267,7 @@ shared_ptr<Statement> Parser::matchStatementReturn() {
return make_shared<StatementReturn>(expression);
}
shared_ptr<Statement> Parser::matchStatementLoop() {
shared_ptr<Statement> Parser::matchStatementRepeat() {
if (!tryMatchingTokenKinds({TokenKind::REPEAT}, true, true))
return nullptr;
@@ -328,7 +328,7 @@ shared_ptr<Statement> Parser::matchStatementLoop() {
tryMatchingTokenKinds({TokenKind::SEMICOLON}, false, true);
return make_shared<StatementLoop>(initStatement, preConditionExpression, postConditionExpression, dynamic_pointer_cast<StatementBlock>(bodyBlockStatement));
return make_shared<StatementRepeat>(initStatement, preConditionExpression, postConditionExpression, dynamic_pointer_cast<StatementBlock>(bodyBlockStatement));
}
shared_ptr<Statement> Parser::matchStatementExpression() {

View File

@@ -28,7 +28,7 @@ private:
shared_ptr<Statement> matchStatementBlock(vector<TokenKind> terminalTokenKinds);
shared_ptr<Statement> matchStatementAssignment();
shared_ptr<Statement> matchStatementReturn();
shared_ptr<Statement> matchStatementLoop();
shared_ptr<Statement> matchStatementRepeat();
shared_ptr<Statement> matchStatementExpression();
shared_ptr<StatementInvalid> matchStatementInvalid(string message = "");

View File

@@ -14,7 +14,7 @@ enum class StatementKind {
FUNCTION,
VARIABLE,
ASSIGNMENT,
LOOP,
REPEAT,
META_EXTERN_FUNCTION,
INVALID
};

View File

@@ -1,39 +0,0 @@
#include "StatementLoop.h"
#include "Parser/Expression/Expression.h"
#include "Parser/Statement/StatementBlock.h"
StatementLoop::StatementLoop(shared_ptr<Statement> initStatement, shared_ptr<Expression> preConditionExpression, shared_ptr<Expression> postConditionExpression, shared_ptr<StatementBlock> bodyBlockStatement):
Statement(StatementKind::LOOP), initStatement(initStatement), preConditionExpression(preConditionExpression), postConditionExpression(postConditionExpression), bodyBlockStatement(bodyBlockStatement) { }
shared_ptr<Statement> StatementLoop::getInitStatement() {
return initStatement;
}
shared_ptr<Expression> StatementLoop::getPreConditionExpression() {
return preConditionExpression;
}
shared_ptr<Expression> StatementLoop::getPostConditionExpression() {
return postConditionExpression;
}
shared_ptr<StatementBlock> StatementLoop::getBodyBlockStatement() {
return bodyBlockStatement;
}
string StatementLoop::toString(int indent) {
string value;
for (int ind=0; ind<indent; ind++)
value += " ";
value += "REP(";
if (initStatement != nullptr)
value += initStatement->toString(0), ", ";
if (preConditionExpression != nullptr)
value += preConditionExpression->toString(0) + ", ";
if (postConditionExpression != nullptr)
value += postConditionExpression->toString(0);
value += "):\n";
value += bodyBlockStatement->toString(indent+1);
return value;
}

View File

@@ -0,0 +1,39 @@
#include "StatementRepeat.h"
#include "Parser/Expression/Expression.h"
#include "Parser/Statement/StatementBlock.h"
StatementRepeat::StatementRepeat(shared_ptr<Statement> initStatement, shared_ptr<Expression> preConditionExpression, shared_ptr<Expression> postConditionExpression, shared_ptr<StatementBlock> bodyBlockStatement):
Statement(StatementKind::REPEAT), initStatement(initStatement), preConditionExpression(preConditionExpression), postConditionExpression(postConditionExpression), bodyBlockStatement(bodyBlockStatement) { }
shared_ptr<Statement> StatementRepeat::getInitStatement() {
return initStatement;
}
shared_ptr<Expression> StatementRepeat::getPreConditionExpression() {
return preConditionExpression;
}
shared_ptr<Expression> StatementRepeat::getPostConditionExpression() {
return postConditionExpression;
}
shared_ptr<StatementBlock> StatementRepeat::getBodyBlockStatement() {
return bodyBlockStatement;
}
string StatementRepeat::toString(int indent) {
string value;
for (int ind=0; ind<indent; ind++)
value += " ";
value += "REP(";
if (initStatement != nullptr)
value += initStatement->toString(0), ", ";
if (preConditionExpression != nullptr)
value += preConditionExpression->toString(0) + ", ";
if (postConditionExpression != nullptr)
value += postConditionExpression->toString(0);
value += "):\n";
value += bodyBlockStatement->toString(indent+1);
return value;
}

View File

@@ -3,7 +3,7 @@
class Expression;
class StatementBlock;
class StatementLoop: public Statement {
class StatementRepeat: public Statement {
private:
shared_ptr<Statement> initStatement;
shared_ptr<Expression> preConditionExpression;
@@ -11,7 +11,7 @@ private:
shared_ptr<StatementBlock> bodyBlockStatement;
public:
StatementLoop(shared_ptr<Statement> initStatement, shared_ptr<Expression> preConditionExpression, shared_ptr<Expression> postConditionExpression, shared_ptr<StatementBlock> bodyBlockStatement);
StatementRepeat(shared_ptr<Statement> initStatement, shared_ptr<Expression> preConditionExpression, shared_ptr<Expression> postConditionExpression, shared_ptr<StatementBlock> bodyBlockStatement);
shared_ptr<Statement> getInitStatement();
shared_ptr<Expression> getPreConditionExpression();
shared_ptr<Expression> getPostConditionExpression();