Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        private LeoItem FindLeoItemPredecessor(EarleyItem earleyItem)
        {
            EarleySet predecessorSet = Sets[earleyItem.GetOrignPosition()];

            return(predecessorSet.FindLeoItemBySymbol(earleyItem.GetRule().GetLeftHandSideOfRule()));
        }