-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOp.java
34 lines (29 loc) · 856 Bytes
/
Op.java
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
public enum Op {
Plus, Minus, Times, Divide, Hat, Undef;
public String toString() {
switch(this) {
case Plus: return "+";
case Minus: return "-";
case Times: return "*";
case Divide: return "/";
case Hat: return "^";
default: return "INVALID_OPERATOR";
}
}
public static boolean isOp(char c) {
if (c == '+') return true;
if (c == '-') return true;
if (c == '*') return true;
if (c == '/') return true;
if (c == '^') return true;
return false;
}
public static Tok getOp(char c) {
if (c == '+') return Tok.PLUS;
if (c == '-') return Tok.MINUS;
if (c == '*') return Tok.TIMES;
if (c == '/') return Tok.DIVIDE;
if (c == '^') return Tok.HAT;
return Tok.UNDEF;
}
}