// ISCNode members public void Evaluate(Scope scope) { Debug.Assert(Left != null && Right != null, "Null operand in binary expression"); Left.Evaluate(scope); Right.Evaluate(scope); switch (Type) { case BinaryExpressionType.ADD: intValue_ = Left.IntValue + Right.IntValue; break; case BinaryExpressionType.SUB: intValue_ = Left.IntValue - Right.IntValue; break; case BinaryExpressionType.MUL: intValue_ = Left.IntValue * Right.IntValue; break; case BinaryExpressionType.DIV: intValue_ = Left.IntValue / Right.IntValue; break; case BinaryExpressionType.MOD: intValue_ = Left.IntValue % Right.IntValue; break; case BinaryExpressionType.ASSIGN: IdentNode identNode = Left as IdentNode; if (identNode == null) throw new InterpreterException("Left operand of '=' must be an lvalue"); if (!scope.IsDefined(identNode.Name)) throw new InterpreterException("Undefined variable: " + identNode.Name); intValue_ = Right.IntValue; scope.Get(identNode.Name).Value = intValue_; break; default: throw new InterpreterException("Unexpected expression type"); } }
// ISCNode members public void Evaluate(Scope scope) { if (!scope.IsDefined(Name)) throw new InterpreterException("Undefined variable: " + Name); intValue_ = scope.Get(Name).Value; }