コード例 #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
        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);
            }
        }
コード例 #3
0
        private void RunMarpa(String input, int fromPosition)
        {
            for (int i = fromPosition; i <= input.Length; i++)
            {
                EarleySet         set   = Sets[i];
                List <EarleyItem> items = set.GetEarleyItemList();
                for (int j = 0; j < items.Count; j++)
                {
                    EarleyItem current = items[j];

                    if (current.IsCompleted())
                    {
                        Completer(current, i);
                    }
                    else
                    {
                        bool condition = Grammar.DoesBelongToTerminals(current.GetCurrentNextSymbol());
                        if (!condition)
                        {
                            Predictor(current, i);
                        }
                        else if (input.Length > i)
                        {
                            Scanner(current, i, input[i]);
                        }
                    }
                }


                if (i + 1 < Sets.Count && Sets[i + 1].GetEarleyItemList().Count == 0)
                {
                    errorHandler.AddNewError(ErrorCode.UNRECOGNISED_SYMBOL, input[i], i);
                    return;
                }
            }
        }