Пример #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 void Scanner(EarleyItem current, int setNumber, Char inputSymbol)
        {
            Symbol nextSymbol = current.GetCurrentNextSymbol();

            if (nextSymbol != null && nextSymbol.Equals(inputSymbol.ToString()))
            {
                EarleyItem newEarleyItem = new EarleyItem(
                    setNumber + 1,
                    new DottedRule(current.GetRule(), current.GetRulePosition() + 1),
                    current.GetOrignPosition()
                    );
                if (newEarleyItem.GetCurrentPrevSymbolList() != null && newEarleyItem.GetCurrentPrevSymbolList().Count > 0)
                {
                    newEarleyItem.AddPredecessorLink(current, setNumber);
                }

                AddToSet(newEarleyItem, setNumber + 1, "Scanner");
            }
        }
Пример #3
0
        private void Predictor(EarleyItem current, int setNumber)
        {
            Symbol      sym           = current.GetCurrentNextSymbol();
            List <Rule> filteredRules = Grammar.GetRulesWithSpecificStartSymbol(sym);

            filteredRules.ForEach((Rule r) =>
            {
                List <Symbol> symList = r.GetRightHandSideOfRule();
                if (symList.Count == 1 && Grammar.CheckIsSymbolANullStringSymbol(symList[0]))
                {
                    AddToSet(new EarleyItem(setNumber, new DottedRule(current.GetRule(), current.GetRulePosition() + 1), setNumber), setNumber, "Predictor");
                }
                else
                {
                    EarleyItem ei = new EarleyItem(setNumber, r, setNumber);
                    AddToSet(ei, setNumber, "Predictor");
                    LeoMemoization(ei, setNumber);
                }
            });
        }
Пример #4
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;
                }
            }
        }