示例#1
0
        private void EarleyReducer(EarleyItem completed, int setNumber)
        {
            int               position = completed.GetOrignPosition();
            EarleySet         set      = Sets[position];
            List <EarleyItem> items    = set.GetEarleyItemList();

            for (int j = 0; j < items.Count; j++)
            {
                EarleyItem current = items[j];
                Symbol     next    = current.GetCurrentNextSymbol();
                if (next != null && next.Equals(completed.GetRule().GetLeftHandSideOfRule()))
                {
                    EarleyItem newEarleyItem = new EarleyItem(
                        setNumber,
                        new DottedRule(current.GetRule(), current.GetRulePosition() + 1),
                        current.GetOrignPosition()
                        );

                    if (current.GetCurrentPrevSymbolList() != null && current.GetCurrentPrevSymbolList().Count > 0)
                    {
                        newEarleyItem.AddPredecessorLink(current, position);
                    }

                    newEarleyItem.AddReducerLink(completed, position);
                    AddToSet(newEarleyItem, setNumber, "EarleyReducer");
                }
            }
        }
示例#2
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);
        }