Beispiel #1
0
        public static T Evaluate <T>(RPNExpression expression)
        {
            try
            {
                var context = new RPNContext(expression);
                while (context.CanMove)
                {
                    context.MoveNext();

                    if (DefaultEvaluator.Evaluate(context))
                    {
                        continue;
                    }
                    if (BasicEvaluator.Evaluate(context))
                    {
                        continue;
                    }
                    if (MathEvaluator.Evaluate(context))
                    {
                        continue;
                    }
                    if (LogicEvaluator.Evaluate(context))
                    {
                        continue;
                    }
                    if (StringEvaluator.Evaluate(context))
                    {
                        continue;
                    }
                    if (RegexEvaluator.Evaluate(context))
                    {
                        continue;
                    }
                    if (DateTimeEvaluator.Evaluate(context))
                    {
                        continue;
                    }
                    if (ControlEvaluator.Evaluate <T>(context))
                    {
                        continue;
                    }

                    context.Stack.Push(context.Current);
                }
                return(context.GetResult <T>());
            }
            catch (RPNException)
            {
                throw;
            }
            catch
            {
                throw new ParsingException(expression.Expression);
            }
        }
Beispiel #2
0
        public static dynamic Evaluate(string expression, params object[] parameters)
        {
            var rpnExpression = new RPNExpression(expression, parameters);

            return(Evaluate <dynamic>(rpnExpression));
        }
Beispiel #3
0
 public static dynamic Evaluate(RPNExpression expression)
 {
     return(Evaluate <dynamic>(expression));
 }
Beispiel #4
0
 internal RPNContext(RPNExpression expression)
 {
     this.Expression = expression;
     this.Load();
 }