implemented array subscript parsing

This commit is contained in:
Lorenzo Torres 2025-12-01 11:02:13 +01:00
parent 403b2b7161
commit c566f7d490
4 changed files with 25 additions and 4 deletions

View file

@ -233,6 +233,20 @@ ast_node *parse_expression(parser *p)
left = node;
}
if (match(p, TOKEN_LSQUARE)) {
ast_node *index = parse_expression(p);
ast_node *node = arena_alloc(p->allocator, sizeof(ast_node));
node->type = NODE_ARRAY_SUBSCRIPT;
node->expr.subscript.expr = left;
node->expr.subscript.index = index;
if (!match(p, TOKEN_RSQUARE)) {
error(p, "expected `]`.");
return NULL;
}
return node;
}
return left;
}