Ejemplo n.º 1
0
        private void EarleyComplete(CompletedState completed, int location)
        {
            var originSet = Chart[completed.Origin];

            // Predictions may grow
            var p = 0;

            for (; p < originSet.NonterminalStates.Count; ++p)
            {
                var nonterminal = originSet.NonterminalStates[p];
                if (!nonterminal.IsSource(completed.Head))
                {
                    continue;
                }

                var dottedRule = nonterminal.DottedRule.Next;
                var origin     = nonterminal.Origin;

                if (Chart.Contains(location, dottedRule, origin))
                {
                    continue;
                }

                var nextState = EarleyItems.NewState(dottedRule, origin);

                if (Chart.Add(location, nextState))
                {
                    Log(compName, location, nextState);
                }
            }
        }
Ejemplo n.º 2
0
        private void Initialize()
        {
            foreach (var startProduction in Grammar.ProductionsForStart())
            {
                var startState = EarleyItems.NewState(startProduction, 0, 0);

                if (Chart.Add(0, startState))
                {
                    Log(startName, 0, startState);
                }
            }

            ReductionPass();
        }
Ejemplo n.º 3
0
        private void PredictProduction(int location, Production production)
        {
            var dottedRule = DottedRules.Get(production, 0);

            if (Chart.Contains(location, dottedRule, 0))
            {
                return;
            }

            var predictedState = EarleyItems.NewState(dottedRule, location);

            if (Chart.Add(location, predictedState))
            {
                Log(predName, location, predictedState);
            }
        }
Ejemplo n.º 4
0
        private void PredictAycockHorspool(NonterminalState evidence, int location)
        {
            var dottedRule = evidence.DottedRule.Next;

            if (Chart.Contains(location, dottedRule, evidence.Origin))
            {
                return;
            }

            var aycockHorspoolState = EarleyItems.NewState(dottedRule, evidence.Origin);

            if (Chart.Add(location, aycockHorspoolState))
            {
                Log(predName, location, aycockHorspoolState);
            }
        }
Ejemplo n.º 5
0
        private void Scan(TerminalState terminal, IToken token)
        {
            var currentSymbol = terminal.DottedRule.PostDot as Terminal;

            if (token.IsFrom(currentSymbol))
            {
                var dottedRule = terminal.DottedRule.Next;
                if (Chart.Contains(Location + 1, dottedRule, terminal.Origin))
                {
                    return;
                }

                var nextState = EarleyItems.NewState(dottedRule, terminal.Origin);

                if (Chart.Add(Location + 1, nextState))
                {
                    LogScan(Location + 1, nextState, token);
                }
            }
        }