コード例 #1
0
        static List<IExpression> _FillErUp(IEnumerable<IExpression> nodes, SymbolReader symbolReader)
        {
            var childrenForNextLevel = new List<IExpression>();

            foreach(var node in nodes)
            {
                if(symbolReader.IsEndOfSymbols())
                    break;

                var symbol = symbolReader.ReadNextSymbol();
                var theOperator = _GetOperator(symbol);
                node.SetLiteral(symbol);
                node.SetOperator(theOperator);

                var childrenToCreateCount = _GetNumberOfChildrenFor(theOperator);

                for(var i=0; i<childrenToCreateCount; i++)
                {
                    var operand = new Operand();
                    node.Add(operand);
                    childrenForNextLevel.Add(operand);
                }
            }

            return childrenForNextLevel;
        }
コード例 #2
0
        public IEvaluatable Convert(string genome)
        {
            var symbolReader = new SymbolReader(genome);

            var root = new Operand();
            var fillList = new List<IExpression> {root};

            while(fillList.Count > 0)
                fillList = _FillErUp(fillList, symbolReader);

            return root;
        }