Пример #1
0
        public static void TestMatrixConvert()
        {
            DealAssignment da      = new DealAssignment("[ 1  ,   2      ; 4     5    ]");
            Matrix         ma      = da.ConvertToMatrix();
            Matrix         re      = ma ^ 2;
            Matrix         remulti = ma * ma;

            ShowStr(re.ToString());
            ShowStr(remulti.ToString());
        }
Пример #2
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
            }
        }