From bf85f20ad0b6453c936a84f1bf88c1ff9062ca40 Mon Sep 17 00:00:00 2001 From: Nathanne Isip Date: Sat, 28 Sep 2024 07:23:07 +0800 Subject: [PATCH] Array object binary operation initial implementation. --- src/ast/expression/BinaryExpression.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/ast/expression/BinaryExpression.cpp b/src/ast/expression/BinaryExpression.cpp index 712ea20..82cedcd 100644 --- a/src/ast/expression/BinaryExpression.cpp +++ b/src/ast/expression/BinaryExpression.cpp @@ -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); @@ -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." + ); +} \ No newline at end of file