Example #1
0
        public override void Evaluate()
        {
            Expression e           = new Expression(RegexMatch.Groups[2].Value, ParentContext);
            bool       untilClause = (RegexMatch.Groups[1].Value.Trim().ToUpper() == "UNTIL");

            if (!untilClause)
            {
                waitTime = e.Float();
            }
            else
            {
                waitExpression = e;
            }

            State = ExecutionState.WAIT;
        }
Example #2
0
        // Evaluate and return the value of the part of an expression that this instance represents
        public object GetValue()
        {
            if (EvalDlg != null)
            {
                EvalDlg();
            }

            if (SpecialValue != null)
            {
                if (string.IsNullOrEmpty(Suffix))
                {
                    return(SpecialValue.ToString());
                }
                else
                {
                    return(SpecialValue.GetSuffix(Suffix));
                }
            }

            if (LeftSide == null)
            {
                if (Variable != null && !IsStatic)
                {
                    return(Variable.Value);
                }
                else
                {
                    return(Value);
                }
            }
            else
            {
                if (Operator == "AND")
                {
                    return(LeftSide.Bool() && RightSide.Bool());
                }
                if (Operator == "OR")
                {
                    return(LeftSide.Bool() || RightSide.Bool());
                }

                if (LeftSide.Value is String || RightSide.Value is String)
                {
                    if (Operator == "+")
                    {
                        return(LeftSide.Value.ToString() + RightSide.Value.ToString());
                    }

                    if (Operator == "==")
                    {
                        return(LeftSide.Value.ToString() == RightSide.Value.ToString());
                    }
                    if (Operator == "=")
                    {
                        return(LeftSide.Value.ToString() == RightSide.Value.ToString());
                    }
                    if (Operator == "!=")
                    {
                        return(LeftSide.Value.ToString() != RightSide.Value.ToString());
                    }
                }

                if (LeftSide.Value is float || RightSide.Value is float)
                {
                    if (Operator == "+")
                    {
                        return(LeftSide.Float() + RightSide.Float());
                    }
                    if (Operator == "-")
                    {
                        return(LeftSide.Float() - RightSide.Float());
                    }
                    if (Operator == "/")
                    {
                        return(LeftSide.Float() / RightSide.Float());
                    }
                    if (Operator == "*")
                    {
                        return(LeftSide.Float() * RightSide.Float());
                    }
                    if (Operator == "^")
                    {
                        return((float)Math.Pow(LeftSide.Double(), RightSide.Double()));
                    }

                    if (Operator == "<")
                    {
                        return(LeftSide.Float() < RightSide.Float());
                    }
                    if (Operator == ">")
                    {
                        return(LeftSide.Float() > RightSide.Float());
                    }
                    if (Operator == "<=")
                    {
                        return(LeftSide.Float() <= RightSide.Float());
                    }
                    if (Operator == ">=")
                    {
                        return(LeftSide.Float() >= RightSide.Float());
                    }
                    if (Operator == "==")
                    {
                        return(LeftSide.Float() == RightSide.Float());
                    }
                    if (Operator == "=")
                    {
                        return(LeftSide.Float() == RightSide.Float());
                    }
                    if (Operator == "!=")
                    {
                        return(LeftSide.Float() != RightSide.Float());
                    }
                }

                if (LeftSide.Value is Direction && RightSide.Value is Direction)
                {
                    if (Operator == "*")
                    {
                        return((Direction)LeftSide.GetValue() * (Direction)RightSide.GetValue());
                    }
                    if (Operator == "+")
                    {
                        return((Direction)LeftSide.GetValue() + (Direction)RightSide.GetValue());
                    }
                    if (Operator == "-")
                    {
                        return((Direction)LeftSide.GetValue() + (Direction)RightSide.GetValue());
                    }
                }
            }

            throw new kOSException("Expression error.");
        }
Example #3
0
        // Evaluate and return the value of the part of an expression that this instance represents
        public object GetValue()
        {
            if (LeftSide == null)
            {
                if (Variable != null && !IsStatic)
                {
                    return(Variable.Value);
                }
                else
                {
                    return(Value);
                }
            }
            else
            {
                if (LeftSide.Value is String || RightSide.Value is String)
                {
                    if (Operator == "+")
                    {
                        return(LeftSide.Value.ToString() + RightSide.Value.ToString());
                    }
                }

                if (LeftSide.Value is float || RightSide.Value is float)
                {
                    if (Operator == "+")
                    {
                        return(LeftSide.Float() + RightSide.Float());
                    }
                    if (Operator == "-")
                    {
                        return(LeftSide.Float() - RightSide.Float());
                    }
                    if (Operator == "/")
                    {
                        return(LeftSide.Float() / RightSide.Float());
                    }
                    if (Operator == "*")
                    {
                        return(LeftSide.Float() * RightSide.Float());
                    }
                    if (Operator == "^")
                    {
                        return((float)Math.Pow(LeftSide.Double(), RightSide.Double()));
                    }

                    if (Operator == "<")
                    {
                        return(LeftSide.Float() < RightSide.Float());
                    }
                    if (Operator == ">")
                    {
                        return(LeftSide.Float() > RightSide.Float());
                    }
                    if (Operator == "<=")
                    {
                        return(LeftSide.Float() <= RightSide.Float());
                    }
                    if (Operator == ">=")
                    {
                        return(LeftSide.Float() >= RightSide.Float());
                    }
                    if (Operator == "==")
                    {
                        return(LeftSide.Float() == RightSide.Float());
                    }
                    if (Operator == "=")
                    {
                        return(LeftSide.Float() == RightSide.Float());
                    }
                    if (Operator == "!=")
                    {
                        return(LeftSide.Float() != RightSide.Float());
                    }
                }

                if (LeftSide.Value is Direction && RightSide.Value is Direction)
                {
                    if (Operator == "*")
                    {
                        return((Direction)LeftSide.Value * (Direction)RightSide.Value);
                    }
                    if (Operator == "+")
                    {
                        return((Direction)LeftSide.Value + (Direction)RightSide.Value);
                    }
                    if (Operator == "-")
                    {
                        return((Direction)LeftSide.Value + (Direction)RightSide.Value);
                    }
                }
            }

            throw new kOSException("Expression error.");
        }
Example #4
0
        public override void Evaluate()
        {
            Expression e = new Expression(RegexMatch.Groups[2].Value, ParentContext);
            bool untilClause = (RegexMatch.Groups[1].Value.Trim().ToUpper() == "UNTIL");

            if (!untilClause)
            {
                waitTime = e.Float();
            }
            else
            {
                waitExpression = e;
            }

            State = ExecutionState.WAIT;
        }