-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOpType.java
More file actions
70 lines (59 loc) · 1.2 KB
/
OpType.java
File metadata and controls
70 lines (59 loc) · 1.2 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
// Allison Schinagle
// CS265 Assignment 3
/**
* Enum defining the the seven operations and their precedence. Highest
* precedence is 2, which is parentheses, next highest is multiplication,
* division, and modulo with a precedence of 1, and then addition and
* subtraction with a precedence of 0.
*/
public enum OpType
{
/**
* Left parens. "("
*/
L_PAR (2),
/**
* Right parens. ")"
*/
R_PAR(2),
/**
* Multiplication. "*"
*/
MUL (1),
/**
* Division. "/"
*/
DIV (1),
/**
* Modulo. "%"
*/
MOD (1),
/**
* Addition. "+"
*/
ADD (0),
/**
* Subtraction. "-"
*/
SUB (0);
/**
* The precedence of the operator. Higher number = higher precedence.
*/
private final int precedence;
/**
* Constructs the OpType with its precedence.
*
* @param prec the precedence of the OpType
*/
OpType(int prec) {
this.precedence = prec;
}
/**
* Return the precedence of the OpType this method is called on.
*
* @return the OpType's precedence as an int
*/
int getPrecedence() {
return this.precedence;
}
}