Example #1
0
 public bool Equals(EarleyItem item)
 {
     if(ReferenceEquals(item, this)) return true;
     return
         _production == item._production
         && _position == item._position
         && _parent == item._parent;
 }
Example #2
0
 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);
             }
         }
     }
 }
Example #3
0
 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);
         }
     }
 }
Example #4
0
        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);
            }
        }