diff options
Diffstat (limited to 'include/token.h')
-rw-r--r-- | include/token.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/include/token.h b/include/token.h new file mode 100644 index 0000000..2f3cbb3 --- /dev/null +++ b/include/token.h @@ -0,0 +1,55 @@ +#ifndef CMONKEY_TOKEN_H +#define CMONKEY_TOKEN_H + +#include "slice.h" + +enum token_type { + TOKEN_ILLEGAL, + TOKEN_EOF, + /* Identifiers/Literals */ + TOKEN_IDENT, + TOKEN_INT, + /* Operators */ + TOKEN_ASSIGN, + TOKEN_PLUS, + TOKEN_MINUS, + TOKEN_BANG, + TOKEN_ASTERISK, + TOKEN_SLASH, + TOKEN_LT, + TOKEN_GT, + TOKEN_EQ, + TOKEN_NOTEQ, + /* Delimiters */ + TOKEN_COMMA, + TOKEN_SEMICOLON, + TOKEN_LPAREN, + TOKEN_RPAREN, + TOKEN_LBRACE, + TOKEN_RBRACE, + /* Keywords */ + TOKEN_FUNC, + TOKEN_LET, + TOKEN_TRUE, + TOKEN_FALSE, + TOKEN_IF, + TOKEN_ELSE, + TOKEN_RETURN, +}; + +struct token { + enum token_type type; + struct slice literal; +}; + +void token_init_keywords(void); + +enum token_type token_lookup_ident(const struct slice *ident); + +inline const char *token_type_print(enum token_type); + +char *token_sprint(struct token *, char *str); + +void token_free_keywords(void); + +#endif |