|
|
|
@ -5,13 +5,18 @@ tree.Operation = function Operation(op, operands) {
|
|
|
|
|
this.operands = operands;
|
|
|
|
|
};
|
|
|
|
|
tree.Operation.prototype.eval = function (env) {
|
|
|
|
|
var a = this.operands[0],
|
|
|
|
|
b = this.operands[1],
|
|
|
|
|
var a = this.operands[0].eval(env),
|
|
|
|
|
b = this.operands[1].eval(env),
|
|
|
|
|
temp;
|
|
|
|
|
|
|
|
|
|
if (a instanceof tree.Dimension) {
|
|
|
|
|
temp = b, b = a, a = temp;
|
|
|
|
|
if (a instanceof tree.Dimension && b instanceof tree.Color) {
|
|
|
|
|
if (this.op === '*' || this.op === '+') {
|
|
|
|
|
temp = b, b = a, a = temp;
|
|
|
|
|
} else {
|
|
|
|
|
throw { name: "OperationError",
|
|
|
|
|
message: "Can't substract or divide a color from a number" };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return a.eval(env).operate(this.op, b.eval(env));
|
|
|
|
|
return a.operate(this.op, b);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|