Exemple #1
0
    public override Value Eval(Environment env)
    {
        Value lv = left.Eval(env);
        Value rv = right.Eval(env);

        if (typeof(StringVal).IsInstanceOfType(lv))
        {
            if (typeof(StringVal).IsInstanceOfType(rv))
            {
                return(new StringVal(((StringVal)(lv)).stringVal + ((StringVal)(rv)).stringVal));
            }
        }
        else if (typeof(IntVal).IsInstanceOfType(lv))
        {
            if (typeof(IntVal).IsInstanceOfType(rv))
            {
                return(new IntVal(((IntVal)(lv)).intVal + ((IntVal)(rv)).intVal));
            }
            lv = new FloatVal((IntVal)lv);
        }
        if (typeof(FloatVal).IsInstanceOfType(lv))
        {
            if (typeof(IntVal).IsInstanceOfType(rv))
            {
                rv = new FloatVal((IntVal)rv);
            }
            if (typeof(FloatVal).IsInstanceOfType(rv))
            {
                return(new FloatVal(((FloatVal)(lv)).floatVal + ((FloatVal)(rv)).floatVal));
            }
        }
        throw new TypeMismatchException("types cannot be added!");
    }
Exemple #2
0
    public override Value Eval(Environment env)
    {
        Value lv = left.Eval(env);
        Value rv = right.Eval(env);

        if (typeof(IntVal).IsInstanceOfType(lv))
        {
            if (typeof(IntVal).IsInstanceOfType(rv))
            {
                return(new IntVal(((IntVal)(lv)).intVal - ((IntVal)(rv)).intVal));
            }
            lv = new FloatVal((IntVal)lv);
        }
        if (typeof(FloatVal).IsInstanceOfType(lv))
        {
            if (typeof(IntVal).IsInstanceOfType(rv))
            {
                rv = new FloatVal((IntVal)rv);
            }
            if (typeof(FloatVal).IsInstanceOfType(rv))
            {
                return(new FloatVal(((FloatVal)(lv)).floatVal - ((FloatVal)(rv)).floatVal));
            }
        }
        throw new TypeMismatchException("must both be numbers!");
    }
    public override Value Eval(Environment env)
    {
        Value lv = left.Eval(env);
        Value rv = right.Eval(env);

        if (typeof(IntVal).IsInstanceOfType(lv))
        {
            if (typeof(IntVal).IsInstanceOfType(rv))
            {
                int li = ((IntVal)(lv)).intVal;
                int ri = ((IntVal)(rv)).intVal;
                return(new IntVal(li * ri));
            }
            else
            {
                lv = new FloatVal((IntVal)lv);
            }
        }
        if (typeof(FloatVal).IsInstanceOfType(lv) && typeof(FloatVal).IsInstanceOfType(rv))
        {
            float lf = ((FloatVal)lv).floatVal;
            float rf = ((FloatVal)rv).floatVal;
            return(new FloatVal(lf * rf));
        }
        else
        {
            throw new TypeMismatchException("must both be numbers!");
        }
    }
Exemple #4
0
    public override Value Eval(Environment env)
    {
        Value lv = left.Eval(env);
        Value rv = right.Eval(env);

        if (typeof(IntVal).IsInstanceOfType(lv))
        {
            lv = new FloatVal((IntVal)lv);
        }
        if (typeof(IntVal).IsInstanceOfType(rv))
        {
            rv = new FloatVal((IntVal)rv);
        }
        if (typeof(FloatVal).IsInstanceOfType(lv) && typeof(FloatVal).IsInstanceOfType(rv))
        {
            float lf = ((FloatVal)lv).floatVal;
            float rf = ((FloatVal)rv).floatVal;
            if (rf == 0)
            {
                throw new DivideByZeroException("cannot divide by zero!");
            }
            return(new FloatVal(lf / rf));
        }
        else
        {
            throw new TypeMismatchException("must both be numbers!");
        }
    }
 protected bool Equals(PrimitivesReferenceModel other)
 {
     return(string.Equals(StringVal, other.StringVal) && IntVal == other.IntVal &&
            BooleanVal == other.BooleanVal && ByteVal == other.ByteVal && LongVal == other.LongVal &&
            FloatVal.Equals(other.FloatVal) && DoubleVal.Equals(other.DoubleVal) &&
            DateTimeVal.Equals(other.DateTimeVal) && ShortVal == other.ShortVal &&
            UShortVal == other.UShortVal && UIntVal == other.UIntVal && ULongVal == other.ULongVal &&
            SByteVal == other.SByteVal && CharVal == other.CharVal);
 }
    public override Value Eval(Environment env)
    {
        Value lv = left.Eval(env);
        Value rv = right.Eval(env);

        if (typeof(NumVal).IsInstanceOfType(lv) && typeof(NumVal).IsInstanceOfType(rv))
        {
            FloatVal f1 = new FloatVal((NumVal)lv);
            FloatVal f2 = new FloatVal((NumVal)rv);
            return(new FloatVal((float)(Math.Pow(f1.floatVal, f2.floatVal))));
        }
        throw new TypeMismatchException("must both be numbers!");
    }
 public override int GetHashCode()
 {
     unchecked
     {
         var hashCode = (StringVal != null ? StringVal.GetHashCode() : 0);
         hashCode = (hashCode * 397) ^ IntVal;
         hashCode = (hashCode * 397) ^ BooleanVal.GetHashCode();
         hashCode = (hashCode * 397) ^ ByteVal.GetHashCode();
         hashCode = (hashCode * 397) ^ LongVal.GetHashCode();
         hashCode = (hashCode * 397) ^ FloatVal.GetHashCode();
         hashCode = (hashCode * 397) ^ DoubleVal.GetHashCode();
         hashCode = (hashCode * 397) ^ DateTimeVal.GetHashCode();
         hashCode = (hashCode * 397) ^ ShortVal.GetHashCode();
         hashCode = (hashCode * 397) ^ UShortVal.GetHashCode();
         hashCode = (hashCode * 397) ^ (int)UIntVal;
         hashCode = (hashCode * 397) ^ ULongVal.GetHashCode();
         hashCode = (hashCode * 397) ^ SByteVal.GetHashCode();
         hashCode = (hashCode * 397) ^ CharVal.GetHashCode();
         return(hashCode);
     }
 }