Skip to content

Commit

Permalink
Array object binary operation initial implementation.
Browse files Browse the repository at this point in the history
  • Loading branch information
nthnn committed Sep 27, 2024
1 parent 07b3a16 commit bf85f20
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/ast/expression/BinaryExpression.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ DynamicObject BinaryExpression::visit(SymbolTable& symbols) {

if(lValue.isNumber() && rValue.isNumber())
return this->applyNumOp(lValue, rValue);
else if(lValue.isArray() && rValue.isArray())
return this->applyArrayOp(lValue, rValue);
else if((lValue.isString() || rValue.isString()) &&
!(this->op == "::" || this->op == "!:"))
return this->applyStringOp(lValue, rValue);
Expand Down Expand Up @@ -234,3 +236,26 @@ DynamicObject BinaryExpression::applyRegexOp(DynamicObject& lValue, DynamicObjec
"Unsupported operation for regular expression matching."
);
}

DynamicObject BinaryExpression::applyArrayOp(DynamicObject& lValue, DynamicObject& rValue) {
if(this->op == "+") {
for(auto& object : *lValue.getArray())
if(!object.isNumber())
throw ASTNodeException(
std::move(this->address),
"Unsupported binary operation for array that contains non-numbers."
);

for(auto& object : *rValue.getArray())
if(!object.isNumber())
throw ASTNodeException(
std::move(this->address),
"Unsupported binary operation for array that contains non-numbers."
);
}

throw ASTNodeException(
std::move(this->address),
"Unsupported operation for array objects."
);
}

0 comments on commit bf85f20

Please sign in to comment.