public bool Equals(EarleyItem item) { if(ReferenceEquals(item, this)) return true; return _production == item._production && _position == item._position && _parent == item._parent; }
private IEnumerable<EarleyItem> Complete(EarleyItem item) { if(item.IsComplete) { foreach(var parentItem in item.Parent) { if (item.Production.LeftSide.Equals(parentItem.NextProductionSymbol)) { yield return new EarleyItem(parentItem.Production, parentItem.Position + 1, parentItem.Parent); } } } }
private IEnumerable<EarleyItem> Scan(EarleyItem item, char c) { var nextSymbol = item.NextProductionSymbol as Terminal; if (nextSymbol != null) { if (nextSymbol.Matches(c)) { yield return new EarleyItem(item.Production, item.Position + 1, item.Parent); } } }
private IEnumerable<EarleyItem> Predict(EarleyItem item, List<EarleyItem> parent) { var nextSymbol = item.NextProductionSymbol as Nonterminal; if(nextSymbol != null) { foreach(var production in nextSymbol.Productions) { yield return new EarleyItem(production, 0, parent); } if(nextSymbol.IsNullable) yield return new EarleyItem(item.Production, item.Position + 1, item.Parent); } }