Example #1
0
        private void BuildTokens()
        {
            _tokens = new List <IToken>();

            foreach (var t in _postFunction.Tokens)
            {
                if (IsVariable(t))
                {
                    if (!_variables.ContainsKey(t))
                    {
                        GenericVariable <object> v;
                        v = new GenericVariable <object>(t, null);
                        _variables.Add(t, v);
                        _tokens.Add(v);
                    }
                    else
                    {
                        var v = _variables[t];
                        _tokens.Add(v);
                    }
                    continue;
                }

                if (ExpressionKeywords.Keywords.Count(x => x.Name == t) == 1)
                {
                    var v = ExpressionKeywords.Keywords.Single(x => x.Name == t);
                    _tokens.Add(v);
                }

                if (IsNumber(t))
                {
                    var v = (GenericOperand <decimal>)ConvertToOperand(t);
                    _tokens.Add(v);
                }

                if (IsString(t))
                {
                    var v = (GenericOperand <string>)ConvertToOperand(t);
                    _tokens.Add(v);
                }

                if (IsConstant(t))
                {
                    var v = ExpressionKeywords.Constants[t];
                    _tokens.Add(v);
                }
            }
        }
 private string replaceStrings(string expression)
 {
     foreach (var op in ExpressionKeywords.StringGroupOperators)
     {
         if (expression.Count(s => s == op[0]) % 2 != 0)
         {
             throw new ExpressionException("String grouping error! \"" + op + "\" use incorrectly.");
         }
         var pattern = string.Format("{0}.*?{0}", op);
         var regex   = new Regex(pattern);
         expression = regex.Replace(expression, m =>
         {
             var name   = Guid.NewGuid().ToString("N");
             var value  = m.Value.Substring(1, m.Value.Length - 2).ToLower();
             var newVar = new GenericVariable <string>(name, value);
             AutoVariables.Add(name, newVar);
             return(" " + name + " ");
         });
     }
     return(expression);
 }