diff options
| author | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-28 08:44:54 -0400 |
|---|---|---|
| committer | bculkin2442 <bjculkin@mix.wvu.edu> | 2016-03-28 08:44:54 -0400 |
| commit | 78d9c539e25f16fd15f06c2b2c48c0ad37a21540 (patch) | |
| tree | 52d5db559d390c2fb83d4a4cd3bbfa4344c482e8 /dice-lang/src/bjc/utils/dice/BindingDiceExpression.java | |
| parent | 1a020352bdcbb6b5279b703f93e42a1eb7071e36 (diff) | |
Imported dice stuff from general utils into dedicated project
Diffstat (limited to 'dice-lang/src/bjc/utils/dice/BindingDiceExpression.java')
| -rw-r--r-- | dice-lang/src/bjc/utils/dice/BindingDiceExpression.java | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/dice-lang/src/bjc/utils/dice/BindingDiceExpression.java b/dice-lang/src/bjc/utils/dice/BindingDiceExpression.java new file mode 100644 index 0000000..9ecce97 --- /dev/null +++ b/dice-lang/src/bjc/utils/dice/BindingDiceExpression.java @@ -0,0 +1,77 @@ +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 { + /** + * The expression being bound to a name + */ + private IDiceExpression exp; + + /** + * The name to bind the expression to + */ + private String name; + + /** + * Create a new dice expression binder from two expressions and an + * enviroment + * + * @param left + * The left side expression to get a name from. Must be a + * ReferenceDiceExpression + * @param right + * The right side to bind to the name + * @param env + * The enviroment to bind into + */ + public BindingDiceExpression(IDiceExpression left, + IDiceExpression right, Map<String, IDiceExpression> env) { + this(((ReferenceDiceExpression) left).getName(), right, env); + } + + /** + * 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); + } + + /* + * (non-Javadoc) + * + * @see bjc.utils.dice.IDiceExpression#roll() + */ + @Override + public int roll() { + return exp.roll(); + } + + /* + * (non-Javadoc) + * + * @see java.lang.Object#toString() + */ + @Override + public String toString() { + return "assign[n=" + name + ", exp=" + exp.toString() + "]"; + } +} |
