diff options
| author | Mustafa Quraish <[email protected]> | 2022-01-30 02:20:58 -0500 |
|---|---|---|
| committer | Mustafa Quraish <[email protected]> | 2022-01-30 18:04:13 -0500 |
| commit | b08bb0a17ed05e7febaee5c71f5cf1ff3447dea1 (patch) | |
| tree | d10d6f869509b7c9d4650f4aa18850fdaec97904 /src/tokens.h | |
| parent | Update build system to use Makefile (diff) | |
| download | cup-b08bb0a17ed05e7febaee5c71f5cf1ff3447dea1.tar.xz cup-b08bb0a17ed05e7febaee5c71f5cf1ff3447dea1.zip | |
Put tokens in their own macro to allow looping over them
Diffstat (limited to 'src/tokens.h')
| -rw-r--r-- | src/tokens.h | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/src/tokens.h b/src/tokens.h index 44f5e6e..3917f0f 100644 --- a/src/tokens.h +++ b/src/tokens.h @@ -12,21 +12,15 @@ F(TOKEN_CLOSE_PAREN, ")") \ F(TOKEN_COLON, ":") \ F(TOKEN_COMMA, ",") \ - F(TOKEN_ELSE, "else") \ F(TOKEN_EOF, "EOF") \ F(TOKEN_EQ, "==") \ F(TOKEN_EXCLAMATION, "!") \ - F(TOKEN_FN, "fn") \ - F(TOKEN_FOR, "for") \ F(TOKEN_GEQ, ">=") \ F(TOKEN_GT, ">") \ F(TOKEN_IDENTIFIER, "identifier") \ - F(TOKEN_IF, "if") \ - F(TOKEN_INT, "int") \ F(TOKEN_INTLIT, "integer literal") \ F(TOKEN_LEQ, "<=") \ F(TOKEN_LSHIFT, "<<") \ - F(TOKEN_LET, "let") \ F(TOKEN_LT, "<") \ F(TOKEN_MINUS, "-") \ F(TOKEN_MINUSEQUALS, "-=") \ @@ -40,20 +34,30 @@ F(TOKEN_PLUSEQUALS, "+=") \ F(TOKEN_PLUSPLUS, "++") \ F(TOKEN_QUESTION, "?") \ - F(TOKEN_RETURN, "return") \ F(TOKEN_RSHIFT, ">>") \ F(TOKEN_SEMICOLON, ";") \ F(TOKEN_SLASH, "/") \ F(TOKEN_STAR, "*") \ F(TOKEN_STRINGLIT, "string literal") \ F(TOKEN_TILDE, "~") \ - F(TOKEN_WHILE, "while") \ F(TOKEN_XOR, "^") +#define ENUM_KEYWORDS(F) \ + F(TOKEN_ELSE, "else") \ + F(TOKEN_FN, "fn") \ + F(TOKEN_FOR, "for") \ + F(TOKEN_IF, "if") \ + F(TOKEN_INT, "int") \ + F(TOKEN_LET, "let") \ + F(TOKEN_RETURN, "return") \ + F(TOKEN_WHILE, "while") \ + + typedef enum { -#define ENUM_TOKEN(name, str) name, - ENUM_TOKENS(ENUM_TOKEN) -#undef ENUM_TOKEN +#define HANDLE_ITEM(name, str) name, + ENUM_TOKENS(HANDLE_ITEM) + ENUM_KEYWORDS(HANDLE_ITEM) +#undef HANDLE_ITEM } TokenType; typedef struct { |