Exemple #1
0
        public override object Visit(TernaryNode obj)
        {
            object condition = obj.Condition.Accept(this);
            bool   b         = ScriptTypeUtil.EvalToBoolean(condition);

            return(b ? obj.TrueValue.Accept(this) : obj.FalseValue.Accept(this));
        }
Exemple #2
0
        private bool Logic(OperatorNode obj)
        {
            bool lhs = ScriptTypeUtil.EvalToBoolean(obj.Lhs.Accept(this));

            //Note: Short cut Rhs
            if (lhs && obj.Token.TokenValue == "||")
            {
                return(true);
            }
            if (!lhs && obj.Token.TokenValue == "&&")
            {
                return(false);
            }
            //Note: Eval Rhs
            bool rhs = ScriptTypeUtil.EvalToBoolean(obj.Rhs.Accept(this));

            if (obj.Token.TokenValue == "||")
            {
                return(lhs || rhs);
            }
            if (obj.Token.TokenValue == "&&")
            {
                return(lhs && rhs);
            }

            ExceptionHelper.ThrowBinaryOperatorInvalid(obj.Token.TokenValue, lhs, rhs);
            return(false);
        }
Exemple #3
0
        public override object Visit(UnaryNode obj)
        {
            object val = obj.OperandNode.Accept(this);

            if (obj.Token.TokenValue == "!")
            {
                bool b = ScriptTypeUtil.EvalToBoolean(val);
                return(!b);
            }

            if (val == null)
            {
                ExceptionHelper.ThrowEvalNull();
            }

            if (obj.Token.TokenValue == "+")
            {
                return(val);
            }

            if (obj.Token.TokenValue == "-")
            {
                if (ScriptTypeUtil.IsDecimal(val))
                {
                    decimal result = ScriptTypeUtil.ConvertToDecimal(val);
                    return(-result);
                }

                if (ScriptTypeUtil.IsLong(val))
                {
                    long result = ScriptTypeUtil.ConvertToLong(val);
                    return(-result);
                }
            }

            ExceptionHelper.ThrowUnaryOperatorInvalid(obj.Token.TokenValue, val);
            return(null);
        }
 public bool EvalToBool(object val)
 {
     return(ScriptTypeUtil.EvalToBoolean(val));
 }