private Value Addition(AdditionNode exp) { try { Constant left = Eval(exp.Left).GetRValue(); Constant right = Eval(exp.Right).GetRValue(); Constant.Type leftType = left.ConstantType; Constant.Type rightType = right.ConstantType; Constant.Type bt = Max(leftType, rightType); switch (bt) { case Constant.Type.Complex: { ComplexValue l = (ComplexValue)Convert(left, bt); ComplexValue r = (ComplexValue)Convert(right, bt); return(ComplexValue.OpAdd(l, r)); } case Constant.Type.Int: { IntValue l = (IntValue)Convert(left, bt); IntValue r = (IntValue)Convert(right, bt); return(IntValue.OpAdd(l, r)); } case Constant.Type.Float: { FloatValue l = (FloatValue)Convert(left, bt); FloatValue r = (FloatValue)Convert(right, bt); return(FloatValue.OpAdd(l, r)); } case Constant.Type.String: { StringValue l = (StringValue)Convert(left, bt); StringValue r = (StringValue)Convert(right, bt); return(StringValue.OpAdd(l, r)); } } throw new ModelInterpreterException("Сложение не определено для типа \"" + bt.ToString() + "\".") { Line = exp.Line, Position = exp.Position }; } catch (TypeConversionError exc) { throw new ModelInterpreterException($"Не удалось преобразование из \"{exc.Src}\" в \"{exc.Dst}\"") { Line = exp.Line, Position = exp.Position }; } catch (ModelInterpreterException exc) { throw exc; } catch (Exception exc) { throw new ModelInterpreterException(exc.Message) { Line = exp.Line, Position = exp.Position }; } }