コード例 #1
0
ファイル: SumSeries.cs プロジェクト: areller/XScriptLib
        protected override double OverrideFunction(string[] parameters, XMParser xmParser, List <XArray> arrs)
        {
            double        sum     = 0;
            int           s       = (int)xmParser.GetDouble(parameters[1], 0, arrs);
            int           e       = (int)xmParser.GetDouble(parameters[2], 0, arrs);
            List <XArray> arrList = new List <XArray>();

            arrList.Add(new XArray("n", 1));
            for (int i = s; i <= e; i++)
            {
                arrList[0].vars[0] = i;
                sum += xmParser.GetDouble(parameters[0], 0, XArray.ConnectLists(arrs, arrList));
            }
            return(sum);
        }
コード例 #2
0
        protected override List <XArray> OverrideProcess(string code, List <XArray> arrs, XSParser parser, string[] cons, int codeLevel)
        {
            if (cons.Length != 2)
            {
                throw new XLogicException(Messages.InvalidNumCons);
            }
            int           from = (int)parser.ParseMathExpr(cons[0], arrs);
            int           to   = (int)parser.ParseMathExpr(cons[1], arrs);
            List <XArray> t    = new List <XArray>();

            t.Add(new XArray("loop." + codeLevel + ".from", 1));
            t.Add(new XArray("loop." + codeLevel + ".to", 1));
            t[0].vars[0] = from;
            t[1].vars[0] = to;
            t.Add(new XArray("loop." + codeLevel + ".current", 1));
            t.Add(new XArray("loop.this.from", 1));
            t.Add(new XArray("loop.this.to", 1));
            t[3].vars[0] = from;
            t[4].vars[0] = to;
            t.Add(new XArray("loop.this.current", 1));
            for (int i = from; i <= to; i++)
            {
                if (i > 1000000)
                {
                    throw new EndlessException(Messages.LoopStuck);
                }
                t[2].vars[0] = i;
                t[5].vars[0] = i;
                arrs         = Helper.OnlyBeneathLevel(parser.ParseReturn(code, codeLevel + 1, XArray.ConnectLists(arrs, t)), codeLevel);
            }
            return(arrs);
        }