-
Notifications
You must be signed in to change notification settings - Fork 1
/
smallc.h
88 lines (73 loc) · 1.38 KB
/
smallc.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
union content{
float Float;
int Int;
char Char;
};
typedef struct dataStruct{
int type;
char name[256];
union content value;
int ifUsed;
struct dataStruct* next;
} dataStruct, *dataNode;
dataNode head;
dataNode tail;
typedef struct valueStruct{
int type;
char contents[256];
} valueStruct, *valueNode;
typedef struct midCodeStruct{
int line;
int opt;
valueNode value1;
valueNode value2;
int jumpLine;
struct midCodeStruct* next;
struct midCodeStruct* ifNext;
struct midCodeStruct* whileNext;
}midCodeStruct, *midCodeNode;
midCodeNode midHead;
midCodeNode midTail;
enum Opt{
Add,
Sub,
Div,
Multi,
Mod,
Mov,
Jump,
CMP,
JA,
JB,
JAE,
JBE,
JE,
JNE,
};
enum ErrorType{
ValueExisted
};
enum ValueType{
IdentType,
NumberType,
Char,
Int,
Float,
JumpType,
};
extern char *strdup(const char *s);
int line;
extern valueNode exeLexp(mpc_ast_t* t);
extern valueNode exeTerm(mpc_ast_t* t);
extern int exe(mpc_ast_t* t);
extern int pushIfNode(midCodeNode node);
midCodeNode ifStackHead;
midCodeNode ifStackTail;
midCodeNode whileStackHead;
midCodeNode whileStackTail;
typedef struct whileLoopNode{
int line;
struct whileLoopNode* next;
}whileLoopNodeStruct, * whileLoopNode;
whileLoopNode whileLoopHead;
whileLoopNode whileLoopTail;