diff options
| author | Carson Fleming <[email protected]> | 2026-03-28 17:05:37 -1000 |
|---|---|---|
| committer | Carson Fleming <[email protected]> | 2026-03-28 17:05:37 -1000 |
| commit | b4d7305730606126d74862ca472a3efed964c2d8 (patch) | |
| tree | 933ee0e11e30ec03181aba9051795513b94b0421 /parser.c | |
| parent | 0dc409ab0967d9973f36c138825067462b9a216f (diff) | |
| download | ccc-b4d7305730606126d74862ca472a3efed964c2d8.tar.gz | |
rehashing and size tracking corrections
Diffstat (limited to 'parser.c')
| -rw-r--r-- | parser.c | 26 |
1 files changed, 21 insertions, 5 deletions
@@ -80,9 +80,23 @@ static void parse_type(struct type_node* p_node) { static void parse_expr(struct expr_node* p_node); -static void parse_int_lit(struct int_lit_node* p_node) { - expect(TK_INT_LIT); - p_node->val = tok.data.int_lit; +static void parse_literal(struct expr_node* p_node) { + peek_or_panic(); + + switch (tok.type) { + case TK_INT_LIT: + expect(TK_INT_LIT); + p_node->type = EXPR_INT_LIT; + p_node->as._int_lit.val = tok.data.int_lit; + break; + case TK_CHAR_LIT: + expect(TK_CHAR_LIT); + p_node->type = EXPR_CHAR_LIT; + p_node->as._char_lit.val = tok.data.char_lit; + break; + default: + PARSER_PANIC("invalid literal type"); + } } static void parse_var_ref(struct var_ref_node* p_node) { @@ -124,8 +138,10 @@ static void parse_expr(struct expr_node* p_node) { expect(TK_RPAREN); break; case TK_INT_LIT: - p_node->type = EXPR_INT_LIT; - parse_int_lit(&p_node->as._int_lit); + case TK_CHAR_LIT: + case TK_FLOAT_LIT: + case TK_STR_LIT: + parse_literal(p_node); break; case TK_IDENT: p_node->type = EXPR_VAR_REF; |
