diff options
| author | Raghuram Subramani <raghus2247@gmail.com> | 2025-06-08 23:50:41 +0530 |
|---|---|---|
| committer | Raghuram Subramani <raghus2247@gmail.com> | 2025-06-08 23:50:41 +0530 |
| commit | 73d8ee51a9bf3175a1b4b339b043f45d17c9d92a (patch) | |
| tree | 9285b29ad316df4dd7398ff8d25234ab7c231d72 /include/token.h | |
| parent | 1de0b57e396d1964aba2c8ddc663bd55d01f5058 (diff) | |
tokens: init
Diffstat (limited to 'include/token.h')
| -rw-r--r-- | include/token.h | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/include/token.h b/include/token.h new file mode 100644 index 0000000..c6a61cd --- /dev/null +++ b/include/token.h @@ -0,0 +1,71 @@ +#ifndef __TOKEN_H +#define __TOKEN_H + +enum TokenType { + // Single-character tokens. + LEFT_PAREN, + RIGHT_PAREN, + LEFT_BRACE, + RIGHT_BRACE, + COMMA, + DOT, + MINUS, + PLUS, + SEMICOLON, + SLASH, + STAR, + + // One or two character tokens. + BANG, + BANG_EQUAL, + EQUAL, + EQUAL_EQUAL, + GREATER, + GREATER_EQUAL, + LESS, + LESS_EQUAL, + + // Literals. + IDENTIFIER, + STRING, + NUMBER, + + // Keywords. + AND, + CLASS, + ELSE, + FUN, + FOR, + IF, + NIL, + OR, + PRINT, + RETURN, + SUPER, + THIS, + VAR, + WHILE, + + TRUE, + FALSE, + + EOFF +}; + +class Token +{ +private: + TokenType type; + char *lexeme; + // literal + unsigned int line; + char *string; + +public: + Token(TokenType type, char *lexeme, unsigned int line); + + char *to_string(void); + void clean(void); +}; + +#endif |
