コード例 #1
0
        public CompileResult CompileExpression(
            Drawing drawing,
            string expressionText,
            Predicate <IFigure> isFigureAllowed)
        {
            CompileResult result = new CompileResult();

            if (expressionText.IsEmpty())
            {
                return(result);
            }

            Node ast = Parse(expressionText, result);

            if (!result.Errors.IsEmpty())
            {
                return(result);
            }

            ExpressionTreeBuilder builder = new ExpressionTreeBuilder();

            builder.SetContext(drawing, isFigureAllowed);
            var expressionTree = builder.CreateExpression(ast, result);

            if (expressionTree == null || !result.Errors.IsEmpty())
            {
                return(result);
            }
            Func <double> function = ExpressionTreeEvaluatorProvider.InterpretExpression(expressionTree);

            result.Expression = function;
            return(result);
        }
コード例 #2
0
ファイル: Compiler.cs プロジェクト: ondrej11/o106
        public CompileResult CompileFunction(Drawing drawing, string functionText)
        {
            CompileResult result = new CompileResult();
            if (string.IsNullOrEmpty(functionText))
            {
                return result;
            }

            ParseTree ast = Parse(functionText, result);
            if (!result.Errors.IsEmpty())
            {
                return result;
            }

            ExpressionTreeBuilder builder = new ExpressionTreeBuilder();
            builder.SetContext(drawing, f => true);
            var expressionTree = builder.CreateFunction(ast.Root, result);
            if (expressionTree == null || !result.Errors.IsEmpty())
            {
                return result;
            }

            Func<double, double> function = ExpressionTreeEvaluatorProvider.InterpretFunction(expressionTree);
            result.Function = function;
            return result;
        }
コード例 #3
0
        public CompileResult CompileFunction(Drawing drawing, string functionText)
        {
            CompileResult result = new CompileResult();

            if (string.IsNullOrEmpty(functionText))
            {
                return(result);
            }

            Node ast = Parse(functionText, result);

            if (!result.Errors.IsEmpty())
            {
                return(result);
            }

            ExpressionTreeBuilder builder = new ExpressionTreeBuilder();

            builder.SetContext(drawing, f => true);
            var expressionTree = builder.CreateFunction(ast, result);

            if (expressionTree == null || !result.Errors.IsEmpty())
            {
                return(result);
            }

            Func <double, double> function = ExpressionTreeEvaluatorProvider.InterpretFunction(expressionTree);

            result.Function = function;
            return(result);
        }
コード例 #4
0
ファイル: Compiler.cs プロジェクト: ondrej11/o106
        public CompileResult CompileExpression(
            Drawing drawing,
            string expressionText,
            Predicate<IFigure> isFigureAllowed)
        {
            CompileResult result = new CompileResult();
            if (expressionText.IsEmpty())
            {
                return result;
            }

            ParseTree ast = Parse(expressionText, result);
            if (!result.Errors.IsEmpty())
            {
                return result;
            }

            ExpressionTreeBuilder builder = new ExpressionTreeBuilder();
            builder.SetContext(drawing, isFigureAllowed);
            var expressionTree = builder.CreateExpression(ast.Root, result);
            if (expressionTree == null || !result.Errors.IsEmpty())
            {
                return result;
            }
            Func<double> function = ExpressionTreeEvaluatorProvider.InterpretExpression(expressionTree);
            result.Expression = function;
            return result;
        }