-
Notifications
You must be signed in to change notification settings - Fork 1
/
lex.h
101 lines (82 loc) · 1.47 KB
/
lex.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#ifndef LEX_H
#define LEX_H
#include <obstack.h>
enum token_type {
LITERAL_OR_ID=1,
OPEN_PAREN,
CLOSE_PAREN,
OPEN_BRACKET,
CLOSE_BRACKET,
OPEN_CURLY,
CLOSE_CURLY,
BANG,
PERCENT,
CARET,
AMPERSAND,
BAR,
STAR,
MINUS,
PLUS,
SLASH,
LEFT_SHIFT,
RIGHT_SHIFT,
BANG_EQUAL,
PERCENT_EQUAL,
CARET_EQUAL,
AMPERSAND_EQUAL,
BAR_EQUAL,
STAR_EQUAL,
MINUS_EQUAL,
PLUS_EQUAL,
SLASH_EQUAL,
LEFT_SHIFT_EQUAL,
RIGHT_SHIFT_EQUAL,
ARROW,
DOT,
ASSIGN,
IS_EQUAL,
LTE,
GTE,
LT,
GT,
DOUBLE_AMPERSAND,
DOUBLE_BAR,
DOUBLE_PLUS,
DOUBLE_MINUS,
QUESTION,
COLON,
SIZEOF,
COMMA,
TILDE,
/* hack -- not token types but we reuse these as parse tree node
* types */
TYPECAST,
FUNCTION_CALL,
SUBSCRIPT,
REFERENCE,
DEREFERENCE,
UNARY_MINUS,
POSTINCREMENT,
POSTDECREMENT,
PREINCREMENT,
PREDECREMENT,
/* not actually ever returned, but needed for correct lexing */
START_COMMENT,
BOGUS,
END_OF_EXPRESSION
};
extern const char* token_names[];
extern const char* token_sigils[];
struct token {
enum token_type token_type;
//if non-0, owned by this token
char *token_value;
};
typedef struct {
const char* pos;
struct obstack obstack;
} lex_buf;
lex_buf start_lex(const char* expr);
void done_lex(lex_buf lex_buf);
struct token get_next_token(lex_buf* buf);
#endif