Beispiel #1
0
        private LNumber IncrementNumber(LNumber val)
        {
            this.DataType = typeof(double);
            var inc = this.Increment == 0 ? 1 : this.Increment;
            if (this.Expression != null)
            {
                var incval = this.Expression.Evaluate();
                // TODO: Check if null and throw langexception?
                inc = ((LNumber)incval).Value;
            }

            // 1. Calculate the unary value
            val = EvalHelper.CalcUnary(val, Op, inc);

            // 2. Set the value back into scope
            this.Value = val;
            this.Ctx.Memory.SetValue(this.Name, val);
            return val;
        }
Beispiel #2
0
 /// <summary>
 /// Evalulates a math expression of 2 numbers.
 /// </summary>
 /// <param name="node">The AST node the evaluation is a part of.</param>
 /// <param name="lhs">The number on the left hand side</param>
 /// <param name="rhs">The number on the right hand side</param>
 /// <param name="op">The math operator.</param>
 /// <returns></returns>
 public static LNumber CalcNumbers(AstNode node, LNumber lhs, LNumber rhs, Operator op)
 {
     var left = lhs.Value;
     var right = rhs.Value;
     var result = 0.0;
     if (op == Operator.Multiply)
     {
         result = left * right;
     }
     else if (op == Operator.Divide)
     {
         result = left / right;
     }
     else if (op == Operator.Add)
     {
         result = left + right;
     }
     else if (op == Operator.Subtract)
     {
         result = left - right;
     }
     else if (op == Operator.Modulus)
     {
         result = left % right;
     }
     return new LNumber(result);
 }
Beispiel #3
0
 /// <summary>
 /// Increments the number supplied.
 /// </summary>
 /// <param name="num"></param>
 /// <param name="op"></param>
 /// <param name="increment"></param>
 /// <returns></returns>
 public static LNumber CalcUnary(LNumber num, Operator op, double increment)
 {
     var val = num.Value;
     if (op == Operator.PlusPlus)
     {
         val++;
     }
     else if (op == Operator.MinusMinus)
     {
         val--;
     }
     else if (op == Operator.PlusEqual)
     {
         val = val + increment;
     }
     else if (op == Operator.MinusEqual)
     {
         val = val - increment;
     }
     else if (op == Operator.MultEqual)
     {
         val = val * increment;
     }
     else if (op == Operator.DivEqual)
     {
         val = val / increment;
     }
     return new LNumber(val);
 }
Beispiel #4
0
 /// <summary>
 /// Evaluates a math expression of 2 time spans.
 /// </summary>
 /// <param name="node">The AST node the evaluation is a part of.</param>
 /// <param name="lhs">The time on the left hand side</param>
 /// <param name="rhs">The time on the right hand side</param>
 /// <param name="op">The math operator.</param>
 /// <returns></returns>
 public static LBool CompareNumbers(AstNode node, LNumber lhs, LNumber rhs, Operator op)
 {
     var left = lhs.Value;
     var right = rhs.Value;
     var result = false;
     if (op == Operator.LessThan)            result = left < right;
     else if (op == Operator.LessThanEqual)  result = left <= right;
     else if (op == Operator.MoreThan)       result = left > right;
     else if (op == Operator.MoreThanEqual)  result = left >= right;
     else if (op == Operator.EqualEqual)     result = left == right;
     else if (op == Operator.NotEqual)       result = left != right;
     return new LBool(result);
 }
Beispiel #5
0
        public static LNumber IncrementNumber(UnaryExpr expr, LNumber val, IAstVisitor visitor)
        {
            var inc = expr.Increment == 0 ? 1 : expr.Increment;
            if (expr.Expression != null)
            {
                var incval = expr.Expression.Evaluate(visitor);
                // TODO: Check if null and throw langexception?
                inc = ((LNumber)incval).Value;
            }

            // 1. Calculate the unary value
            val = ComLib.Lang.Runtime.EvalHelper.CalcUnary(val, expr.Op, inc);

            // 2. Set the value back into scope
            expr.Ctx.Memory.SetValue(expr.Name, val);
            return val;
        }