/// <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); }
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); }
/// <summary> /// Evaluate /// </summary> /// <returns></returns> public object VisitNegate(NegateExpr expr) { return null; }
/// <summary> /// Evaluate /// </summary> /// <returns></returns> public object VisitNegate(NegateExpr expr) { return(EvalHelper.Negate(expr, this)); }
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; }
/// <summary> /// Evaluate /// </summary> /// <returns></returns> public object VisitNegate(NegateExpr expr) { return EvalHelper.Negate(expr, this); }
/// <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; }
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"); }