commit f5f932d9c15fb8a2ee31f9872e4f58d32edc0407
parent d3caa452677c37ba27a04041c2bde49a78a504b7
Author: Eyal Sawady <ecs@d2evs.net>
Date: Mon, 28 Dec 2020 22:09:33 -0500
parse: implement field access
Diffstat:
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/include/ast.h b/include/ast.h
@@ -105,7 +105,10 @@ struct ast_expression_access {
struct ast_expression *array;
struct ast_expression *index;
};
- // TODO: Field selection
+ struct {
+ struct ast_expression *_struct;
+ char *field;
+ };
};
};
diff --git a/src/parse.c b/src/parse.c
@@ -1060,7 +1060,17 @@ parse_postfix_expression(struct parser *par, struct ast_expression *lvalue)
lvalue = parse_call_expression(par, lvalue);
break;
case T_DOT:
- assert(0); // TODO: field access expression
+ trenter(TR_PARSE, "field-access");
+ want(par, T_NAME, &tok);
+ struct ast_expression *exp =
+ xcalloc(sizeof(struct ast_expression), 1);
+ exp->type = EXPR_ACCESS;
+ exp->access.type = ACCESS_FIELD;
+ exp->access._struct = lvalue;
+ exp->access.field = tok.name;
+ lvalue = exp;
+ trleave(TR_PARSE, NULL);
+ break;
case T_LBRACKET:
unlex(par->lex, &tok);
lvalue = parse_index_slice_expression(par, lvalue);