Example #1
0
        /// <summary>
        /// Creates a unary expression with symbol scope, context, script refernce set.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Expr Negate(Expr expr, TokenData token)
        {
            var exp = new NegateExpr();

            exp.Expression = expr;
            SetupContext(exp, token);
            return(exp);
        }
Example #2
0
        public static object Negate(NegateExpr expr, IAstVisitor visitor)
        {
            var result = expr.Expression.Visit(visitor) as LObject;

            if (result == null)
            {
                throw ExceptionHelper.BuildRunTimeException(expr, "Null value encountered");
            }

            // Negate number.
            if (result.Type == LTypes.Number)
            {
                var retVal = ((LNumber)result).Value;
                retVal = retVal * -1;
                return(new LNumber(retVal));
            }
            throw ExceptionHelper.BuildRunTimeException(expr, "Can only convert a number to a negative value");
        }
 /// <summary>
 /// Evaluate
 /// </summary>
 /// <returns></returns>
 public object VisitNegate(NegateExpr expr)
 {
     return(null);
 }
Example #4
0
 /// <summary>
 /// Evaluate
 /// </summary>
 /// <returns></returns>
 public object VisitNegate(NegateExpr expr)
 {
     return null;
 }
Example #5
0
 /// <summary>
 /// Evaluate
 /// </summary>
 /// <returns></returns>
 public object VisitNegate(NegateExpr expr)
 {
     return(EvalHelper.Negate(expr, this));
 }
Example #6
0
        protected IType CheckExpr(NegateExpr expr)
        {
            IType a = CheckExpr(expr.Expr1);

            if (!(a is BoolType || a is NumericType))
            {
                AddError(String.Format("Negation not possible. Incompatible type: '{0}', Only bool and numerical types are supported.",
                    a.ToString()), true, expr.SourcePosition);

                return UnknownType.Instance;
            }

            return a;
        }
Example #7
0
 /// <summary>
 /// Evaluate
 /// </summary>
 /// <returns></returns>
 public object VisitNegate(NegateExpr expr)
 {
     return EvalHelper.Negate(expr, this);
 }
Example #8
0
 /// <summary>
 /// Creates a unary expression with symbol scope, context, script refernce set.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Expr Negate(Expr expr, TokenData token)
 {
     var exp = new NegateExpr();
     exp.Expression = expr;
     SetupContext(exp, token);
     return exp;
 }
Example #9
0
        public static object Negate(NegateExpr expr, IAstVisitor visitor)
        {
            var result = expr.Expression.Visit(visitor) as LObject;
            if (result == null)
                throw ExceptionHelper.BuildRunTimeException(expr, "Null value encountered");

            // Negate number.
            if(result.Type == LTypes.Number)
            {
                var retVal = ((LNumber) result).Value;
                retVal = retVal*-1;
                return new LNumber(retVal);
            }
            throw ExceptionHelper.BuildRunTimeException(expr, "Can only convert a number to a negative value");
        }