Beispiel #1
0
 public Grammar transformToNonnullableGrammar(Grammar g)
 {
     List<Nonterminal> nonterminals = bulidNonterminalsForNonnullableGrammar(g);
     Nonterminal distinguishedSymbol = distinguishedSymbolForNonnullableGrammar(g);
     List<Rule> rules = buildRulesForNonnullableGrammar(g);
     Grammar g1 = new Grammar(nonterminals, g.Terminals, rules, distinguishedSymbol);
     g1.removeUnreachableSymbols();
     g1.findVanishingSymbols();
     return g1;
 }
Beispiel #2
0
 public override Grammar read(string fname)
 {
     Grammar g = new Grammar();
     StreamReader sr = new StreamReader(fname);
     string line;
     // читаем нетерминалы
     List<string> nonTerms = readBlock(sr);
     nonTerms.ForEach(s => g.Nonterminals.Add(new Nonterminal(s)));
     // читаем терминалы
     List<string> terms = readBlock(sr);
     terms.ForEach(s => g.Terminals.Add(new Terminal(s)));
     // читаем правила
     List<string> rules = readBlock(sr);
     g.Rules = parseRules(rules, terms, nonTerms);
     // читаем аксиому
     string axiom = readAxiom(sr);
     if (!nonTerms.Contains(axiom))
         throw new FormatException("Некорректный формат файла.");
     g.DistinguishedSymbol = new Nonterminal(axiom);
     sr.Close();
     g.findVanishingSymbols();
     return g;
 }