blob: a715074522b1520f1278f658bc2a9ba6c220c687 (
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
36
37
38
39
40
41
42
43
44
45
46
47
48
|
package bjc.utils.dice;
import java.util.Map;
/**
* A variable expression that represents binding a variable to a name in an
* enviroment
*
* @author ben
*
*/
public class BindingDiceExpression implements IDiceExpression {
private String name;
private IDiceExpression exp;
/**
* Create a new dice expression binder
*
* @param name
* The name of the variable to bind
* @param exp
* The expression to bind to the variable
* @param env
* The enviroment to bind it in
*/
public BindingDiceExpression(String name, IDiceExpression exp,
Map<String, IDiceExpression> env) {
this.name = name;
this.exp = exp;
env.put(name, exp);
}
public BindingDiceExpression(IDiceExpression left,
IDiceExpression right, Map<String, IDiceExpression> env) {
this(((ReferenceDiceExpression) left).getName(), right, env);
}
@Override
public int roll() {
return exp.roll();
}
@Override
public String toString() {
return "assign[n=" + name + ", exp=" + exp.toString() + "]";
}
}
|