Example #1
0
        private bool TryOptimizeByRecursiveFunction(string expression, out OptimizerResult result)
        {
            result = new OptimizerResult();
            var countStarted        = false;
            var bracketsCount       = 0;
            var leftBracketLocation = -1;

            for (var i = 1; i < expression.Length; i++)
            {
                if (MathDefinitions.BracketsDefinitions.TryGetValue(expression[i], out var left))
                {
                    if (!countStarted)
                    {
                        var charBefore = expression[i - 1];
                        countStarted = left && (charBefore.IsLetter() || charBefore.IsNumber());
                    }

                    if (countStarted)
                    {
                        bracketsCount = left ? bracketsCount += 1 : bracketsCount -= 1;

                        if (leftBracketLocation == -1)
                        {
                            leftBracketLocation = i;
                        }
                    }
                }

                if (countStarted && bracketsCount == 0)
                {
                    var innerFunction    = expression[(leftBracketLocation + 1)..i];
Example #2
0
        public void Add(OptimizerResult resultToAdd)
        {
            foreach (var variableToken in resultToAdd.VariableTokens)
            {
                AddVariable(variableToken.Key, variableToken.Value);
            }

            ExpressionTokens.AddRange(resultToAdd.ExpressionTokens);
        }
Example #3
0
 public void AddVariable(string name, OptimizerResult variableResult)
 {
     VariableTokens.Add(name, variableResult);
 }