public override IResultValue Evaluate()
        {
            IResultValue first  = First.Evaluate();
            IResultValue second = Second.Evaluate();

            return(new ResultString(First.Evaluate().ToString() + Second.Evaluate().ToString()));
        }
        public override IResultValue Evaluate()
        {
            IResultValue num1 = First.Evaluate();
            IResultValue num2 = Second.Evaluate();

            double d1 = (double)num1.ToDecimal();
            double d2 = (double)num2.ToDecimal();

            return(new ResultBoolean(!d1.AlmostEqualTo(d2)));
        }
        public override IResultValue Evaluate()
        {
            IResultValue res1 = First.Evaluate();
            IResultValue res2 = Second.Evaluate();

            if (!((double)res1.ToDecimal()).IsInteger(8) || !((double)res2.ToDecimal()).IsInteger(8))
            {
                throw new EvaluationException(this,
                                              "Cannot use floating-point types in modulus calculation.");
            }

            return(new ResultNumberReal((decimal)(res1.ToInteger() % res2.ToInteger())));
        }
        public override Node Evaluate(Env env)
        {
            var a = First.Evaluate(env);
            var b = Second.Evaluate(env);

            if (a is Number && b is Color)
            {
                if (Operator == "*" || Operator == "+")
                {
                    var temp = b;
                    b = a;
                    a = temp;
                }
                else
                {
                    throw new ParsingException("Can't substract or divide a color from a number", Location);
                }
            }

            try
            {
                var operable = a as IOperable;
                if (operable != null)
                {
                    return(operable.Operate(this, b).ReducedFrom <Node>(this));
                }

                if (Operator == "+" && (a is Quoted || a is TextNode) && (b is Quoted || b is TextNode)) // Runge
                {
                    //Quoted qa = a as Quoted;
                    //Quoted qb = b as Quoted;
                    return(new Quoted(a.ToCSS(env) + Operator + b.ToCSS(env), (a is Quoted) ? (a as Quoted).Escaped: false));
                }

                throw new ParsingException(string.Format("Cannot apply operator {0} to the left hand side: {1}", Operator, a.ToCSS(env)), Location);
            }
            catch (DivideByZeroException e)
            {
                throw new ParsingException(e, Location);
            }
            catch (InvalidOperationException e)
            {
                throw new ParsingException(e, Location);
            }
        }
        public override IResultValue Evaluate()
        {
            string       str      = First.Evaluate().ToString();
            IResultValue countIRV = Second.Evaluate();

            if (countIRV.Type != MathType.Integer)
            {
                throw new EvaluationException("That's no integer....");
            }
            int    count = (int)countIRV.ToInteger();
            string res   = "";

            for (int i = 0; i < count; i++)
            {
                res += str;
            }

            return(new ResultString(res));
        }
Example #6
0
        public override Node Evaluate(Env env)
        {
            var a = First.Evaluate(env);
            var b = Second.Evaluate(env);

            if (a is Number && b is Color)
            {
                if (Operator == "*" || Operator == "+")
                {
                    var temp = b;
                    b = a;
                    a = temp;
                }
                else
                {
                    throw new ParsingException("Can't substract or divide a color from a number", Index);
                }
            }

            try
            {
                var operable = a as IOperable;
                if (operable != null)
                {
                    return(operable.Operate(this, b));
                }

                throw new ParsingException(string.Format("Cannot apply operator {0} to the left hand side: {1}", Operator, a.ToCSS(env)), Index);
            }
            catch (DivideByZeroException e)
            {
                throw new ParsingException(e, Index);
            }
            catch (InvalidOperationException e)
            {
                throw new ParsingException(e, Index);
            }

            return(null);
        }
 public override IResultValue Evaluate()
 {
     return(new ResultNumberReal(First.Evaluate().ToDecimal() / Second.Evaluate().ToDecimal()));
 }
 public override IResultValue Evaluate()
 {
     return(new ResultBoolean(First.Evaluate().ToDecimal() <= Second.Evaluate().ToDecimal()));
 }
 public override IResultValue Evaluate()
 {
     return(new ResultBoolean(First.Evaluate().ToBoolean() && Second.Evaluate().ToBoolean()));
 }
Example #10
0
 public override IResultValue Evaluate()
 {
     return(new ResultNumberReal(MathPlus.Pow((double)First.Evaluate().ToDecimal(), (double)Second.Evaluate().ToDecimal())));
 }