added parsing of function call

This commit is contained in:
Karma Riuk
2025-07-15 19:42:43 +02:00
parent 59bff59cf7
commit a016bbaa5e
6 changed files with 168 additions and 1 deletions

View File

@@ -32,4 +32,35 @@ namespace ast {
if (body != nullptr)
delete body;
}
// ---------------------------- FUNCTION CALL ----------------------------
function_call::function_call(token::token token, expression* target)
: token(std::move(token)),
target(target) {};
std::string function_call::token_literal() const {
return token.literal;
};
std::string function_call::str() const {
std::stringstream ss;
ss << target->str() << "(";
bool first = true;
for (auto& param : parameters) {
if (!first)
ss << ", ";
ss << param->str();
first = false;
}
ss << ")";
return ss.str();
};
function_call::~function_call() {
if (target != nullptr)
delete target;
for (auto& param : parameters)
delete param;
}
} // namespace ast

View File

@@ -18,4 +18,15 @@ namespace ast {
std::string str() const override;
~function_literal();
};
struct function_call : expression {
function_call(token::token, expression*);
token::token token;
expression* target;
std::vector<expression*> parameters;
std::string token_literal() const override;
std::string str() const override;
~function_call();
};
} // namespace ast