示例#1
0
文件: EarleyItem.cs 项目: SeanU/NEPI
 public bool Equals(EarleyItem item)
 {
     if(ReferenceEquals(item, this)) return true;
     return
         _production == item._production
         && _position == item._position
         && _parent == item._parent;
 }
示例#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);
             }
         }
     }
 }
示例#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);
         }
     }
 }
示例#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);
            }
        }