예제 #1
0
파일: Grammar.cs 프로젝트: sunny-hell/bmstu
 public Grammar(List<Nonterminal> nonterminals, List<Terminal> terminals, List<Rule> rules, Nonterminal distinguishedSymbol)
 {
     _nonterminals = new List<Nonterminal>(nonterminals);
     _terminals = new List<Terminal>(terminals);
     _rules = new List<Rule>(rules);
     _distinguishedSymbol = distinguishedSymbol;
     //findVanishingSymbols();
 }
예제 #2
0
파일: Grammar.cs 프로젝트: sunny-hell/bmstu
 public Grammar(Grammar g)
 {
     _nonterminals = new List<Nonterminal>(g.Nonterminals);
     _terminals = new List<Terminal>(g.Terminals);
     _rules = new List<Rule>(g.Rules);
     _distinguishedSymbol = new Nonterminal(g.DistinguishedSymbol);
     _vanishingSymbols = new List<Nonterminal>(g.VanishingSymbols);
 }
예제 #3
0
 public Nonterminal(Nonterminal nt)
 {
     _sym = nt.Sym;
 }
예제 #4
0
파일: Rule.cs 프로젝트: sunny-hell/bmstu
 public Rule(Nonterminal left, List<Symbol> right)
 {
     _left = new Nonterminal(left);
     _right = new List<Symbol>(right);
 }
예제 #5
0
파일: Rule.cs 프로젝트: sunny-hell/bmstu
 public Rule(Rule r)
 {
     _left = new Nonterminal(r.Left);
     _right = new List<Symbol>(r.Right);
 }
예제 #6
0
파일: Rule.cs 프로젝트: sunny-hell/bmstu
 public Rule()
 {
     _left = new Nonterminal();
     _right = new List<Symbol>();
 }
예제 #7
0
 private List<Symbol> nonterminalToSymbolString(Nonterminal nt)
 {
     return _nonterminalSymbolStringMap[nt.Sym];
 }
예제 #8
0
 private List<Rule> createRulesForLeftVanishing(List<Rule> curRules, Nonterminal left)
 {
     List<Rule> newRules = new List<Rule>();
     foreach (Rule r in curRules)
     {
         Rule newRule = new Rule(r);
         newRule.Left = _nonnullableNonterminalsMap[left.Sym];
         newRules.Add(newRule);
     }
     return newRules;
 }
예제 #9
0
 private List<Nonterminal> bulidNonterminalsForNonnullableGrammar(Grammar g)
 {
     _nonnullableNonterminalsMap = new Dictionary<string, Nonterminal>();
     List<Nonterminal> N = new List<Nonterminal>(g.Nonterminals);
     foreach (Nonterminal vs in g.VanishingSymbols)
     {
         Nonterminal newNonterminal = new Nonterminal(String.Format("{0}*", vs.Sym));
         N.Add(newNonterminal);
         _nonnullableNonterminalsMap.Add(vs.Sym, newNonterminal);
     }
     return N;
 }
예제 #10
0
 private List<Rule> buildRulesForNonterminal(Nonterminal nonterminal, Grammar g)
 {
     List<Rule> newRules = new List<Rule>();
     List<Rule> rules = new List<Rule>();
     List<Symbol> symStr = nonterminalToSymbolString(nonterminal);
     List<Symbol> firstTerminals = symStr.TakeWhile(ss => ss is Terminal).ToList();
     foreach (Symbol nt in symStr)
         if (nt is Nonterminal)
         {
             int ind = symStr.IndexOf(nt);
             List<Symbol> restOfString = symStr.GetRange(ind + 1, symStr.Count - ind - 1);
             foreach (Rule r in g.Rules)
             {
                 if (r.Left.Sym == nt.Sym && !r.isERule())
                 {
                     Rule newRule = new Rule();
                     newRule.Left = new Nonterminal(nonterminal);
                     newRule.Right = buildRightPartOfNewRule(firstTerminals, restOfString, r);
                     newRules.Add(newRule);
                 }
             }
             if (ind == 0)
                 break;
         }
     if (firstTerminals.Count != 0)
         newRules.Add(new Rule((Nonterminal)nonterminal, firstTerminals));
     return newRules;
 }