예제 #1
0
        public static ISet <Terminal> First(IEnumerable <Production> productions, SymbolsChain chain)
        {
            var first = CreateNewEmptyTerminalSet();

            bool            allSymbolsIsEpsilonGenerating = true;
            var             enumerator = chain.GetEnumerator();
            ISet <Terminal> curFirst   = null;

            while (enumerator.MoveNext())
            {
                curFirst = First(productions, enumerator.Current);
                first.UnionWith(curFirst.ExceptTerminal(GeneralizedTerminal.Epsilon));

                if (!curFirst.Contains(GeneralizedTerminal.Epsilon))
                {
                    allSymbolsIsEpsilonGenerating = false;
                    break;
                }
            }

            if (allSymbolsIsEpsilonGenerating)
            {
                first.Add(GeneralizedTerminal.Epsilon);
            }

            return(first);
        }
예제 #2
0
        private static SymbolsChain FirstRightSideChain(SymbolsChain chain, Nonterminal nonterminal)
        {
            int index = chain.FindIndex(nonterminal);

            if (index == -1)
            {
                return(null);
            }

            return(chain.Subchain(index + 1));
        }
예제 #3
0
        private static IEnumerable <SymbolsChain> RightSideChains(SymbolsChain chain, Nonterminal nonterminal)
        {
            var rightChains = new List <SymbolsChain>();

            SymbolsChain current = chain;

            do
            {
                current = FirstRightSideChain(current, nonterminal);

                if (current != null)
                {
                    rightChains.Add(current);
                }
                else
                {
                    break;
                }
            } while (true);

            return(rightChains);
        }
예제 #4
0
        public Production(Nonterminal leftPart, SymbolsChain rightPart)
        {
            LeftPart = leftPart;

            RightPart = rightPart;
        }