Example #1
0
        IBooleanBase ConvertTokenToCondition(string conditionTokens, IDictionary <string, Tuple <string, IData, bool> > variables, ref IRule rule)
        {
            IList <string> postFixConditionTokens = ParseConditionToPostFixTokenList(new StringBuilder(conditionTokens));

            Stack <object> stack = new Stack <object>();

            for (int index = 0; index < postFixConditionTokens.Count; index++)
            {
                string token = postFixConditionTokens[index];

                if (IsOperator(token))
                {
                    IList <object> operands = new List <object>();

                    if (((token == AndExpression.Operator) || (token == OrExpression.Operator)))
                    {
                        while (stack.Any())
                        {
                            operands.Add(stack.Pop());
                        }
                    }
                    else
                    {
                        operands.Add(stack.Pop());
                        operands.Add(stack.Pop());
                    }

                    Type operatorType = GetOperatorType(token);

                    stack.Push(CreateConditionInstance(operatorType, operands.ToArray()));
                }
                else
                {
                    stack.Push(variables[token].Item2);
                    rule.AddVariableScope(variables[token].Item2, variables[token].Item3);
                }
            }

            IBooleanBase condition = (IBooleanBase)stack.Pop();

            return(condition);
        }