Example #1
0
        public void ReplaceFuncExpressTemp(params string  [] number)
        {        //让FuncExpressTemp这个属性发生改变
            Wrong = false;
            if (Parameters == null || Parameters[0] == null || Parameters[0] == "" || number[0] == "")
            {
                Wrong = true;
                return;
            }
            FuncString funcexpress = new FuncString();

            funcexpress.SetString(FuncExpress);            //初始化
            for (int i = 0; i < number.Length && Parameters[i] != null; i++)
            {
                FuncExpressTemp = funcexpress.ReplaceAllEks("(" + number[i] + ")", funcexpress.FindAllString(Parameters[i]), Parameters[i].Length);
//				FuncExpressTemp=funcexpress.ReplaceAllEks(number[i],funcexpress.FindAllString(Parameters[i]),Parameters[i].Length);

                funcexpress.SetString(FuncExpressTemp);
            }
        }
Example #2
0
        /// <summary>
        /// 完成输入表达式的转换
        /// </summary>
        /// <returns>
        /// return 4; f(1,2)保留了FuncName="f",FuncExpressTemp="1,2"
        /// return 1; x,x+y 类型返回FuncName=x,x+y
        /// return 2; 赋值x=1
        /// return 3; 表达式定义 f(x,y)=x+y
        /// return 5; x=[1,2]
        /// </returns>
        public int  AnalyseEquation()
        {
            string equation          = this.GetString();
            int    leftbraket        = this.FindOp(0, '(');
            int    leftsquarebracket = this.FindOp(0, '[');
            int    equalsign         = this.FindOp(0, '=');

            if (equalsign == -1)            //没有等号
            {
                if (leftbraket != -1)       //有括号
                {
                    int rightbraketd = this.FindOp(leftbraket, ')');
                    FuncName        = this.FromToEnd(-1, leftbraket - 1);
                    FuncExpressTemp = this.FromToEnd(leftbraket, rightbraketd - 1);
                    return(4);                   //f(1,2)保留了FuncName="f",FuncExpressTemp="1,2"
                }

                //没有括号
                FuncName = equation.Trim();

                return(1);               //变量 x , f(1,2), x+y,plot(f)等情况
            }
            if (leftbraket == -1 || equalsign < leftbraket || equalsign < leftsquarebracket)
            {
                FuncName    = this.FromToEnd(-1, equalsign - 1);
                FuncExpress = this.FromToEnd(equalsign, this.GetLength() - 1);
                return(2);               //赋值 x=1
            }
            int rightbraket = this.FindOp(leftbraket, ')');

            FuncName = this.FromToEnd(-1, leftbraket - 1);

            string     lefteq   = FromToEnd(leftbraket, rightbraket);
            FuncString leftfunc = new FuncString();

            leftfunc.SetString(lefteq);
            int[] split = leftfunc.FindOpOutOfBrackets(',');

            split = PushToHead <int>(split, -1);
            string[] strsplit = new string[20];            //保存分割后的字符串
            for (int j = 0; j < split.Length - 1; j++)
            {
                strsplit[j] = leftfunc.FromToEnd(split[j], split[j + 1] - 1);
            }

            strsplit[split.Length - 1] = leftfunc.FromToEnd(split[split.Length - 1], leftfunc.GetLength() - 2);
            Parameters = strsplit;
            int EqualSign = FindOp(rightbraket, '=');

            FuncExpress     = FromToEnd(EqualSign, GetLength() - 1);
            FuncExpressTemp = FuncExpress;
            //   f(x,y)=skjhf
            return(3);           //表达式
        }
Example #3
0
        public void Run()
        {
            Console.WriteLine("Hello World! type: help() to know how to use");
            while (InputData != "exit")
            {
                GetDataToInput();
//				PushToShow("进入run程序");
                funstring.SetString(InputData);
                int Extype = funstring.AnalyseEquation();
                if (Extype == 1 || Extype == 4)                  //没有等号 判断为命令或求值之类
//					PushToShow("不是存值");
                {
                    AnalyseInputG(Extype);
                    continue;
                }
                //保存起来
                string funs = funstring.GetFuncName();

                CalData caldata = null;
                switch (Extype)
                {
                case 2:

                    DealAssignment da = new DealAssignment(funstring.GetFuncExpress());
                    if (tdc.CheckName(funs))
                    {
                        DataType getdt = new DataType();
                        try {
                            getdt = da.GetDataType();
                        } catch (ExpError e) {
                            PushToShow(e.Message);
                            continue;
                        }
                        if (getdt == DataType.EXP)
                        {
                            try {
                                ((ExpData)(da.GetCalData())).GetValueFinal();                                        //防止循环调用SimpleCal--> ReplaceParamers--> GetValueEx-->SimpleCal
                            } catch (AssignedError e) {
                                PushToShow(e.Message);
                                continue;
                            }
                        }
                    }
                    try {
                        caldata = da.GetCalData();
                    } catch (AssignedError e) {
                        PushToShow(e.Message);
                        continue;
                    }

                    break;

                case 3:
                    caldata = new FuncData(funstring.GetFuncExpress(), funstring.GetParamers());
                    break;

                default:
                    break;
                }
                if (CheckDuplicationName(funs))
                {
                    tdc.Remove(tdc.FindPosition(funs));
                }
                if (funstring.CheckFunName(funs))
                {
                    PushToShow("Variable Name not acceptable!");
                    continue;
                }
                if (tdc.CreateData(funstring.GetFuncName(), caldata))
                {
                    PushToShow("数据已保存");
                }
                else
                {
                    PushToShow("Not accept input!");
                }
                #region 之前写的不好就改了


//				int a = funstring.FindOp(0, '=');
//				int b = funstring.FindOp(0, '(');
//				if (a != -1) {
//
//
//					if (b > a) {
//						funstring.AnalyseEquation();
                ////						funstring.ShowParamers();
//						if(CheckDuplicationName()) continue;
//
//						tdc.CreateData(funstring.GetFuncName(), funstring.GetFuncExpress(), funstring.GetParamers());
//					} else {
//						funstring.AnalyseVariable();
                ////						funstring.ShowParamers();
//						if(CheckDuplicationName()) continue;
//						tdc.CreateData(funstring.GetFuncName(), funstring.GetFuncExpress());
//					}
//				} else {
//
//				}


                #endregion
            }
        }