コード例 #1
0
ファイル: Option.cs プロジェクト: sliverp/DadA
 public override void doSomethings(SignTable signTable)
 {
     this.initSignTable(signTable);
     while (this.isBreak())
     {
         foreach (Operation op in this.circulateBody)
         {
             op.doSomethings(signTable);
             ConditionLeft.content = signTable.getSignById(ConditionLeft.id).content;
         }
     }
 }
コード例 #2
0
ファイル: Option.cs プロジェクト: sliverp/DadA
        public override void doSomethings(SignTable contextTable)
        {
            this.initSignTable(contextTable);
            SignTable runtimeTable = Utils.DeepCopy <SignTable>(this.signTable);//深拷贝运行时符号表

            //执行函数
            for (int i = 0; i < runtimeTable.size(); i++)
            {
                if (runtimeTable[i].content is FunctionBuilder)
                {
                    List <Sign> trueArgs = new List <Sign>();
                    for (int j = i + 1; j < signTable.size(); j++)
                    {//向后检索实参列表
                        if (runtimeTable[j].type == "args")
                        {
                            trueArgs.Add(runtimeTable[j]);
                        }
                        else
                        {
                            break;
                        }
                    }
                    Function f       = ((FunctionBuilder)runtimeTable[i].content).build(trueArgs);
                    MateData fResult = f.run();

                    runtimeTable[i].content = fResult;
                }
            }
            String s = "";


            //从上下中给变量赋值
            foreach (Sign sign in runtimeTable)
            {
                if (contextTable.has(sign.id))
                {
                    sign.content = contextTable.getSignById(sign.id).content;
                }
                else if (sign.content is Hashable)
                {
                    if (sign.id != "" && sign.id[0] != '-')
                    {
                        contextTable.Add(sign);
                    }
                }

                if (sign.type == "结果")
                {
                    continue;
                }
                if (sign.content is Hashable)
                {
                    s = s + sign.content.toString();
                }
                else if (sign.content == null)
                {
                    s = s + sign.type;
                }
            }
            DataTable dataTable = new DataTable();
            double    x         = double.Parse(dataTable.Compute(s, null).ToString());
            DadaInt   data      = new DadaInt("");

            data.setData(x.ToString());
            Sign ss = runtimeTable.Find((e) => e.type == "结果");

            //以下写的很乱,但功能是对的
            if (ss != null)
            {
                if (contextTable.has(ss.id))
                {
                    contextTable.getSignById(ss.id).content = ss.content;
                }
                else
                {
                    contextTable.Add(ss);
                }
            }
            if (ss != null)
            {
                contextTable.getSignById(ss.id).content = data;
            }
            else
            {
                result    = data;
                this.mean = "返回";
            }
        }