#ifndef __TOKEN_H #define __TOKEN_H #define FOREACH_TOKEN(FUNCTION) \ FUNCTION(LEFT_PAREN) \ FUNCTION(RIGHT_PAREN) \ FUNCTION(LEFT_BRACE) \ FUNCTION(RIGHT_BRACE) \ FUNCTION(COMMA) \ FUNCTION(DOT) \ FUNCTION(MINUS) \ FUNCTION(PLUS) \ FUNCTION(SEMICOLON) \ FUNCTION(SLASH) \ FUNCTION(STAR) \ FUNCTION(BANG) \ FUNCTION(BANG_EQUAL) \ FUNCTION(EQUAL) \ FUNCTION(EQUAL_EQUAL) \ FUNCTION(GREATER) \ FUNCTION(GREATER_EQUAL) \ FUNCTION(LESS) \ FUNCTION(LESS_EQUAL) \ FUNCTION(IDENTIFIER) \ FUNCTION(STRING) \ FUNCTION(NUMBER) \ FUNCTION(AND) \ FUNCTION(CLASS) \ FUNCTION(ELSE) \ FUNCTION(FUN) \ FUNCTION(FOR) \ FUNCTION(IF) \ FUNCTION(NIL) \ FUNCTION(OR) \ FUNCTION(PRINT) \ FUNCTION(RETURN) \ FUNCTION(SUPER) \ FUNCTION(THIS) \ FUNCTION(VAR) \ FUNCTION(WHILE) \ FUNCTION(TRUE) \ FUNCTION(FALSE) \ FUNCTION(EOFF) #define GENERATE_ENUM(ENUM) ENUM, #define GENERATE_STRING(STRING) #STRING, typedef enum { FOREACH_TOKEN(GENERATE_ENUM) } token_type_e; static const char *TOKEN_STRING[] = { FOREACH_TOKEN(GENERATE_STRING) }; class Token { private: token_type_e m_type; char *m_lexeme; // literal unsigned int m_line; char *m_string; public: void init(token_type_e type, char *lexeme, unsigned int line); char *to_string(void); void clean(void); }; #endif