示例#1
0
        private Func <double, double> ParseFunction(string str)
        {
            var tree = NumExprParser.ExpToTree(str);
            var expr = NumExprToLinqExprTranslator.TranslateExprTree(tree);

            return(expr.Compile());
        }
示例#2
0
            public static Expression <Func <double, double> > TranslateExprTree(NumExpr tree)
            {
                var translator = new NumExprToLinqExprTranslator();
                var body       = tree.Apply(translator);
                var lambda     = Expression.Lambda <Func <double, double> >(body, translator.Arg);

                return(lambda);
            }
示例#3
0
        private void PerformIntegrationForCustomFunction()
        {
            string functionString = null;

            if (
                Dialogs.TryRequestValue("Input function : ", s => true, s => {
                var tree = NumExprParser.ExpToTree(s);
                var expr = NumExprToLinqExprTranslator.TranslateExprTree(tree);
                functionString = tree.Apply(new NumExprStringCollector());
                return(expr.Compile());
            }, out var f))
            {
                this.PerformIntegrationForFunction(x => f(x));
            }
            else
            {
                Dialogs.PrintCancellation();
            }
        }