private IEnumerable <object> LoopRel(IEnumerable <string> tokens, Func <string, string, string, object> map) { var enume = tokens.GetEnumerator(); var window = new List <string>(3); var anyMore = true; while (anyMore) { while (window.Count < 3 && (anyMore = enume.MoveNext())) { if (IsGroup(enume.Current) || OperChecker.IsLogOper(enume.Current)) { if (window.Count != 0) { throw new Exception("Invalid logic expression"); } yield return(enume.Current); continue; } window.Add(enume.Current); } if (window.Count == 3) { yield return(map(window[0], window[1], window[2])); } else { foreach (var token in window) { yield return(token); } } window.Clear(); } }