summaryrefslogtreecommitdiff
path: root/src/parser.c
diff options
context:
space:
mode:
authorJohnny Richard <johnny@johnnyrichard.com>2023-04-30 03:11:00 -0300
committerJohnny Richard <johnny@johnnyrichard.com>2023-04-30 17:40:01 +0200
commitb1f7b0cccc6986ca107d9eeb1c7d5e5e5a32dc49 (patch)
treefb1eb8192c3f6da14796d59831030dd23935edcd /src/parser.c
parent090da456910429708ef7ee202b627e3dbce17819 (diff)
gas: Compile variable expression with scope support
This patch adds the variable compilation and uses a scope (a stack of map) to lookup for identities. Today we use a vector + ref_entry structs in order to achieve the scope implementation. The ref_entry lacks memory management, we are still no sure who will be the owner of the pointer. We also want to replace the scope a hashtable_t type as soon as we get one. Signed-off-by: Johnny Richard <johnny@johnnyrichard.com> Co-authored-by: Carlos Maniero <carlosmaniero@gmail.com>
Diffstat (limited to 'src/parser.c')
-rw-r--r--src/parser.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/src/parser.c b/src/parser.c
index 48a9125..f4829ee 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -135,10 +135,10 @@ parser_parse_factor(parser_t *parser, ast_node_t *node)
if (!drop_expected_token(parser, TOKEN_CPAREN))
return false;
return true;
- case TOKEN_NAME:
- ast_node_init_identifier(node, token.value);
+ case TOKEN_NAME: {
// TODO: Check node kind, today accepts only variables
- if (scope_get(parser->scope, token.value) == NULL) {
+ ast_node_t *var_node = scope_get(parser->scope, token.value);
+ if (var_node == NULL) {
parser_error_t error;
error.token = token;
sprintf(error.message, "identifier '" SVFMT "' not defined", SVARG(&token.value));
@@ -146,7 +146,10 @@ parser_parse_factor(parser_t *parser, ast_node_t *node)
return false;
}
+ ast_node_init_variable(node, &var_node->data.variable_declaration.identifier);
+
return true;
+ }
default: {
parser_error_t error;
error.token = token;