added parsing of function call
This commit is contained in:
@@ -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
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user