Пример #1
0
        private HashSet <ISymbol> CreateRightRecursiveSymbols(
            IDottedRuleRegistry dottedRuleRegistry,
            Dictionary <ISymbol, UniqueList <ISymbol> > symbolPaths)
        {
            var hashSet = new HashSet <ISymbol>();

            for (var p = 0; p < _productions.Count; p++)
            {
                var production = _productions[p];
                var position   = production.RightHandSide.Count;
                var completed  = dottedRuleRegistry.Get(production, position);
                var symbolPath = symbolPaths[production.LeftHandSide];

                for (var s = position; s > 0; s--)
                {
                    var preDotSymbol = production.RightHandSide[s - 1];
                    if (preDotSymbol.SymbolType != SymbolType.NonTerminal)
                    {
                        break;
                    }

                    var preDotNonTerminal = preDotSymbol as INonTerminal;
                    if (symbolPath.Contains(preDotNonTerminal))
                    {
                        hashSet.Add(production.LeftHandSide);
                        break;
                    }
                    if (!IsTransativeNullable(preDotNonTerminal))
                    {
                        break;
                    }
                }
            }
            return(hashSet);
        }
Пример #2
0
        private void PredictProduction(int j, IProduction production)
        {
            var dottedRule = _dottedRuleRegistry.Get(production, 0);

            if (_chart.Contains(j, StateType.Normal, dottedRule, 0))
            {
                return;
            }
            // TODO: Pre-Compute Leo Items. If item is 1 step from being complete, add a transition item
            var predictedState = StateFactory.NewState(dottedRule, j);

            if (_chart.Enqueue(j, predictedState))
            {
                Log(PredictionLogName, j, predictedState);
            }
        }