-
Notifications
You must be signed in to change notification settings - Fork 9
/
tokens.h
75 lines (63 loc) · 1.06 KB
/
tokens.h
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
67
68
69
70
71
72
73
74
75
#ifndef TOKENS_H
#define TOKENS_H
enum class TOK {
UNDEFINED,
EOI,
// Can start an expression
INTLIT,
LPAR,
NOT,
// Is a type keyword
BOOLEAN,
INT,
// Can start a statement
__FIRST_STMT,
LBRACE = __FIRST_STMT,
ID,
IF,
WHILE,
PRINT,
__LAST_STMT = PRINT,
// TODO: Handle the next couple as just identifiers that we intern ?
PUBLIC,
ELSE,
RETURN,
STATIC,
VOID,
STRING,
TRUE,
FALSE,
THIS,
NEW,
CLASS,
EXTENDS,
ASGN,
RPAR,
RBRACE,
RBRACKET,
COMMA,
DOT,
SEMI,
__FIRST_OP,
AND_AND = __FIRST_OP,
LT,
PLUS,
MINUS,
STAR,
LBRACKET,
__LAST_OP = LBRACKET,
__LAST = ASGN,
};
constexpr int TOK_LEN = (int)TOK::__LAST - (int)TOK::UNDEFINED;
struct token_t {
TOK kind;
// TODO: Eliminate those (with e.g. inheritance
// or allocating separately manually).
union {
const char *id;
int val;
};
};
void print_token(token_t tok);
const char* token_name(TOK tok);
#endif