Esempio n. 1
0
        public (ImmutableList <Symbol>, Symbol) Run(Symbol symbol)
        {
            var variableAssigner        = new VariableAssigner();
            var globalVariablesReplacer = new GlobalVariablesReplacer(variableAssigner);

            var fullEvaluator = new FullEvaluator(
                ImmutableList <ISymbolVisitor <Symbol> > .Empty
                .Add(variableAssigner)
                );

            var context = Seq[DefaultContext, additionalContext].Visit(fullEvaluator).Symbol;
//            symbol = Seq[context, symbol];

            var steps = ImmutableList <Symbol> .Empty.Add(symbol);

            var i = 0;

            while (true)
            {
                var(newSteps, newResult) = symbol
                                           .Visit(globalVariablesReplacer)
                                           .Visit(globalVariablesReplacer)
                                           .Visit(globalVariablesReplacer)
                                           .Visit(globalVariablesReplacer)
                                           .Visit(globalVariablesReplacer)
                                           .Visit(fullEvaluator);

                if (Equals(newResult, symbol) && i > 0)
                {
                    return(steps, symbol);
                }

                steps  = steps.AddRange(newSteps).WithoutDuplicates();
                symbol = newResult;

                try {
                    Logger.Log($"Iteration: {symbol}");
                }
                catch {
                    // ignored
                }

                if (i++ > maxIterations)
                {
                    return(steps, Seq["Max iterations count reached", symbol]);
 public FunctionPreprocessor(FullEvaluator fullEvaluator, Expression function)
 {
     this.fullEvaluator = fullEvaluator;
     this.function      = function;
 }