forked from ladingwu/compiler_java_python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExps.java
More file actions
178 lines (165 loc) · 3.5 KB
/
Exps.java
File metadata and controls
178 lines (165 loc) · 3.5 KB
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
package parse;
import java.awt.SystemColor;
import java.util.ArrayList;
import java.util.List;
//enum type_id {NUM,STRING,BOOL,NORMAL_NUM,NORMAL_STRING};
enum type_com{BIG,LITTLE,EQUAL,BIG_EQUAL,LITTLE_EQUAL};
enum type_cal{BIG,LITTLE,EQUAL,BIG_EQUAL,LITTLE_EQUAL,
GOT,ADD,SUB,MUL,DIV,ID,NUM,STRING,BOOL,NORMAL_NUM,
NORMAL_STRING,TRANS_NUM,TRANS_STRING,TRANS_BOOL,FUNC,WHI,IFE};
enum type_ret{NUM,STRING,BOOL};
class Exp{
type_cal type;
String line;
String row;
}
//数值或者变量
class Exp_mark extends Exp{
String value;
List<Exp> list_value=null;
public void set_listvalue(Exp s){
if(list_value==null){
list_value=new ArrayList<Exp>();
}
list_value.add(s);
}
Exp got=null; //判断变量后面是否是一个等号
}
class Exp_type extends Exp{
Exp Id=null; //定义的变量
}
class Exp_calcul extends Exp{
Exp left;
Exp right;
}
//条件
class Exp_cond extends Exp{
Exp left;
Exp_comp exp_comp;
Exp right;
}
//比较符号
class Exp_comp extends Exp{
}
//函数定义
class Exp_func extends Exp{
Exp_funcname name;
// String return_type;
// Exp_defvar exp; //传入参数不定
// List<Exp> list_var=null;
// exp表达式的个数也不定
List<Exp> list_exp=null;
// while循环的个数也不定
// List<Exp> list_whi=null;
// if条件语句的个数也不定
// List<Exp> list_ife=null;
public void setExp(Exp exp){
if(list_exp==null){
list_exp=new ArrayList<Exp>();
}
list_exp.add(exp);
}
}
class Exp_funcname extends Exp{
String name=null;
}
////变量定义
//class Exp_defvar extends Exp{
//
// String id_name;
//
//}
class Exp_whi extends Exp{
// Object exp;
Exp_cond condition;
// Exp_ife if_el;
Exp next=null;
// List<Exp> list_whi=null;
// List<Exp> list_if=null;
// List<Exp> list_exp=null;
// public void setList_whi(Exp whi){
// if(list_whi==null){
// list_whi=new ArrayList<Exp>();
// }
// list_whi.add(whi);
// }
// public void setList_if(Exp ife){
// if(list_if==null){
// list_if=new ArrayList<Exp>();
// }
// list_if.add(ife);
// }
// public void setList_exp(Exp exp){
// if(list_exp==null){
// list_exp=new ArrayList<Exp>();
// }
// list_exp.add(exp);
// }
}
class Exp_ife extends Exp{
Exp_cond condition;
Exp left=null; //满足条件时
Exp right=null; //不满足条件时
// List<Exp> list_whi=null;
// List<Exp> list_if=null;
// List<Exp> list_exp=null;
// public void setList_whi(Exp whi){
// if(list_whi==null){
// list_whi=new ArrayList<Exp>();
// }
// list_whi.add(whi);
// }
// public void setList_if(Exp ife){
// if(list_if==null){
// list_if=new ArrayList<Exp>();
// }
// list_if.add(ife);
// }
// public void setList_exp(Exp exp){
// if(list_exp==null){
// list_exp=new ArrayList<Exp>();
// }
// list_exp.add(exp);
// }
//
//// else条件下的可能的语句
// Exp_cond condition1;
// List<Exp> list_whi1=null;
// List<Exp> list_if1=null;
// List<Exp> list_exp1=null;
// public void setList_whi1(Exp whi){
// if(list_whi1==null){
// list_whi1=new ArrayList<Exp>();
// }
// list_whi1.add(whi);
// }
// public void setList_if1(Exp ife){
// if(list_if1==null){
// list_if1=new ArrayList<Exp>();
// }
// list_if1.add(ife);
// }
// public void setList_exp1(Exp exp){
// if(list_exp1==null){
// list_exp1=new ArrayList<Exp>();
// }
// list_exp1.add(exp);
// }
}
class Exp_B extends Exp{
// Exp list_whi=null;
// Exp exp_if=null;
List<Exp> list_exp=null;
// public void setList_whi(Exp whi){
// list_whi=whi;
// }
// public void setList_if(Exp ife){
// exp_if=ife;
// }
public void setList_exp(Exp exp){
if(list_exp==null){
list_exp=new ArrayList<Exp>();
}
list_exp.add(exp);
}
}