示例#1
0
        /// <summary>
        /// Evaluates an expression and returns a <see cref="Variable" />.
        /// </summary>
        /// <param name="expression">The expression to evaluate.</param>
        /// <param name="data">The <see cref="Data" /> object containing all of the story variables.</param>
        /// <returns>A <see cref="Variable" /> instance containing the results of the evaluation.</returns>
        private static Variable Evaluate(string expression, Data data)
        {
            var lexer   = new MathLexer(new AntlrInputStream(expression));
            var parser  = new MathParser(new CommonTokenStream(lexer));
            var visitor = new MathVisitor {
                Data = data
            };

            return(visitor.Visit(parser.expr()));
        }
示例#2
0
        /// <summary>
        /// 执行函数
        /// </summary>
        /// <returns></returns>
        public Operand Evaluate()
        {
            if (_context == null)
            {
                LastError = "Please use Parse to compile formula !";
                throw new Exception("Please use Parse to compile formula !");
            }
            var visitor = new MathVisitor();

            visitor.GetParameter += GetParameter;
            visitor.excelIndex    = UseExcelIndex ? 1 : 0;
            visitor.DiyFunction  += ExecuteDiyFunction;
            return(visitor.Visit(_context));
        }