From 3da421417167d30ef6291342b19b08419049faae Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Sat, 5 Feb 2022 00:58:16 -0500 Subject: Add `sizeof()` operator that can return the size of a type. --- src/parser.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src/parser.c') diff --git a/src/parser.c b/src/parser.c index 81c90da..99926d0 100644 --- a/src/parser.c +++ b/src/parser.c @@ -541,6 +541,14 @@ Node *parse_factor(Lexer *lexer) Lexer_next(lexer); expr = parse_expression(lexer); assert_token(Lexer_next(lexer), TOKEN_CLOSE_PAREN); + + // FIXME: This should probably go somewhere else more appropriate + } else if (token.type == TOKEN_SIZEOF) { + Lexer_next(lexer); + assert_token(Lexer_next(lexer), TOKEN_OPEN_PAREN); + Type *type = parse_type(lexer); + assert_token(Lexer_next(lexer), TOKEN_CLOSE_PAREN); + expr = Node_from_int_literal(size_for_type(type)); } else if (is_literal_token(token.type)) { expr = parse_literal(lexer); } else if (token.type == TOKEN_IDENTIFIER) { -- cgit v1.2.3