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); }
private static SymbolsChain FirstRightSideChain(SymbolsChain chain, Nonterminal nonterminal) { int index = chain.FindIndex(nonterminal); if (index == -1) { return(null); } return(chain.Subchain(index + 1)); }
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); }
public Production(Nonterminal leftPart, SymbolsChain rightPart) { LeftPart = leftPart; RightPart = rightPart; }