diff options
| author | Raghuram Subramani <raghus2247@gmail.com> | 2025-06-13 11:45:49 +0530 |
|---|---|---|
| committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-06-13 11:45:49 +0530 |
| commit | e119cb100dadf8b3e3b6660029abf73d14cf209b (patch) | |
| tree | 366b289a742fa6a8e043feac6217fa0ae1f5217b /include | |
| parent | 35931d1021ac886e85015fc6e1640350cba578a1 (diff) | |
lexer: handle identifiers
Diffstat (limited to 'include')
| -rw-r--r-- | include/lexer.h | 1 | ||||
| -rw-r--r-- | include/token.h | 10 |
2 files changed, 11 insertions, 0 deletions
diff --git a/include/lexer.h b/include/lexer.h index 8122848..4605142 100644 --- a/include/lexer.h +++ b/include/lexer.h @@ -27,6 +27,7 @@ private: private: void string(void); void number(void); + void identifier(void); private: void add_token(token_type_e type); diff --git a/include/token.h b/include/token.h index 176ff27..92106a2 100644 --- a/include/token.h +++ b/include/token.h @@ -45,9 +45,19 @@ #define GENERATE_ENUM(ENUM) ENUM, #define GENERATE_STRING(STRING) #STRING, +#define N_KEYWORDS 16 + typedef enum { FOREACH_TOKEN(GENERATE_ENUM) } token_type_e; static const char *TOKEN_STRING[] = { FOREACH_TOKEN(GENERATE_STRING) }; +static const char *KEYWORD_STRING_MAPPING[N_KEYWORDS] + = { "and", "class", "else", "false", "for", "fun", "if", "nil", + "or", "print", "return", "super", "this", "true", "var", "while" }; + +static const token_type_e KEYWORD_TYPE_MAPPING[N_KEYWORDS] + = { AND, CLASS, ELSE, FALSE, FOR, FUN, IF, NIL, + OR, PRINT, RETURN, SUPER, THIS, TRUE, VAR, WHILE }; + class Token { private: |
