From a76181288ae27b85521838ee87352727c3cba2f8 Mon Sep 17 00:00:00 2001
From: Ferenc Szontágh <szf@fsociety.hu>
Date: Fri, 18 Apr 2025 10:15:12 +0000
Subject: [PATCH] call function when variable defined
---
src/Parser/Parser.cpp | 24 ++++++++++++++++++++++++
1 files changed, 24 insertions(+), 0 deletions(-)
diff --git a/src/Parser/Parser.cpp b/src/Parser/Parser.cpp
index 3934023..1b900a3 100644
--- a/src/Parser/Parser.cpp
+++ b/src/Parser/Parser.cpp
@@ -311,6 +311,30 @@
// Pop the matching "("
operator_stack.pop();
expect_unary = false;
+ }
+ // Function call as expression: identifier followed by '('
+ else if (token.type == Lexer::Tokens::Type::IDENTIFIER &&
+ peekToken().type == Lexer::Tokens::Type::PUNCTUATION && peekToken().value == "(") {
+ // Parse function call
+ std::string func_name = token.value;
+ consumeToken(); // consume function name
+ consumeToken(); // consume '('
+ std::vector<ParsedExpressionPtr> call_args;
+ // Parse arguments if any
+ if (!(currentToken().type == Lexer::Tokens::Type::PUNCTUATION && currentToken().value == ")")) {
+ while (true) {
+ auto arg_expr = parseParsedExpression(Symbols::Variables::Type::NULL_TYPE);
+ call_args.push_back(std::move(arg_expr));
+ if (match(Lexer::Tokens::Type::PUNCTUATION, ",")) {
+ continue;
+ }
+ break;
+ }
+ }
+ expect(Lexer::Tokens::Type::PUNCTUATION, ")");
+ // Create call expression node
+ output_queue.push_back(ParsedExpression::makeCall(func_name, std::move(call_args)));
+ expect_unary = false;
} else if (token.type == Lexer::Tokens::Type::OPERATOR_ARITHMETIC) {
std::string op = std::string(token.lexeme);
--
Gitblit v1.9.3