Beispiel #1
0
        private RPNExpression ParseToRPN(string expression)
        {
            RPNExpression rpnExpression = new RPNExpression(_FunctionEvaluator, _FunctionCallPrecedence);

            rpnExpression.DoWork(delegate
            {
                Token token             = null;
                MatchCollection matches = this.Regex.Matches(expression);
                foreach (Match match in matches)
                {
                    int groupIndex = -1;
                    for (int index = 0; index < _TokenDefinitions.Count; index++)
                    {
                        if (match.Groups[index + 1].Success)
                        {
                            groupIndex = index;
                            break;
                        }
                    }
                    token = new Token(_TokenDefinitions[groupIndex], match.Value);
                    rpnExpression.ApplyToken(token);
                }
            });

            return(rpnExpression);
        }
Beispiel #2
0
        public IExpression Parse(string expression)
        {
            lock (_CacheLock)
            {
                if (_ExpressionCache.ContainsKey(expression))
                {
                    return(_ExpressionCache[expression]);
                }
                else
                {
                    //1. parse to reverse polish notation expression
                    RPNExpression rpn = ParseToRPN(expression);
                    //2.
                    IExpression iexpression = rpn.Compile();
                    //3. into cache
                    _ExpressionCache[expression] = iexpression;

                    return(iexpression);
                }
            }
        }