public GrammarProductionDatabase(IEnumerable <GrammarProduction> productions, NonterminalSymbol startingSymbol) { var productionsPlusStart = productions.Union( new GrammarProduction[] { new GrammarProduction(NonterminalSymbol.StartingSymbol, new SymbolString(new Symbol[] { startingSymbol })) }); this.Productions = new HashSet <GrammarProduction>(productionsPlusStart).OrderBy(p => p).ToList().AsReadOnly(); this.Nonterminals = new HashSet <NonterminalSymbol>(this.Productions.Select(p => p.Head)).OrderBy(nt => nt).ToList().AsReadOnly(); this.StartingSymbol = NonterminalSymbol.StartingSymbol; MapProductionsToNTSymbols(); ComputeNullableSymbols(); }
public bool IsNullable(NonterminalSymbol nt) { return(mNullableSymbols.Contains(nt)); }
public IReadOnlyList <GrammarProduction> this[NonterminalSymbol nt] { get { return(mProductionsByNTSymbol[nt]); } }
public GrammarProduction(NonterminalSymbol head, SymbolString body) { this.Head = head; this.Body = body; }