Exemplo n.º 1
0
 private void breakRuleForNonnullableGrammar(Rule r, Grammar g, out List<Nonterminal> firstVanishing, out List<Symbol> rest)
 {
     firstVanishing = new List<Nonterminal>();
     rest = new List<Symbol>();
     foreach (Symbol s in r.Right)
     {
         if (rest.Count > 0)
             rest.Add(s);
         else
             if (g.isVanishingSymbol(s))
                 firstVanishing.Add((Nonterminal)s);
             else
                 rest.Add(s);
     }
 }
Exemplo n.º 2
0
        private List<Rule> buildRulesForNonnullableGrammar(Grammar g)
        {
            List<Rule> rules = new List<Rule>();
            List<Rule> newRules = new List<Rule>();
            foreach (Rule r in g.Rules)
            {
                if (r.isERule())
                    rules.Add(r);
                else
                {
                    newRules.Clear();
                    List<Nonterminal> firstVanishing;
                    List<Symbol> rest;
                    breakRuleForNonnullableGrammar(r, g, out firstVanishing, out rest);
                    if (firstVanishing.Count > 0)
                        newRules.AddRange(createNewRulesForFisrtVanishing(r, firstVanishing, rest));
                    if (rest.Count > 0)
                        newRules.Add(createRuleWithNoFisrtVanishing(r, rest));
                    if (g.isVanishingSymbol(r.Left))
                        newRules.AddRange(createRulesForLeftVanishing(newRules, r.Left));
                    rules.AddRange(newRules);
                }

            }
            return rules;
        }
Exemplo n.º 3
0
 private Nonterminal distinguishedSymbolForNonnullableGrammar(Grammar g)
 {
     Nonterminal S;
     if (g.isVanishingSymbol(g.DistinguishedSymbol))
         S = _nonnullableNonterminalsMap[g.DistinguishedSymbol.Sym];
     else
         S = g.DistinguishedSymbol;
     return S;
 }