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()); }
public override INumber Execute(RuntimeData runtime, params INumber[] parameters) { var param = parameters[0]; if (param is Variable || param is Member) { string name = ""; if (param is Variable) { name = (param as Variable).Name; } if (param is Member) { name = (param as Member).Text; } if (runtime.ContainsFunc(name)) { var func = runtime.GetFunc(param, false); if (func is UserDefineFunction) { return((func as UserDefineFunction).Formula as INumber); } } } return(parameters[0].Eval(runtime)); }
public override INumber Execute(RuntimeData runtime, params INumber[] parameters) { if (parameters[0] is Variable || parameters[0] is Member) { Variable v = parameters[0] as Variable; if (v == null) { v = new Variable((parameters[0] as Member).Token); } if (!runtime.Functions.ContainsKey(v.Name)) { throw new RuntimeException(string.Format("関数 '{0}' は見つかりませんでした。", parameters[0])); } if (!(runtime.GetFunc(v, false) is UserDefineFunction)) { throw new RuntimeException("さdelfunc関数で削除できるのはユーザー定義関数のみです。", parameters[9]); } runtime.Functions.Remove(v.Name); } return(null); }
private static IExpression ExecuteFunc(RuntimeData runtime, IExpression func, INumber multiple) { if (func == null) { throw new ArgumentNullException("func"); } if (func is IFunction) { List <IExpression> param = new List <Interface.IExpression>(); int count = runtime.NowBlock.Count; for (int i = 0; i < count; i++) { IExpression ex = runtime.NowBlock.Pop(); if (ex is LineBreak) { break; } param.Insert(0, ex); } List <ExpressionType> paramType = new List <Expression.ExpressionType>(); for (int i = 0; i < param.Count; i++) { IExpression ex = param[i]; if (ex is LineBreak) { break; } if (ex is IConstParameter) { paramType.Add(ExpressionType.Number); continue; } else if (ex is IUnknownParameter || ex is Member || ex is Variable) { paramType.Add(ExpressionType.Unknown); continue; } else if (ex is AdditionFormula || ex is MultipleFormula) { paramType.Add(ExpressionType.Formula); continue; } else if (ex is Fraction || ex is FunctionFormula || ex is FuncedINumber) { paramType.Add(ExpressionType.Unknown); continue; } throw new NotImplementedException(); } var function = runtime.GetFunc(func, true, paramType.ToArray()); var res = function.Execute(runtime, param.ConvertAll <INumber>(a => { if (function.DoEvaledParam) { return((a as IEval).Eval(runtime)); } else { return(a as INumber); } }).ToArray()); if (runtime.Setting.IsDebug) { StringBuilder sb = new StringBuilder("Func Eval Result : "); sb.Append(function.Name); sb.Append("("); for (int i = 0; i < param.Count; i++) { if (i != 0) { sb.Append(", "); } sb.Append(param[i].ToString()); } sb.Append(")"); sb.Append(" => " + res == null ? "" : res.ToString()); Console.WriteLine(sb.ToString()); } return(res); } if (func is IConstParameter) { return((func as INumber).Multiple(runtime, multiple)); } throw new RuntimeException("関数と数値以外にパラメータを指定して実行することはできません", func); }
public INumber Execute(RuntimeData runtime, INumber left, INumber right) { return(runtime.GetFunc(new Member(new Token("diff", Analyzer.TokenType.Member)), false).Execute(runtime, new Variable(new Token("x", Analyzer.TokenType.Member)), left)); }
public INumber Execute(RuntimeData runtime, INumber left, INumber right) { var func = runtime.GetFunc(new Member(new Token("eval", Analyzer.TokenType.Member)), false, ExpressionType.Unknown); return(func.Execute(runtime, right)); }