Skip to content

Commit

Permalink
If statement (work in progress)
Browse files Browse the repository at this point in the history
  • Loading branch information
IO32NQ committed May 1, 2024
1 parent c74e23b commit 1d07042
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/examples/if_test.dpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
x = 2

if x == 2:
print("if worked")
else:
print("Else worked")
30 changes: 28 additions & 2 deletions src/Evaluator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ void Evaluator::visit(const std::shared_ptr<ColumnNode> &node) {}

void Evaluator::visit(const std::shared_ptr<DivExprNode> &node) {}

void Evaluator::visit(const std::shared_ptr<ElseNode> &node) {}
void Evaluator::visit(const std::shared_ptr<ElseNode> &node) {
std::vector<std::shared_ptr<AstNode>> elseBodyNodes = node->getChildNodeList();

for (size_t i = 0; i < elseBodyNodes.size(); ++i) {
elseBodyNodes[i]->accept(shared_from_this());
}

}

void Evaluator::visit(const std::shared_ptr<EqualExprNode> &node) {}

Expand All @@ -38,7 +45,26 @@ void Evaluator::visit(const std::shared_ptr<GreaterExprNode> &node) {}

void Evaluator::visit(const std::shared_ptr<HeaderIndexNode> &node) {}

void Evaluator::visit(const std::shared_ptr<IfNode> &node) {}
void Evaluator::visit(const std::shared_ptr<IfNode> &node) {
std::shared_ptr<AstNode> condNode = node->getCondNode();
std::vector<std::shared_ptr<AstNode>> bodyNodes = node->getBodyNodes();
std::shared_ptr<AstNode> elseNode = node->getElseNode();

condNode->accept(shared_from_this());

//bool bool_test = false;

if (condNode) {
for (size_t i = 0; i < bodyNodes.size(); ++i) {
//std::cout << "bodyNodes[" << i << "]: "<< elseNode->getText() << '\n';
bodyNodes[i]->accept(shared_from_this());
}
}
else if (elseNode != nullptr){
//std::cout << "elsenode " << elseNode->getText() << '\n';
elseNode->accept(shared_from_this());
}
}

void Evaluator::visit(const std::shared_ptr<IndexNode> &node) {
std::shared_ptr<AstNode> identifierNode = node->getRightNode();
Expand Down

0 comments on commit 1d07042

Please sign in to comment.