private static bool TryDerive([NotNull, ItemNotNull] List <Symbol> tape, int start, [NotNull] GrammarRule0 rule, IDerivationTracker tracker) { if (tape.Count < start + rule.LeftHandSide.Count) { return(false); } var sublist = tape.GetRange(start, rule.LeftHandSide.Count); if (!sublist.SequenceEqual(rule.LeftHandSide)) { return(false); } tape.RemoveRange(start, rule.LeftHandSide.Count); tape.InsertRange(start, rule.RightHandSide); tracker.Track(tape, rule); return(true); }
public static bool TryDerive([NotNull, ItemNotNull] this List <Symbol> tape, [NotNull] GrammarRule0 rule, IDerivationTracker tracker) => tape.Where((t, index) => TryDerive(tape, index, rule, tracker)).Any();