From 3129b741064c2b4f2c6c2408bd42cc83f7341ea8 Mon Sep 17 00:00:00 2001 From: Carlos Maniero Date: Wed, 10 May 2023 16:53:05 -0300 Subject: gas: Generate function call This is an initial commit that enables function calls. At this point only functions with no parameters is going to work. Signed-off-by: Carlos Maniero --- src/parser.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index b94087f..578514c 100644 --- a/src/parser.c +++ b/src/parser.c @@ -339,10 +339,9 @@ parser_parse_factor(parser_t *parser) return expression; } case TOKEN_NAME: { - // TODO: Check node kind, today accepts only variables - ast_node_t *var_node = scope_get(parser->scope, token.value); + ast_node_t *referenced_node = scope_get(parser->scope, token.value); - if (var_node == NULL) { + if (referenced_node == NULL) { parser_error_t error; error.token = token; sprintf(error.message, "identifier '" SVFMT "' not defined", SVARG(&token.value)); @@ -350,8 +349,21 @@ parser_parse_factor(parser_t *parser) return NULL; } - return ast_node_new_variable(&var_node->data.variable_declaration.identifier, - var_node->data.variable_declaration.type); + if (referenced_node->kind == AST_VARIABLE_DECLARATION) { + return ast_node_new_variable(&referenced_node->data.variable_declaration.identifier, + referenced_node->data.variable_declaration.type); + } + + // Parse function parameters + if (!drop_expected_token(parser, TOKEN_OPAREN)) { + return NULL; + } + if (!drop_expected_token(parser, TOKEN_CPAREN)) { + return NULL; + } + + return ast_node_new_function_call(&referenced_node->data.function.identifier, + referenced_node->data.function.return_type); } default: { parser_error_t error; -- cgit v1.2.3