Example #1
0
        private static IExpression GetMember(RuntimeData runtime, IExpression parent, Member searchToken)
        {
            // まずは変数を検索する
            if (parent == null)
            {
                if (runtime.ContainsKey(searchToken.Text))
                {
                    return(runtime.GetData(searchToken.Token));
                }
            }

            // 親メンバーから検索
            if (parent != null)
            {
                throw new NotImplementedException();
            }

            // フィールドメンバーから検索
            if (parent == null)
            {
                if (runtime.ContainsFunc(searchToken.Text))
                {
                    return(runtime.GetFunc(searchToken, false));
                }
            }

            // 不明なものはとりあえず変数と見立てる
            if (parent == null)
            {
                return(new Variable(searchToken.Token));
            }

            throw new SyntaxException(string.Format("'{0}'は見つかりませんでした", searchToken.Text),
                                      searchToken.Token, new KeyNotFoundException());
        }
Example #2
0
        public override INumber Eval(RuntimeData runtime)
        {
            if (runtime.ContainsKey(this.Text))
            {
                var res = runtime.GetData(this.Token).Eval(runtime).Clone();
                res = res.Power(runtime, this.Pow);
                return(res);
            }

            // 変数として処理する
            // その際に変数を評価して渡す
            return(GetVariable(runtime).Eval(runtime));

            throw new RuntimeException(string.Format("'{0}'は見つかりませんでした。", this.Text), this.Token);
        }
Example #3
0
        public static IntegralConstant Create(RuntimeData runtime)
        {
            int i = 1;

            for (; ; i++)
            {
                if (!runtime.ContainsKey("C" + i, true))
                {
                    break;
                }
            }

            IntegralConstant res = new Expression.IntegralConstant();

            res.id = i;
            return(res);
        }
Example #4
0
 public override INumber Eval(RuntimeData runtime)
 {
     if (runtime.ContainsKey(this.Token.Text))
     {
         var res = runtime.GetData(this.Token);
         res = res.Multiple(runtime, this.multi);
         res = res.Power(runtime, this.Pow);
         if (res == this)
         {
             return(this);
         }
         return(res.Eval(runtime));
     }
     else
     {
         return(this);
     }
 }
Example #5
0
        public override INumber ExecuteDiff(RuntimeData runtime, string t)
        {
            INumber res = null;

            if (runtime.ContainsKey(this.Name))
            {
                res = this.Eval(runtime).ExecuteDiff(runtime, t);
            }
            else
            {
                if (this.Name == t)
                {
                    if (!(this.multi is IConstParameter))
                    {
                        throw new NotImplementedException();
                    }
                    var me = this.Clone();
                    me.Pow = me.Pow.Subtract(runtime, Number.New(1));
                    me     = me.Optimise(runtime);
                    res    = me;
                }
                else
                {
                    res = new FuncedINumber(
                        runtime.Functions["diff"], new INumber[] { new Variable(new Token(t, Analyzer.TokenType.Member)), this });
                }
            }

            var mf = Runtime.Func.Differential.DiffPow(runtime, t, this);

            if (mf != null)
            {
                mf.AddItem(runtime, res);
                return(mf);
            }
            else
            {
                return(res);
            }
        }