blob: 176ff2765f7637941ee0b924ac1438851d602063 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#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
|