Ejemplo n.º 1
0
        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();
        }
Ejemplo n.º 2
0
 public bool IsNullable(NonterminalSymbol nt)
 {
     return(mNullableSymbols.Contains(nt));
 }
Ejemplo n.º 3
0
 public IReadOnlyList <GrammarProduction> this[NonterminalSymbol nt] {
     get {
         return(mProductionsByNTSymbol[nt]);
     }
 }
Ejemplo n.º 4
0
 public GrammarProduction(NonterminalSymbol head, SymbolString body)
 {
     this.Head = head;
     this.Body = body;
 }