Esempio n. 1
0
        public void GerarPalavraAPartirDaSequencia()
        {
            string Resultado = string.Empty;

            for (int i = 0; i < Sequencia.Count; i++)
            {
                if (i == 0)
                {
                    Resultado = Inicial;
                }

                var seq = Sequencia[i];

                var regra = RegrasDeProducao.Where(x => x.Indice == seq).FirstOrDefault();

                Resultado = SubstituirPrimeiraOcorrencia(Resultado, regra.De, regra.Para);
            }

            var LetrasDoResultado = Resultado.ToCharArray().ToList();

            foreach (var LetraResultado in LetrasDoResultado)
            {
                if (!Alfabeto.Contains(LetraResultado.ToString()))
                {
                    Erro = $"O resultado da linguagem gerada nĂŁo pertence ao alfabeto. Alfabeto: {string.Join(", ", Alfabeto)} | Resultado: {Resultado}";
                    return;
                }
            }

            Resposta = Resultado;
        }
Esempio n. 2
0
        private void LerAlfabeto()
        {
            int op;

            Console.WriteLine("Insira o alfabeto");
            do
            {
                Console.WriteLine("Escreva um simbolo para ser inserido: ");
                var simbolo = Convert.ToChar(Console.ReadLine() ?? throw new InvalidOperationException());

                if (Alfabeto.Any(a => a == simbolo))
                {
                    Console.WriteLine($"Simbolo {simbolo} ja foi inserido no alfabeto");
                }
                else
                {
                    Alfabeto.Add(simbolo);
                }

                Console.WriteLine("Deseja inserir mais um caracter no alfabeto? 1- Sim 0- NĂŁo");
                op = Convert.ToInt32(Console.ReadLine());

                Console.WriteLine("\n\n" + MostrarAlfabeto());
            } while (op == 1);
        }
Esempio n. 3
0
 public void AgregarAlfabeto(params char[] alfabeto)
 {
     foreach (var item in alfabeto)
     {
         Alfabeto.Add(item);
     }
 }
Esempio n. 4
0
        static void Main(string[] args)
        {
            string continuar = "";

            do
            {
                var alfabetoLista = new List <Alfabeto>();

                char letras = 'a';
                for (int contador = 1; contador <= 26; contador++, letras++)
                {
                    var ap = new Alfabeto {
                        Letra = letras, Numero = contador
                    };
                    alfabetoLista.Add(ap);
                }

                C.WriteLine("Digite uma palavra");
                string palavraDigitada = C.ReadLine();
                char[] charArray       = palavraDigitada.ToLower().ToCharArray();

                foreach (var item in charArray)
                {
                    if (!item.ToString().Contains(" "))
                    {
                        C.Write(alfabetoLista.FirstOrDefault(c => c.Letra == item).Numero.ToString() + " ");
                    }
                }

                C.ReadKey();
                C.WriteLine("Deseja Continuar [S/N]");
                continuar = C.ReadLine();
            } while (continuar.ToLower() == "s");
        }
    private void ConfigurarTransicoes()
    {
        Console.WriteLine("Nessa etapa você deve informar para cada estado o símbolo de entrada e o estado de transição. \nCaso tenha terminado o mapeamento ou não desejas mapear para o estado informado, digite proximo.");
        Dictionary <string, Dictionary <string, string> > transicoes = new Dictionary <string, Dictionary <string, string> >();

        foreach (string estado in Estados)
        {
            Dictionary <string, string> mapaEstado = new Dictionary <string, string>();
            Console.WriteLine($"Para o estado: {estado}, digite o símbolo de entrada com o estado de transição separado por vírgula.\n Após aperte enter. Ex: Letra,estado");
            string mapeamento = "";
            do
            {
                mapeamento = Console.ReadLine();
                if (!mapeamento.Contains(","))
                {
                    Console.WriteLine("Entrada não está no formato especificado.");
                    continue;
                }

                string[] vetorLeitura = mapeamento.Split(",");
                if (!Alfabeto.Contains(vetorLeitura[0]) || !Estados.Contains(vetorLeitura[1]))
                {
                    Console.WriteLine("Entrada não está no alfabeto cadastrado ou estado informado não foi cadastrado previamente. Verfique e tente novamente.");
                    continue;
                }

                mapaEstado.Add(vetorLeitura[0], vetorLeitura[1]);
            } while (!mapeamento.Equals("proximo"));
            transicoes.Add(estado, mapaEstado);
        }
        Transicoes = transicoes;
    }
Esempio n. 6
0
 //Genero el nuevo alfabeto(que tiene al default)
 //Inicializo la lista de algoritmos
 //Inicializo la lista de formatos
 //Inicializa la lista
 private Configuracion()
 {
     alfabeto   = new Alfabeto();
     algoritmos = new List <InterfazAlgoritmo>();
     formatos   = new List <InterfaceFormato>();
     metodo     = "";
 }
        private void buttonGenAlfa_Click(object sender, EventArgs e)
        {
            //Validando que haya un dato deentrada en el textBoxNombre
            if (textBoxNombre.Text.Length == 0 || textBoxMatricula.Text.Length == 0 || textBoxApellido.Text.Length == 0)
            {
                MessageBox.Show("No se a ingresado nombre, apellido y/o matricula", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Condiciones cond = new Condiciones();
                bool        mat  = cond.validadorMatricula(textBoxMatricula.Text);

                if (mat)
                {
                    Alfabeto alf2 = new Alfabeto();

                    labelMuestraAlfabeto.Text = "{ " + string.Join(",", alf2.obtenerAlfabeto(textBoxNombre.Text.ToLower() + textBoxApellido.Text.ToLower(), textBoxMatricula.Text)) + " }";

                    Gramatica gram2 = new Gramatica();
                    labelj.Text  = "j={ " + string.Join(",", gram2.obtenernombre(textBoxNombre.Text.ToLower())) + " }";
                    labeli.Text  = "i={ " + string.Join(",", gram2.obtenerMatricula(textBoxMatricula.Text)) + " }";
                    labelw.Text  = "w={ " + string.Join(",", gram2.obteneriniciales(textBoxApellido.Text.ToLower(), 1)) + " }";
                    labelwi.Text = "w^I={ " + string.Join(",", gram2.obteneriniciales(textBoxApellido.Text.ToLower(), 2)) + " }";
                }
                else
                {
                    MessageBox.Show("La matricula debe de tener Ăşnicamente nĂşmeros", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
        private void buttonAceptar_Click(object sender, EventArgs e)
        {
            //Validando que haya un dato deentrada en el textBoxNombre
            if (textBoxNombre.Text.Length == 0 || textBoxMatricula.Text.Length == 0 || textBoxApellido.Text.Length == 0)
            {
                MessageBox.Show("No se a ingresado nombre, apellido y/o matricula", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                Condiciones cond = new Condiciones();
                bool        mat  = cond.validadorMatricula(textBoxMatricula.Text);

                if (mat)
                {
                    //Creamos la lista que tendra a nuestro alfabeto
                    List <char> alfabeto = new List <char>();

                    Alfabeto alf2 = new Alfabeto();
                    alfabeto = alf2.obtenerAlfabeto(textBoxNombre.Text.ToLower() + textBoxApellido.Text.ToLower(), textBoxMatricula.Text);

                    labelMuestraAlfabeto.Text = "{ " + string.Join(",", alf2.obtenerAlfabeto(textBoxNombre.Text.ToLower() + textBoxApellido.Text.ToLower(), textBoxMatricula.Text)) + " }";

                    Gramatica gram2 = new Gramatica();
                    labelj.Text  = "j={ " + string.Join(",", gram2.obtenernombre(textBoxNombre.Text.ToLower())) + " }";
                    labeli.Text  = "i={ " + string.Join(",", gram2.obtenerMatricula(textBoxMatricula.Text)) + " }";
                    labelw.Text  = "w={ " + string.Join(",", gram2.obteneriniciales(textBoxApellido.Text.ToLower(), 1)) + " }";
                    labelwi.Text = "w^I={ " + string.Join(",", gram2.obteneriniciales(textBoxApellido.Text.ToLower(), 2)) + " }";

                    ValidarExpresion vExp = new ValidarExpresion(textBoxNombre.Text.ToLower(), textBoxApellido.Text.ToLower(), textBoxMatricula.Text);

                    //variables booleanas para guardar el estado true false de algunas condiciones
                    bool    SoloAlfabeto = cond.EnAlfabeto(textBoxExpresion.Text, alfabeto);
                    bool [] estados      = vExp.validar(textBoxExpresion.Text);

                    if (textBoxExpresion.Text.Length != 0)
                    {
                        MessageBox.Show("Esta en alfabeto: " + SoloAlfabeto +
                                        "\nInicia con la matricula: " + estados[0] +
                                        "\nContiene w: " + estados[1] +
                                        "\nContiene I en medio: " + estados[2] +
                                        "\nContiene 2 wI por cada w: " + estados[3] +
                                        "\nTermina con el nombre repetido 2 veces" + estados[4]);
                    }
                    else
                    {
                        MessageBox.Show("USTED INGRESO NADA", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("La matricula debe de tener Ăşnicamente nĂşmeros", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                }
            }
        }
Esempio n. 9
0
 public void AgregarEstado(Estado estado)
 {
     foreach (var transicion in estado.Transiciones)
     {
         if (AlfabetoAutomatico)
         {
             Alfabeto.Add(transicion.Key);
         }
         else if (!Alfabeto.Contains(transicion.Key))
         {
             throw new TransitionNotInAlphabetException();
         }
     }
     Estados.Add(estado);
     estado.AutomataPadre = this;
 }
Esempio n. 10
0
        /// <summary>
        /// Validação para Inicio do AFD
        /// </summary>
        /// <param name="palavra"></param>
        /// <param name="sistema"></param>
        /// <returns></returns>
        public bool IsValid(string palavra, Sistema sistema)
        {
            //Verifica se a palavra esta de acordo com o alfabet
            if (true)
            {
                int count = 0;
                foreach (var letra in palavra)
                {
                    if (Alfabeto.Contains(letra.ToString()))
                    {
                        count++;
                    }
                }
                if (palavra.Length != count)
                {
                    return(false);
                }
            }
            //Verifica se o estado Inicial e Final esta na lista de estados
            if (true)
            {
                if (!ListEstados.Contains(Iestado))
                {
                    return(false);
                }

                int count = (Festado.Where(item => ListEstados.Contains(item))).Count();
                if (count != Festado.Count)
                {
                    return(false);
                }
            }
            //Verifica se o valor das transições esta no alfabeto
            if (true)
            {
                foreach (var item in ListaTransicao)
                {
                    if (!Alfabeto.Contains(item.NextItem))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
Esempio n. 11
0
 /// <summary>
 /// Recebe dados do arquivo e transforma em Objetos
 /// </summary>
 /// <param name="file"></param>
 private void RecebeDados(string[] file)
 {
     nEstados    = file[0].Split(' ').Count();
     ListEstados = file[0].Split(' ').ToList();
     Alfabeto    = file[1].ToLower().Split(' ').ToList();
     if (Alfabeto.Contains("d"))
     {
         Alfabeto = AlteraAlfabeto(Alfabeto);
     }
     Iestado = file[2].ToUpper();
     Festado = file[3].ToUpper().Split(' ').ToList();
     for (int i = 4; i < file.Length; i++)
     {
         Transicao.Add(file[i].ToLower().Split(' ').ToList());
     }
     //aaaa
 }
Esempio n. 12
0
        private string MostrarAlfabeto()
        {
            var alfabeto = "Alfabeto: ";

            foreach (var simbolo in Alfabeto)
            {
                if (simbolo == Alfabeto.Last())
                {
                    alfabeto += simbolo;
                }
                else
                {
                    alfabeto += simbolo + ", ";
                }
            }

            return(alfabeto);
        }
        public Principal(string Nombre, string Apellido, string Matricula)
        {
            InitializeComponent();

            //Le asignamos a los textbox Nombre y Matricula los valores por default
            textBoxNombre.Text    = Nombre;
            textBoxApellido.Text  = Apellido;
            textBoxMatricula.Text = Matricula;

            //Creamos un objeto de tipo alfabeto_y _gramatica para acceder a sus funciones
            Alfabeto alf1 = new Alfabeto();

            labelMuestraAlfabeto.Text = "{ " + string.Join(",", alf1.obtenerAlfabeto(Nombre.ToLower() + Apellido.ToLower(), Matricula)) + " }";

            //Muestra las expresiones i, j, w, w^I
            Gramatica gram = new Gramatica();

            labelj.Text  = "j={ " + string.Join(",", gram.obtenernombre(Nombre.ToLower())) + " }";
            labeli.Text  = "i={ " + string.Join(",", gram.obtenerMatricula(Matricula)) + " }";
            labelw.Text  = "w={ " + string.Join(",", gram.obteneriniciales(Apellido.ToLower(), 1)) + " }";
            labelwi.Text = "w^I={ " + string.Join(",", gram.obteneriniciales(Apellido.ToLower(), 2)) + " }";
        }
Esempio n. 14
0
        public static void imprimirTabuleiro(Tabuleiro tabuleiro)
        {
            int contadorColuna = 0;

            for (int i = 0; i < tabuleiro.linhas; i++)
            {
                for (int j = 0; j < tabuleiro.colunas; j++)
                {
                    if (j == 0)
                    {
                        Console.Write(tabuleiro.colunas - contadorColuna + " ");
                        contadorColuna++;
                    }
                    imprimirPeca(tabuleiro.peca(i, j));
                }
                Console.WriteLine();
            }
            Console.Write(" ");
            for (int i = 0; i < tabuleiro.colunas; i++)
            {
                Console.Write(" " + Alfabeto.getLetra(i));
            }
            Console.WriteLine();
        }
Esempio n. 15
0
 public Cifrador(Alfabeto abecedario)
 {
     alfabeto = abecedario;
 }
Esempio n. 16
0
 public void Perfect_lower_case()
 {
     Assert.True(Alfabeto.Verifica("abcdefghijklmnopqrstuvwxyz"));
 }
Esempio n. 17
0
 public void Missing_the_letter_t()
 {
     Assert.False(Alfabeto.Verifica("Ma che bel gufo spenzola da quei ravi"));
 }
 public CifradorVigenere()
 {
     Alfabeto alfabeto = new Alfabeto();
 }
Esempio n. 19
0
 public void With_numbers()
 {
     Assert.True(Alfabeto.Verifica("the 1 quick brown fox jumps over the 2 lazy dogs"));
 }
Esempio n. 20
0
 public void With_underscores()
 {
     Assert.True(Alfabeto.Verifica("Qualche vago ione tipo zolfo, bromo, sodio"));
 }
Esempio n. 21
0
 public void Missing_letters_replaced_by_numbers()
 {
     Assert.False(Alfabeto.Verifica("7h3 qu1ck brown fox jumps ov3r 7h3 lazy dog"));
 }
Esempio n. 22
0
 public void Mixed_case_and_punctuation()
 {
     Assert.True(Alfabeto.Verifica("\"Five quacking Zephyrs jolt my wax bed.\""));
 }
Esempio n. 23
0
 public void Case_insensitive()
 {
     Assert.True(Alfabeto.Verifica("Che Tempi brevi zio, quando solfeggi "));
 }
Esempio n. 24
0
 public void Empty_sentence()
 {
     Assert.False(Alfabeto.Verifica(""));
 }
Esempio n. 25
0
 public void Only_lower_case()
 {
     Assert.True(Alfabeto.Verifica("the quick brown fox jumps over the lazy dog"));
 }