-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlexer.h
56 lines (49 loc) · 1005 Bytes
/
lexer.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
#ifndef LEXER__H_
#define LEXER__H_
#define FOREACH_TOKEN(F) \
F(Illegal) \
F(EndOfFile) \
F(Ident) \
F(Integer) \
F(Assign) \
F(Plus) \
F(Minus) \
F(Bang) \
F(Asterisk) \
F(Slash) \
F(LowerThan) \
F(GreaterThan) \
F(Equal) \
F(NotEqual) \
F(Comma) \
F(Semicolon) \
F(LeftParenthesis) \
F(RightParenthesis) \
F(LeftBrace) \
F(RightBrace) \
F(Function) \
F(Let) \
F(True) \
F(False) \
F(If) \
F(Else) \
F(Return) \
enum TokenType {
#define F(token) token,
FOREACH_TOKEN(F)
#undef F
};
extern const char *token_to_string(enum TokenType token);
struct Token {
enum TokenType type;
const char *beg;
const char *end;
};
struct Lexer {
const char *cur;
const char *end;
};
int lexer_create(struct Lexer *lex, const char *beg, const char *end);
int lexer_destroy(struct Lexer *lex);
int lexer_next_token(struct Lexer *lex, struct Token *token);
#endif // LEXER__H_