コード例 #1
0
        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
                                ));
            }
        }
コード例 #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);
        }
コード例 #3
0
        internal static void PrintSets(List <EarleySet> setsToPrint, bool all)
        {
            if (setsToPrint == null)
            {
                return;
            }

            for (int i = 0; i < setsToPrint.Count; i++)
            {
                Console.WriteLine("\n <=============================SET=================================> " + i);
                EarleySet set = setsToPrint[i];

                List <EarleyItem> items = set.GetEarleyItemList();
                for (int k = 0; k < items.Count; k++)
                {
                    EarleyItem e = items[k];
                    if (!all)
                    {
                        if (e.IsCompleted())
                        {
                            Console.WriteLine("\t\t" + e.ToString());
                        }
                    }
                    else
                    {
                        Console.WriteLine((e.IsCompleted() ? "\t\t" : "\t") + e.ToString());
                    }
                }

                Console.WriteLine("\n <--------> ");
                List <LeoItem> transitiveItems = set.GetLeoItemList();
                for (int k = 0; k < transitiveItems.Count; k++)
                {
                    LeoItem e = transitiveItems[k];
                    Console.WriteLine(e.ToString());
                }
                Console.WriteLine("\n <=====================================================================> " + i);
            }
        }
コード例 #4
0
 internal void AddLeoItem(LeoItem leoItem)
 {
     _leoItemList.Add(leoItem);
 }