summaryrefslogtreecommitdiff
path: root/BJC-Utils2/src/main/java/bjc/utils/dice/ast/OperatorDiceNode.java
blob: 92b49b743f6ca383b57c3d8264cb73b4fb217c15 (plain)
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
package bjc.utils.dice.ast;

// The following classes need to be changed upon addition of a new operator
// 1. DiceASTExpression
// 2. DiceASTFlattener
// 3. DiceASTParser
public enum OperatorDiceNode implements IDiceASTNode {
	ASSIGN, ADD, SUBTRACT, MULTIPLY, DIVIDE, GROUP, COMPOUND;
	
	@Override
	public boolean isOperator() {
		return true;
	}
	
	public static OperatorDiceNode fromString(String s) {
		switch(s) {
			case ":=":
				return ASSIGN;
			case "+":
				return ADD;
			case "-":
				return SUBTRACT;
			case "*":
				return MULTIPLY;
			case "/":
				return DIVIDE;
			case "d":
				return GROUP;
			case "c":
				return COMPOUND;
			default:
				throw new IllegalArgumentException(s + " is not a valid operator node");
		}
	}
}