From 405d0c32ba8a6a065c2a8767295490e4add20498 Mon Sep 17 00:00:00 2001 From: Quinn Stephens Date: Sat, 7 Jun 2025 23:03:12 -0400 Subject: Refactor and begin parser * Added token flags * Added `int` keyword * Moved code from main.c to parser/parser.c * Began work on parsing declarations Signed-off-by: Quinn Stephens --- src/lexer/keywords.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/lexer/keywords.c') diff --git a/src/lexer/keywords.c b/src/lexer/keywords.c index 7bb6b47..30eb2a1 100644 --- a/src/lexer/keywords.c +++ b/src/lexer/keywords.c @@ -34,7 +34,7 @@ #include "lexer/keywords.h" #include "log.h" -#define KEYWORD_COUNT 1 +#define KEYWORD_COUNT 2 #define KEYWORD_MAP_ROWS 16 @@ -43,13 +43,15 @@ static struct hashmap map; static struct { const char *str; - enum token_kind value; + enum token_kind tok_kind; + uint8_t tok_flags; } info[KEYWORD_COUNT] = { - { "void", TK_VOID } + { "void", TK_VOID, TF_BUILTIN_TYPE }, + { "int" , TK_INT , TF_BUILTIN_TYPE } }; static void -add_keyword(const char *str, enum token_kind value) +add_keyword(const char *str, enum token_kind tok_kind, uint8_t tok_flags) { struct keyword *kwd; @@ -60,7 +62,8 @@ add_keyword(const char *str, enum token_kind value) } kwd->len = strlen(str); - kwd->value = value; + kwd->tok_kind = tok_kind; + kwd->tok_flags = tok_flags; kwd->hashmap_entry.hash = hash(str, kwd->len); hashmap_add(map, &kwd->hashmap_entry); @@ -93,6 +96,6 @@ keywords_init(void) /* Register all keywords */ for (int k = 0; k < KEYWORD_COUNT; k++) { - add_keyword(info[k].str, info[k].value); + add_keyword(info[k].str, info[k].tok_kind, info[k].tok_flags); } } -- cgit v1.2.3