示例#1
0
        // check 2 value is equal ////////////////////////////////////////////////////////////////////////////////////////////////////
        static public bool IsEqual(VarInfo var1, VarInfo var2)
        {
            if (var1.isNull || var2.isNull)
            {
                return(false);
            }

            if (var1.type != var2.type)
            {
                return(false);
            }

            switch (var1.type)
            {
            case DataType.FA_Boolean:
            {
                return(var1.toCS_bool() == var2.toCS_bool());
            }

            case DataType.FA_String:
            {
                return(var1.toCS_String() == var2.toCS_String());
            }

            case DataType.FA_Number:
            {
                const double epsilon = 1e-9;
                return(Math.Abs(var1.toCS_Double() - var2.toCS_Double()) <= epsilon);
            }
            }
            return(false);
        }
示例#2
0
        static public VarInfo XorNum(List <VarInfo> parameters)
        {
            if (parameters.Count == 0)
            {
                return(VarInfo.NullVal);
            }

            int temp = parameters[0].toCS_Int();

            foreach (var parameter in parameters)
            {
                try
                {
                    if (parameter.type == DataType.FA_Number && !parameter.isNull)
                    {
                        temp ^= parameter.toCS_Int();
                    }
                    else
                    {
                        return(VarInfo.NullVal);
                    }
                }
                catch
                {
                    return(VarInfo.NullVal);
                }
            }

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#3
0
        static public VarInfo IsNumber(List <VarInfo> parameters)
        {
            if (parameters.Count != 1)
            {
                return(VarInfo.NullVal);
            }

            if (parameters[0].isNull)
            {
                return(VarInfo.NullVal);
            }

            bool   temp;
            string value = parameters[0].value;

            try
            {
                double.Parse(value);
                temp = true;
            }
            catch
            {
                temp = false;
            }

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#4
0
        public VarInfo HandleExpression(string expression, out string ErrorReport)
        {
            VarInfo temp = VarInfo.NullVal;

            expression  = RemoveSpacing(expression);
            ErrorReport = "";

            if (expression == "")
            {
                return(VarInfo.NullVal);
            }

            temp = HandleConst(expression);
            if (!temp.isNull)
            {
                return(temp);
            }

            temp = HandleVariable(expression);
            if (!temp.isNull)
            {
                return(temp);
            }

            temp = HandleFunction(expression);
            if (!temp.isNull)
            {
                return(temp);
            }

            ErrorReport = "Error: Illegal Expression";
            return(VarInfo.NullVal);
        }
示例#5
0
 public VarInfo(VarInfo instance)
 {
     this.type   = instance.type;
     this.value  = instance.value;
     this.value  = StandardizeValue(this.value, this.type);
     this.isNull = instance.isNull;
 }
示例#6
0
        static public VarInfo Average(List <VarInfo> parameters)
        {
            double temp = 0;

            foreach (var parameter in parameters)
            {
                if (parameter.type == DataType.FA_Number && !parameter.isNull)
                {
                    temp += parameter.toCS_Double();
                }
                else
                {
                    return(VarInfo.NullVal);
                }
            }

            if (parameters.Count == 0)
            {
                return(VarInfo.NullVal);
            }

            temp /= parameters.Count;

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#7
0
        static public VarInfo Random(List <VarInfo> parameters)
        {
            if (CheckParameterTypes(parameters, "NN"))
            {
                int    x = (int)parameters[0].toCS_Double();
                int    y = (int)parameters[1].toCS_Double();
                double temp;

                try
                {
                    temp = random.Next(x, y + 1);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            if (CheckParameterTypes(parameters, "N"))
            {
                int    x = (int)parameters[0].toCS_Double();
                double temp;

                try
                {
                    temp = random.Next(x);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            if (CheckParameterTypes(parameters, ""))
            {
                double temp;

                try
                {
                    temp = random.Next();
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            return(VarInfo.NullVal);
        }
示例#8
0
        private bool ResetFlow()
        {
            State           = FlowRunState.Start;
            LastBlockResult = null;
            CurrentBlock    = null;
            FlowData.ClearData();

            return(true);
        }
示例#9
0
文件: frmScan.cs 项目: lhmson/FlowArt
        private bool ValidValue()
        {
            if (dataType == DataType.FA_Boolean)
            {
                return(true);
            }

            string value = tbValue.Text;

            return(VarInfo.ValidValue(value, dataType));
        }
示例#10
0
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////
        // Handle blocks /////////////////////////////////////////////////////////////////////////////////////////////////
        //////////////////////////////////////////////////////////////////////////////////////////////////////////////////


        // handle blocks behavior and return value of blocks if available
        private VarInfo HandleBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map         = form.ActiveMdiChild as FlowMap;
            VarInfo BlockResult = null;

            ErrorReport = "";

            MainInterface.Instance.UserLog("--> " + CurrentBlock.Kind.ToString() + " Block: " + CurrentBlock.Text, LogType.Normal);

            switch (CurrentBlock.Kind)
            {
            case BlockType.Start:
            {
                BlockResult = HandleStartBlock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.End:
            {
                BlockResult = HandleEndBlock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.Process:
            {
                BlockResult = HandleProcessBlock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.Input:
            {
                BlockResult = HandleInputBlock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.Output:
            {
                BlockResult = HandleOutputblock(CurrentBlock, out ErrorReport);
                break;
            }

            case BlockType.Condition:
            {
                BlockResult = HandleConditionBlock(CurrentBlock, out ErrorReport);
                break;
            }
            }

            UpdateWatch();
            return(BlockResult);
        }
示例#11
0
        public FlowBlock GetNextBlock(FlowBlock CurrentBlock, VarInfo blockResult, out string ErrorReport)
        {
            if( CurrentBlock == null )
                return GetStartBlock(out ErrorReport);
            ErrorReport = "";

            if(CurrentBlock.Kind == BlockType.End)
            {
                return null;
            }

            List<IGoLink> OutLinks = new List<IGoLink>();
            OutLinks.Clear();
            foreach(IGoLink link in CurrentBlock.Links)
            {
                if( (link.FromNode as FlowBlock).GetHashCode() == CurrentBlock.GetHashCode() )
                    OutLinks.Add(link);
            }

            if( OutLinks.Count < 1 )
            {
                ErrorReport = "Error: No out-link is found";
                return null;
            }

            if(CurrentBlock.Kind == BlockType.Condition)
            {
                OutLinks[0] = PickLinkFromConditionBlock(OutLinks, blockResult, out ErrorReport);
                if( ErrorReport != "" )
                    return null;
            }
            else
            if( OutLinks.Count > 1 )
            {
                ErrorReport = "Error: Regular blocks should only have ONE out-link";
                return null;
            }

            if(OutLinks[0] != null)
            {
                return OutLinks[0].ToNode as FlowBlock;
            }
            else
            {
                // already handled before ;)
                return null;
            }
        }
示例#12
0
        private VarInfo HandleConditionBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map = form.ActiveMdiChild as FlowMap;

            ErrorReport = "";

            string  expression = CurrentBlock.Text;
            VarInfo varRes     = FlowData.HandleExpression(expression, out ErrorReport);

            if (ErrorReport != "")
            {
                return(null);
            }

            MainInterface.Instance.UserLog("Value: " + CurrentBlock.Text + " = " + varRes.value, LogType.Normal);
            return(varRes);
        }
示例#13
0
        private VarInfo HandleProcessBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map = form.ActiveMdiChild as FlowMap;

            ErrorReport = "";

            string expression = CurrentBlock.Text;

            if (CurrentBlock.Text == "")
            {
                ErrorReport = "Blank expression";
                return(null);
            }

            // handle deletion
            if (CurrentBlock.Text[0] == '~')
            {
                FlowData.HandleDeletion(expression, out ErrorReport);
                if (ErrorReport != "")
                {
                    return(null);
                }

                MainInterface.Instance.UserLog("Deletion: " + expression.Remove(0, 1), LogType.Normal);
                return(null);
            }

            VarInfo varRes = FlowData.HandleAssignment(expression, out ErrorReport);

            if (ErrorReport != "")
            {
                return(null);
            }

            if (!varRes.isNull)
            {
                MainInterface.Instance.UserLog("Assignment: " + CurrentBlock.Text + " = " + varRes.value, LogType.Normal);
            }
            else
            {
                MainInterface.Instance.UserLog("Declaration: " + CurrentBlock.Text, LogType.Normal);
            }

            return(varRes);
        }
示例#14
0
        static public VarInfo ToString(List <VarInfo> parameters)
        {
            string x    = parameters[0].toCS_String();
            var    temp = "";

            try
            {
                temp = x;
            }
            catch
            {
                return(VarInfo.NullVal);
            }

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#15
0
        //------------------------------------------------------------------------------------------------------------------------------------------------------
        // declare variables -----------------------------------------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------------------------------------------------------------
        public void DeclareVariable(string varName, DataType dataType, out string ErrorReport)
        {
            if (!ValidName(varName))
            {
                ErrorReport = "Error: Invalid variable name: " + varName;
                return;
            }

            if (Exist(varName))
            {
                ErrorReport = "Error: Duplicate variable name: " + varName;
                return;
            }

            ErrorReport = "";
            VarInfo temp = new VarInfo(dataType, "", true);

            UserVariables.Add(varName, temp);
        }
示例#16
0
        static public VarInfo SubStr(List <VarInfo> parameters)
        {
            if (CheckParameterTypes(parameters, "SNN"))
            {
                string x = parameters[0].toCS_String();
                int    a = (int)parameters[1].toCS_Double();
                int    b = (int)parameters[2].toCS_Double();
                string temp;

                try
                {
                    temp = x.Substring(a, b);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            if (CheckParameterTypes(parameters, "SN"))
            {
                string x = parameters[0].toCS_String();
                int    a = (int)parameters[1].toCS_Double();
                string temp;

                try
                {
                    temp = x.Substring(a);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            return(VarInfo.NullVal);
        }
示例#17
0
        private VarInfo HandleInputBlock(FlowBlock CurrentBlock, out string ErrorReport)
        {
            FlowMap map = form.ActiveMdiChild as FlowMap;

            ErrorReport = "";

            string varAndType = CurrentBlock.Text;
            string varName;

            FlowData.HandleDeclaration(varAndType, out varName, out ErrorReport);
            if (ErrorReport != "")
            {
                return(null);
            }

            DataType varType = FlowData.GetVarInfo(varName, out ErrorReport).type;

            if (ErrorReport != "")
            {
                return(null);
            }

            frmScan      InputForm    = new frmScan(varName, varType);
            DialogResult dialogResult = InputForm.ShowDialog();

            if (dialogResult == DialogResult.Cancel)
            {
                ErrorReport = "Error: User input was canceled";
                return(null);
            }

            VarInfo InputVarInfo = InputForm.VarInfoResult;

            FlowData.AssignVariable(varName, InputVarInfo, out ErrorReport);
            if (ErrorReport != "")
            {
                return(null);
            }

            MainInterface.Instance.UserLog("Input: " + varName + " = " + InputVarInfo.value, LogType.Normal);
            return(null);
        }
示例#18
0
        static public VarInfo IsDecEq(List <VarInfo> parameters)
        {
            bool temp = true;

            for (int i = 0; i < parameters.Count - 1; i++)
            {
                if (parameters[i].type == DataType.FA_Number && parameters[i + 1].type == DataType.FA_Number)
                {
                    temp = temp && (parameters[i].toCS_Double() >= parameters[i + 1].toCS_Double());
                }
                else
                {
                    return(VarInfo.NullVal);
                }
            }

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#19
0
        static public VarInfo LCM(List <VarInfo> parameters)
        {
            int temp = parameters[0].toCS_Int();

            foreach (var parameter in parameters)
            {
                if (parameter.type == DataType.FA_Number && !parameter.isNull)
                {
                    temp = additional_LCM(temp, parameter.toCS_Int());
                }
                else
                {
                    return(VarInfo.NullVal);
                }
            }

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#20
0
        public void AssignVariable(string varName, VarInfo varInfo, out string ErrorReport)
        {
            if (!Exist(varName))
            {
                ErrorReport = "Error: Not declared variable name: " + varName;
                return;
            }

            VarInfo temp = UserVariables[varName];

            if (varInfo.type != temp.type)
            {
                ErrorReport = "Error: Wrong expected data type: " + varName;
                return;
            }

            ErrorReport            = "";
            temp                   = new VarInfo(varInfo);
            UserVariables[varName] = temp;
        }
示例#21
0
        static public VarInfo Xor(List <VarInfo> parameters)
        {
            bool temp = false;

            foreach (var parameter in parameters)
            {
                if (parameter.type == DataType.FA_Boolean && !parameter.isNull)
                {
                    temp = temp ^ parameter.toCS_bool();
                }
                else
                {
                    return(VarInfo.NullVal);
                }
            }

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#22
0
        static public VarInfo IsEqual(List <VarInfo> parameters)
        {
            if (parameters.Count == 2)
            {
                bool temp;
                try
                {
                    temp = VarInfo.IsEqual(parameters[0], parameters[1]);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            return(VarInfo.NullVal);
        }
示例#23
0
        static public VarInfo Concat(List <VarInfo> parameters)
        {
            string temp = "";

            foreach (var parameter in parameters)
            {
                if (!parameter.isNull)
                {
                    temp += parameter.toCS_String();
                }
                else
                {
                    return(VarInfo.NullVal);
                }
            }

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#24
0
        static public VarInfo Max(List <VarInfo> parameters)
        {
            double temp = parameters[0].toCS_Double();

            foreach (var parameter in parameters)
            {
                if (parameter.type == DataType.FA_Number && !parameter.isNull)
                {
                    temp = Math.Max(temp, parameter.toCS_Double());
                }
                else
                {
                    return(VarInfo.NullVal);
                }
            }

            VarInfo result = new VarInfo(temp);

            return(result);
        }
示例#25
0
        static public VarInfo Log(List <VarInfo> parameters)
        {
            if (CheckParameterTypes(parameters, "NN"))
            {
                double x = parameters[0].toCS_Double();
                double y = parameters[1].toCS_Double();
                double temp;

                try
                {
                    temp = Math.Log(y, x);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            if (CheckParameterTypes(parameters, "N"))
            {
                double x = parameters[0].toCS_Double();
                double temp;

                try
                {
                    temp = (double)Math.Log10(x);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            return(VarInfo.NullVal);
        }
示例#26
0
        static public VarInfo Round(List <VarInfo> parameters)
        {
            if (CheckParameterTypes(parameters, "NN"))
            {
                double x = parameters[0].toCS_Double();
                int    y = (int)Math.Floor(parameters[1].toCS_Double());
                double temp;

                try
                {
                    temp = (double)Math.Round(x, y);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            if (CheckParameterTypes(parameters, "N"))
            {
                double x = parameters[0].toCS_Double();
                double temp;

                try
                {
                    temp = (double)Math.Round(x);
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            return(VarInfo.NullVal);
        }
示例#27
0
        static public VarInfo RandomFloat(List <VarInfo> parameters)
        {
            if (CheckParameterTypes(parameters, ""))
            {
                double temp;

                try
                {
                    temp = random.NextDouble();
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            return(VarInfo.NullVal);
        }
示例#28
0
        static public VarInfo RandomPick(List <VarInfo> parameters)
        {
            if (parameters.Count == 0)
            {
                return(VarInfo.NullVal);
            }

            int index = random.Next(parameters.Count);

            foreach (var parameter in parameters)
            {
                if (parameter.type != parameters[0].type || parameter.isNull)
                {
                    return(VarInfo.NullVal);
                }
            }

            VarInfo result = new VarInfo(parameters[index]);

            return(result);
        }
示例#29
0
        //------------------------------------------------------------------------------------------------------------------------------------------------------
        // assign variables ------------------------------------------------------------------------------------------------------------------------------------
        //------------------------------------------------------------------------------------------------------------------------------------------------------
        public void AssignVariable(string varName, DataType dataType, string value, out string ErrorReport)
        {
            if (!Exist(varName))
            {
                ErrorReport = "Error: Not declared variable name: " + varName;
                return;
            }

            VarInfo temp = UserVariables[varName];

            if (!VarInfo.ValidValue(value, temp.type))
            {
                ErrorReport = "Error: Wrong expected data type: " + varName;
                return;
            }

            ErrorReport            = "";
            temp.value             = value;
            temp.isNull            = false;
            UserVariables[varName] = temp;
        }
示例#30
0
        static public VarInfo Not(List <VarInfo> parameters)
        {
            if (CheckParameterTypes(parameters, "B"))
            {
                bool x = parameters[0].toCS_bool();
                bool temp;

                try
                {
                    temp = !x;
                }
                catch
                {
                    return(VarInfo.NullVal);
                }

                VarInfo result = new VarInfo(temp);
                return(result);
            }

            return(VarInfo.NullVal);
        }