private bool LeoReducer(EarleyItem completed, int setNumber) { int position = completed.GetOrignPosition(); Symbol lhs = completed.GetRule().GetLeftHandSideOfRule(); EarleySet set = Sets[position]; LeoItem transitiveItem = set.FindLeoItemBySymbol(lhs); if (transitiveItem == null) { return(false); } EarleyItem newEarleyItem = new EarleyItem( setNumber, transitiveItem.GetDottedRule(), transitiveItem.GetOrignPosition() ); EarleyItem current = Sets[transitiveItem.GetOrignPosition()].GetEarleyItemList() .Find(el => el.GetDottedRule().Equals(transitiveItem.GetDottedRule()) && el.GetOrignPosition() == transitiveItem.GetOrignPosition()); if (current.GetCurrentPrevSymbolList() != null && current.GetCurrentPrevSymbolList().Count > 0) { newEarleyItem.AddPredecessorLink(current, position); } newEarleyItem.AddReducerLink(completed, position); AddToSet( newEarleyItem, setNumber, "LeoReducer" ); return(true); }
private void LeoMemoization(EarleyItem earleyItem, int setNumber) { if (!Sets[setNumber].IsItemLeoEligible(earleyItem)) { return; } Symbol penult = earleyItem.GetItemPenult(); LeoItem predecessorLeoItem = FindLeoItemPredecessor(earleyItem); if (predecessorLeoItem != null) { Sets[predecessorLeoItem.GetOrignPosition()] .AddLeoItem(new LeoItem( predecessorLeoItem.GetDottedRule(), predecessorLeoItem.GetOrignPosition(), penult )); } else { Sets[earleyItem.GetOrignPosition()] .AddLeoItem(new LeoItem( new DottedRule(earleyItem.GetRule(), earleyItem.GetRulePosition() + 1), earleyItem.GetOrignPosition(), penult )); } }