From 24522c8496c2661ba90b560bed0da482a85c3c8d Mon Sep 17 00:00:00 2001 From: Quinn Stephens Date: Mon, 9 Jun 2025 22:11:41 -0400 Subject: parser: Parse pointer levels (e.g. void **) Signed-off-by: Quinn Stephens --- src/parser/parser.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/parser/parser.c') diff --git a/src/parser/parser.c b/src/parser/parser.c index ccdc037..b947ea2 100644 --- a/src/parser/parser.c +++ b/src/parser/parser.c @@ -96,6 +96,7 @@ static bool parse_decl(struct parser *ctx) { struct type *type; + int ptr_levels; struct ast_node *node; /* @@ -112,6 +113,12 @@ parse_decl(struct parser *ctx) } parser_advance(ctx); + ptr_levels = 0; + while (ctx->tok.kind == TOK_ASTERISK) { + ptr_levels++; + parser_advance(ctx); + } + if (ctx->tok.kind != TOK_IDENTIFIER) { tok_error(&ctx->tok, "expected identifier after type\n"); return false; @@ -127,7 +134,7 @@ parse_decl(struct parser *ctx) node->name = ctx->tok.pos; node->name_len = ctx->tok.len; node->type = type; - node->ptr_levels = 0; + node->ptr_levels = ptr_levels; parser_advance(ctx); if (ctx->tok.kind == TOK_LPAREN) { -- cgit v1.2.3