Пример #1
0
		// 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");
			}
		}
Пример #2
0
		// ISCNode members
		public void Evaluate(Scope scope)
		{
			if (!scope.IsDefined(Name))
				throw new InterpreterException("Undefined variable: " + Name);
			intValue_ = scope.Get(Name).Value;
		}