3 public class Operation {
4 public static final int LOGIC_OR=1;
5 public static final int LOGIC_AND=2;
6 public static final int BIT_OR=3;
7 public static final int BIT_XOR=4;
8 public static final int BIT_AND=5;
9 public static final int EQUAL=6;
10 public static final int NOTEQUAL=7;
11 public static final int LT=8;
12 public static final int GT=9;
13 public static final int LTE=10;
14 public static final int GTE=11;
15 public static final int LEFTSHIFT=12;
16 public static final int RIGHTSHIFT=13;
17 public static final int SUB=14;
18 public static final int ADD=15;
19 public static final int MULT=16;
20 public static final int DIV=17;
21 public static final int MOD=18;
22 public static final int UNARYPLUS=19;
23 public static final int UNARYMINUS=20;
24 public static final int POSTINC=21;
25 public static final int POSTDEC=22;
26 public static final int PREINC=23;
27 public static final int PREDEC=24;
28 public static final int LOGIC_NOT=25;
29 public static final int ISAVAILABLE=26;
30 public static final int URIGHTSHIFT=27;
31 public static final int COMP=28;
33 public static final int ASSIGN=100;
35 private int operation;
36 public Operation(int op) {
40 public Operation(String op) {
41 this.operation=parseOp(op);
48 public static int parseOp(String st) {
49 if (st.equals("logical_or"))
51 else if (st.equals("logical_and"))
53 else if (st.equals("bitwise_or"))
55 else if (st.equals("bitwise_xor"))
57 else if (st.equals("bitwise_and"))
59 else if (st.equals("equal"))
61 else if (st.equals("not_equal"))
63 else if (st.equals("comp_lt"))
65 else if (st.equals("comp_gt"))
67 else if (st.equals("comp_lte"))
69 else if (st.equals("comp_gte"))
71 else if (st.equals("leftshift"))
73 else if (st.equals("rightshift"))
75 else if (st.equals("urightshift"))
77 else if (st.equals("sub"))
79 else if (st.equals("add"))
81 else if (st.equals("mult"))
83 else if (st.equals("div"))
85 else if (st.equals("mod"))
87 else if (st.equals("unaryplus"))
89 else if (st.equals("unaryminus"))
91 else if (st.equals("postinc"))
93 else if (st.equals("postdec"))
95 else if (st.equals("preinc"))
97 else if (st.equals("predec"))
99 else if (st.equals("not"))
101 else if (st.equals("comp"))
107 public String toString() {
108 if (operation==LOGIC_OR)
110 else if (operation==LOGIC_AND)
112 else if (operation==LOGIC_NOT)
114 else if (operation==COMP)
116 else if (operation==BIT_OR)
118 else if (operation==BIT_XOR)
120 else if (operation==BIT_AND)
122 else if (operation==EQUAL)
124 else if (operation==NOTEQUAL)
126 else if (operation==LT)
128 else if (operation==GT)
130 else if (operation==LTE)
132 else if (operation==GTE)
134 else if (operation==LEFTSHIFT)
136 else if (operation==RIGHTSHIFT)
138 else if (operation==URIGHTSHIFT)
140 else if (operation==SUB)
142 else if (operation==ADD)
144 else if (operation==MULT)
146 else if (operation==DIV)
148 else if (operation==MOD)
150 else if (operation==UNARYPLUS)
152 else if (operation==UNARYMINUS)
154 else if (operation==POSTINC)
156 else if (operation==POSTDEC)
158 else if (operation==PREINC)
160 else if (operation==PREDEC)
162 else if (operation==ASSIGN)
164 else if (operation==ISAVAILABLE)
165 return "isavailable";
166 else throw new Error("op="+operation);