-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoken.h
71 lines (65 loc) · 1.96 KB
/
token.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
/*
* these are keywords that are recognized by the lexer.
* they all have values that are printable for debug
* purposes and for cheap serializing into intermediate files
*/
typedef enum {
/* pseudo-keywords, and expression operators */
E_O_F = 0,
EXPR = 0x01,
NEG = 0x02,
NOT = 0x03,
NONE = ' ',
/* C keywords */
ASM = 'A', AUTO = 'o',
BOOLEAN = 'b' , BREAK = 'B',
CASE = 'C', CHAR = 'c', CONST = 'k', CONTINUE = 'N',
DEFAULT = 'O', DO = 'D', DOUBLE = 'd',
ELSE = 'E', ENUM = 'e', EXTERN = 'x',
FLOAT = 'f', FOR = 'F',
GOTO = 'G',
IF = 'I', INT = 'i',
LONG = 'l',
REGISTER = 'r', RETURN = 'R',
SIZEOF = 'z', SHORT = 's', STATIC = 'p', STRUCT = 'a', SWITCH = 'S',
TYPEDEF = 't',
UNION = 'm', UNSIGNED = 'u',
VOID = 'v', VOLATILE = '4',
WHILE = 'W',
/* syntactic cogs */
BEGIN = '{', END = '}',
LBRACK = '[', RBRACK = ']',
LPAR = '(', RPAR = ')',
SEMI = ';', COMMA = ',',
LABEL = '3',
/* terminals */
SYM = '5', NUMBER = '9', STRING = '\"',
/* operators */
ASSIGN = '=', DOT = '.', DEREF = 'M',
PLUS = '+', MINUS = '-', STAR = '*', DIV = '/', MOD = '%',
AND = '&', OR = '|', XOR = '^',
LT = '<', GT = '>', BANG = '!', TWIDDLE = '~',
QUES = '?', COLON = ':',
INCR = 'U', DECR = 'V',
LSHIFT = 'y' , RSHIFT = 'w',
LOR = 'h', LAND = 'j',
EQ = 'Q', NEQ = 'n', LE = 'L', GE = 'g',
PLUSEQ = 'P', SUBEQ = '_', MULTEQ = 'T', DIVEQ = '2', MODEQ = '7',
ANDEQ = '@', OREQ = '1', XOREQ = 'X',
LANDEQ = 'J', LOREQ = 'H',
RSHIFTEQ = '6', LSHIFTEQ = '0',
/* CPP */
INCLUDE = '#',
DEFINE = '$', UNDEF = 'K',
IFDEF = 'Y', ENDIF = 'Z', ELIF = '8'
} token_t;
/*
* these are the operator priority levels.
* when parsing an expression at priority level N, and you encounter an operator of priority < N,
* stop parsing.
*/
#define PRI_SEMI 0
#define PRI_PAREN 1
#define PRI_EQ 2
#define PRI_MULT 3
#define PRI_ADD 4