private void PreencherRegrasArParaArEArParaMaiorAr() { RolesArToGreatAs = new List <RuleProduction>(); RolesArToAr = new List <RuleProduction>(); RolesSubstituiArGreatAs = new List <RuleProduction>(); RolesReplaceArParaAr = new List <RuleProduction>(); for (int i = 0; i < Normalized.Rules.Count; i++) { RuleProduction rAtual = Normalized.Rules[i]; var destino = rAtual.Destiny.Copy(); if (rAtual.IsFirstVariable()) { if (NewNames.ContainsKey(rAtual.Source)) { if (NewNames[rAtual.Source].Id > NewNames[rAtual.FirstDestiny()].Id) { Normalized.Rules.Remove(rAtual); i--; List <RuleProduction> regrasDestino = Normalized.GetRules(rAtual.FirstDestiny()); RolesArToGreatAs.Add(rAtual); //Remoção de Regra, decrementa i for (int j = 0; j < regrasDestino.Count; j++) { RuleProduction regraTemp = Normalized.AddRule(rAtual.Source, regrasDestino[j].Destiny.AddRange(rAtual.SkipFirstDestiny())); RolesSubstituiArGreatAs.Add(regraTemp); } } else if (NewNames[rAtual.Source].Name == NewNames[rAtual.FirstDestiny()].Name) { RolesArToAr.Add(rAtual); var bAtual = new Symbol(GetNewId(), string.Empty, false); Normalized.Variables.Add(bAtual); destino = destino.SkipFirst(); RuleProduction regraTemp = Normalized.AddRule(bAtual, destino); RolesReplaceArParaAr.Add(regraTemp); regraTemp = Normalized.AddRule(bAtual, destino.Add(bAtual)); RolesReplaceArParaAr.Add(regraTemp); //Removi volta o i Normalized.Rules.Remove(rAtual); i--; List <RuleProduction> regrasOrigem = Normalized.GetRules(rAtual.Source); for (int j = 0; j < regrasOrigem.Count; j++) { regraTemp = Normalized.AddRule(rAtual.Source, regrasOrigem[j].Destiny.Add(bAtual)); RolesReplaceArParaAr.Add(regraTemp); } } } } } }
private void ColocarTerminalInicio() { for (int i = 0; i < Normalized.Rules.Count; i++) { RuleProduction rAtual = Normalized.Rules[i]; if (!rAtual.Destiny[0].Terminal) { //Removi regra volta regra Normalized.Rules.Remove(rAtual); i--; var destino = rAtual.SkipFirstDestiny(); List <RuleProduction> regras = Normalized.GetRules(rAtual.FirstDestiny()); for (int j = 0; j < regras.Count; j++) { RuleProduction regraTemp = Normalized.AddRule(rAtual.Source, regras[j].Destiny.Copy().AddRange(destino)); } } } }