public object Evaluate()
        {
            if (expression == null)
            {
                throw new ExpressionEvaluatorException("the expression should not be empty or null");
            }

            object result;

            try
            {
                ExpressionLexer  lexer  = new ExpressionLexer(expression);
                ExpressionParser parser = new ExpressionParser(
                    new TokenStream(lexer),
                    context);

                ExpressionNode    tree    = parser.Parse();
                ExpressionVisitor visitor = new ExpressionVisitor(context);
                IExpression       expr    = ExpressionBuilder.Build(tree);
                expr.Accept(visitor);

                result = visitor.EvaluationResult;
            }
            catch (Exception e) // reports all unexpected exceptions
            {
                context.ReportError(
                    String.Format(
                        "failed to evaluate expression '{0}' : '{1}'",
                        expression,
                        e.Message));
                result = expression;
            }

            return(result);
        }
        public object Evaluate()
        {
            if (expression == null)
            {
                throw new ExpressionEvaluatorException("the expression should not be empty or null");
            }

            object result;
            try
            {
                ExpressionLexer lexer = new ExpressionLexer(expression);
                ExpressionParser parser = new ExpressionParser(
                    new TokenStream(lexer),
                    context);

                ExpressionNode tree = parser.Parse();
                ExpressionVisitor visitor = new ExpressionVisitor(context);
                IExpression expr = ExpressionBuilder.Build(tree);
                expr.Accept(visitor);

                result = visitor.EvaluationResult;
            }
            catch (Exception e) // reports all unexpected exceptions
            {
                context.ReportError(
                    String.Format(
                    "failed to evaluate expression '{0}' : '{1}'",
                    expression,
                    e.Message));
                result = expression;
            }

            return result;
        }
 public TokenStream(ExpressionLexer lexer)
 {
     this.lexer = lexer;
 }
Example #4
0
 public TokenStream(ExpressionLexer lexer)
 {
     this.lexer = lexer;
 }