public TOutput Parse(IEditEnumerable <TInput> input) { string parsing = "parsing |"; foreach (TInput s in input) { parsing += s + "|"; } Print.Log(parsing); Stack <Evaluator> quantities = new Stack <Evaluator>(); IEditEnumerator <TInput> itr = input.GetEnumerator(); quantities.Push(new Evaluator(new Parse.Collections.Generic.LinkedList <object>(), new LinkedList <LinkedListNode <object> > [Count], new LinkedList <Operator <TOutput> > [Count])); while (true) { Evaluator quantity = quantities.Peek(); bool done = !itr.MoveNext(); if (done || Closing.Contains(itr.Current)) { Evaluator e = quantities.Pop(); Print.Log("close", e.Input.Count); LinkedListNode <object> a = e.Input.First; while (a != null) { Print.Log(a.Value, a.Value?.GetType()); a = a.Next; } Print.Log("\n"); TOutput answer = Close(e); if (quantities.Count == 0) { if (done) { return(answer); } else { Parse.Collections.Generic.LinkedList <object> front = new Parse.Collections.Generic.LinkedList <object>(); front.AddFirst(answer); quantities.Push(new Evaluator(front, new LinkedList <LinkedListNode <object> > [Count], new LinkedList <Operator <TOutput> > [Count])); } } else { quantities.Peek().Input.AddLast(answer); } } else if (Opening.Contains(itr.Current)) { Print.Log("open"); quantities.Push(new Evaluator(new Parse.Collections.Generic.LinkedList <object>(), new LinkedList <LinkedListNode <object> > [Count], new LinkedList <Operator <TOutput> > [Count])); } else { Operator <TOutput> operation; if (Operations.TryGetValue(itr.Current, out operation)) { Print.Log("found operator", itr.Current); int index = IndexOf(itr.Current); // Put the operator in the linked list as a node LinkedListNode <object> node = new LinkedListNode <object>(itr.Current); // Get the list of all of this type of operator (e.g. all instances of "+") if (quantity.Operations[index] == null) { quantity.Operations[index] = new LinkedList <LinkedListNode <object> >(); quantity.Operators[index] = new LinkedList <Operator <TOutput> >(); } if (operation.Order == ProcessingOrder.RightToLeft) { quantity.Operations[index].AddFirst(node); quantity.Operators[index].AddFirst(operation); } else { quantity.Operations[index].AddLast(node); quantity.Operators[index].AddLast(operation); } quantity.Input.AddLast(node); } else { Print.Log("found operand", itr.Current); foreach (TOutput o in ParseOperand(itr.Current)) { Print.Log("\t" + o); quantity.Input.AddLast(o); } } } } }
public T Parse(IEditEnumerable <T> input) => Parse(input.GetEnumerator());