-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlexer.h
52 lines (44 loc) · 1019 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
#ifndef LEXER_H
#define LEXER_H
// operation order : https://www.cs.uic.edu/~i109/Notes/COperatorPrecedenceTable.pdf
typedef enum TokenType {
UNDEFINED, BEGIN,
P0,
ADD, MIN,
P1,
MUL, DIV, MOD,
PRIORITY_END,
NUMBER, DECIMAL,
PAREN, THESE,
NOT,
EQ, GE, GT, LE, LT, NE,
AND, OR,
EQ_ASS, ADD_ASS, MIN_ASS, MUL_ASS, DIV_ASS, MOD_ASS,
AND_ASS, OR_ASS, XOR_ASS, NOT_ASS,
LEFT_SHIFT_ASS, RIGHT_SHIFT_ASS,
BIT_AND, BIT_OR, BIT_XOR, BIT_NOT,
LEFT_SHIFT, RIGHT_SHIFT,
TEXT,
END,
} TokenType;
extern char *lookup_TokenType[]; // in lexer.c
typedef double Decimal;
typedef struct Token {
TokenType type;
union {
struct {
char *text;
int len;
};
int number;
Decimal decimal;
};
} Token;
static Token token_null = {
.type = UNDEFINED,
.number = 0,
};
int next_token(char *prog, Token *tok);
void print_tok(Token tok);
int token_equals(Token tok1, Token tok2);
#endif // LEXER_H