Ejemplo n.º 1
0
    protected void inserirAutomato(object sender, EventArgs e)
    {
        novo = new NovoAutomato(this);
        Automato novoAutomato = novo.getAutomato();

        automato = novoAutomato.getAutomato();
    }
Ejemplo n.º 2
0
    protected void OnButton6Clicked(object sender, EventArgs e)
    {
        Automato temp = new Automato(automatos.Count + 1);

        for (int i = 0; i < entradas.Count; i++)
        {
            temp.addEstado(entradas [i].estado1);
            temp.addSimbolo(entradas [i].simbolo);
            if (entradas [i].estado2.Text.Contains(","))
            {
                string[] quebra = entradas [i].estado2.Text.Split(',');
                for (int j = 0; j < quebra.Length; j++)
                {
                    temp.addEstado(quebra[j]);
                    temp.addTransicao(entradas [i].estado1, entradas [i].simbolo, quebra[j]);
                }
            }
            else
            {
                temp.addEstado(entradas [i].estado2.Text);
                temp.addTransicao(entradas [i].estado1, entradas [i].simbolo, entradas [i].estado2.Text);
            }
        }
        automatos.Add(temp);
        atualizarListaAutomatos();
    }
Ejemplo n.º 3
0
    public void coverterAFDGR(int indice)
    {
        Automato  temp  = automatos [indice];
        Gramatica GR    = new Gramatica(temp);
        string    texto = "";

        foreach (var t in GR.Producoes)
        {
            Gramatica.Regular producao = t.Value;
            string            parte    = "";
            for (int j = 0; j < producao.Proximos.Count; j++)
            {
                if (producao.Proximos.Count > 1)
                {
                    if (j == producao.Proximos.Count - 1)
                    {
                        parte += producao.Proximos[j];
                    }
                    else
                    {
                        parte += producao.Proximos[j] + "|";
                    }
                }
                else
                {
                    parte += producao.Proximos[j];
                }
            }
            //if ((producao.Atual != "" && parte != "") && (producao.Atual != "" || parte != "")) {
            texto += producao.Atual + "->" + parte + "\r\n";
            //}
        }
        textview2.Buffer.Text = texto;
    }
Ejemplo n.º 4
0
        public static Transicao EditaTransicao(Transicao t, Automato aut)
        {
            AlteraTransicao at = new AlteraTransicao();
            at.MontaCombos(aut);
            if (t != null)
            {
                at.cmbEstOr.SelectedItem = t.EstadoOrigem;
               // at.cmbEstDest.SelectedItem = t.EstadoDestino;
                at.cmbSimbolo.SelectedItem = t.Simbolo;
            }

            at.ShowDialog();
            if (at.Ok)
            {
                if (t == null)
                {
                    t = new Transicao();
                }

                t.EstadoOrigem = (Estado)at.cmbEstOr.SelectedItem;
               // t.EstadoDestino = (Estado)at.cmbEstDest.SelectedItem;
                t.Simbolo = (Simbolo)at.cmbSimbolo.SelectedItem;
                return t;
            }
            else {
                return null;
            }
        }
Ejemplo n.º 5
0
 /*
 public static Transicao getNewTransicao(Automato aut)
 {
     AlteraTransicao at = new AlteraTransicao();
     at.MontaCombos(aut);
     at.ShowDialog();
     return at.transicao;
 }*/
 public void MontaCombos(Automato at)
 {
     foreach (Estado e in at.Estados.Values)
     {
         cmbEstOr.Items.Add(e);
         cmbEstDest.Items.Add(e);
     }
     foreach (Simbolo s in at.Alfabeto.Values)
     {
         cmbSimbolo.Items.Add(s);
     }
 }
Ejemplo n.º 6
0
    public void minimizacao(int indice)
    {
        Automato automato   = automatos [indice];
        Automato minimizado = automato.Minimizacao(automato, automato.ID);

        foreach (var t in minimizado.transicoes)
        {
            foreach (string s in t.Value.estado2)
            {
                Console.WriteLine(t.Value.estado1 + " " + t.Value.simbolo + " " + s);
            }
        }
    }
Ejemplo n.º 7
0
 protected void OnDeterminizarAutmatoActionActivated(object sender, EventArgs e)
 {
     Automato atm = new Automato(automato);
 }
Ejemplo n.º 8
0
    public void converterGRAFND(int indice)
    {
        Gramatica        GR           = gramaticas [indice];
        Automato         temp         = GR.GetAutomato();
        List <string>    estados1     = new List <string>();
        List <string>    simbolos     = new List <string>();
        List <string[]>  transicao    = new List <string[]> ();
        HashSet <string> tempEstados1 = new HashSet <string> ();
        HashSet <string> tempSimbolos = new HashSet <string> ();

        foreach (var t in temp.transicoes)
        {
            Console.WriteLine(t.Value.estado1 + " " + t.Value.simbolo);
            string estado = "";
            foreach (string s in temp.estadosFinais)
            {
                if (t.Value.estado1 == temp.estadoInicial)
                {
                    estado = "+" + t.Value.estado1;
                }
                else if (t.Value.estado1 == s)
                {
                    estado = "*" + t.Value.estado1;
                }
                else
                {
                    estado = t.Value.estado1;
                }
            }
            tempEstados1.Add(estado);
            tempSimbolos.Add(t.Value.simbolo);
            foreach (string h in t.Value.estado2)
            {
                string estado2 = "";
                foreach (string s in temp.estadosFinais)
                {
                    if (h == temp.estadoInicial)
                    {
                        estado2 = "+" + h;
                    }
                    else if (h == s)
                    {
                        estado2 = "*" + h;
                    }
                    else if (h == temp.estadoInicial && h == s)
                    {
                        estado2 = "+*" + h;
                    }
                    else
                    {
                        estado2 = h;
                    }
                }
                string[] chave = { estado, t.Value.simbolo, estado2 };
                transicao.Add(chave);
            }
        }
        foreach (string x in tempEstados1)
        {
            estados1.Add(x);
        }
        foreach (string x in tempSimbolos)
        {
            simbolos.Add(x);
        }
        abrirAutomato(estados1, simbolos, transicao);
    }
Ejemplo n.º 9
0
    public void converterER(int indice)
    {
        ExpressaoRegular ER           = expressoes[indice];
        Automato         temp         = ER.transformaERemAFD();
        List <string>    estados1     = new List <string>();
        List <string>    simbolos     = new List <string>();
        List <string[]>  transicao    = new List <string[]> ();
        HashSet <string> tempEstados1 = new HashSet <string> ();
        HashSet <string> tempSimbolos = new HashSet <string> ();

        foreach (var t in temp.transicoes)
        {
            string estado = "";
            foreach (string s in temp.estadosFinais)
            {
                if (t.Value.estado1 == temp.estadoInicial)
                {
                    estado = "+" + t.Value.estado1;
                }
                else if (t.Value.estado1 == s)
                {
                    estado = "*" + t.Value.estado1;
                }
                else
                {
                    estado = t.Value.estado1;
                }
            }
            tempEstados1.Add(estado);
            tempSimbolos.Add(t.Value.simbolo);
            foreach (string h in t.Value.estado2)
            {
                string estado2 = "";
                foreach (string s in temp.estadosFinais)
                {
                    if (h == temp.estadoInicial)
                    {
                        estado2 = "+" + h;
                    }
                    else if (h == s)
                    {
                        estado2 = "*" + h;
                    }
                    else if (h == temp.estadoInicial && h == s)
                    {
                        estado2 = "+*" + h;
                    }
                    else
                    {
                        estado2 = h;
                    }
                }
                string[] chave = { estado, t.Value.simbolo, estado2 };
                transicao.Add(chave);
            }
        }
        foreach (string x in tempEstados1)
        {
            estados1.Add(x);
        }
        foreach (string x in tempSimbolos)
        {
            simbolos.Add(x);
        }
        abrirAutomato(estados1, simbolos, transicao);
    }
Ejemplo n.º 10
0
    public void interseccao(int indice1, int indice2)
    {
        Automato         automato1    = automatos [indice1];
        Automato         automato2    = automatos [indice2];
        Automato         temp         = automato2.Interseccao(automato1);
        List <string>    estados1     = new List <string>();
        List <string>    simbolos     = new List <string>();
        List <string[]>  transicao    = new List <string[]> ();
        HashSet <string> tempEstados1 = new HashSet <string> ();
        HashSet <string> tempSimbolos = new HashSet <string> ();

        foreach (var t in temp.transicoes)
        {
            string estado = "";
            foreach (string s in temp.estadosFinais)
            {
                if (t.Value.estado1 == temp.estadoInicial)
                {
                    estado = "+" + t.Value.estado1;
                }
                else if (t.Value.estado1 == s)
                {
                    estado = "*" + t.Value.estado1;
                }
                else
                {
                    estado = t.Value.estado1;
                }
            }
            tempEstados1.Add(estado);
            tempSimbolos.Add(t.Value.simbolo);
            foreach (string h in t.Value.estado2)
            {
                string estado2 = "";
                foreach (string s in temp.estadosFinais)
                {
                    if (h == temp.estadoInicial)
                    {
                        estado2 = "+" + h;
                    }
                    else if (h == s)
                    {
                        estado2 = "*" + h;
                    }
                    else if (h == temp.estadoInicial && h == s)
                    {
                        estado2 = "+*" + h;
                    }
                    else
                    {
                        estado2 = h;
                    }
                }
                string[] chave = { estado, t.Value.simbolo, estado2 };
                transicao.Add(chave);
            }
        }
        foreach (string x in tempEstados1)
        {
            estados1.Add(x);
        }
        foreach (string x in tempSimbolos)
        {
            simbolos.Add(x);
        }
        abrirAutomato(estados1, simbolos, transicao);
    }
Ejemplo n.º 11
0
    public void uniao(int indice1, int indice2)
    {
        Automato         automato1    = automatos[indice1];
        Automato         automato2    = automatos[indice2];
        Automato         temp         = automato2.Uniao(automato1);
        List <string>    estados1     = new List <string>();
        List <string>    simbolos     = new List <string>();
        List <string[]>  transicao    = new List <string[]> ();
        HashSet <string> tempEstados1 = new HashSet <string> ();
        HashSet <string> tempSimbolos = new HashSet <string> ();

        foreach (var t in temp.transicoes)
        {
            string estado = "";
            foreach (string s in temp.estadosFinais)
            {
                if (t.Value.estado1 == temp.estadoInicial)
                {
                    estado = "+" + t.Value.estado1;
                }
                else if (t.Value.estado1 == s)
                {
                    estado = "*" + t.Value.estado1;
                }
                else
                {
                    estado = t.Value.estado1;
                }
            }
            tempEstados1.Add(estado);
            tempSimbolos.Add(t.Value.simbolo);
            foreach (string h in t.Value.estado2)
            {
                string estado2 = "";
                foreach (string s in temp.estadosFinais)
                {
                    if (h == temp.estadoInicial)
                    {
                        estado2 = "+" + h;
                    }
                    else if (h == s)
                    {
                        estado2 = "*" + h;
                    }
                    else if (h == temp.estadoInicial && h == s)
                    {
                        estado2 = "+*" + h;
                    }
                    else
                    {
                        estado2 = h;
                    }
                }
                string[] chave = { estado, t.Value.simbolo, estado2 };
                transicao.Add(chave);
            }
        }
        foreach (string x in tempEstados1)
        {
            estados1.Add(x);
        }
        foreach (string x in tempSimbolos)
        {
            simbolos.Add(x);
        }
        string[] novaChave = new string[3];
        for (int i = 0; i < transicao.Count; i++)
        {
            string[] chave = transicao [i];
            for (int j = 0; j < transicao.Count; j++)
            {
                string[] chave2 = transicao [j];
                if (chave[0] == chave2[0] && chave[1] == chave2[1])
                {
                    if (chave[2] != chave2[2] && chave[2] != "" && chave2[2] != "")
                    {
                        novaChave [0] = chave [0];
                        novaChave [1] = chave [1];
                        novaChave [2] = chave [2] + "," + chave2 [2];
                    }
                }
            }
        }
        transicao.Add(novaChave);
        abrirAutomato(estados1, simbolos, transicao);
    }
Ejemplo n.º 12
0
    protected void OnCombobox1Changed(object sender, EventArgs e)
    {
        string[]         indice       = combobox1.ActiveText.Split(' ');
        Automato         temp         = automatos[Int32.Parse(indice[1])];
        List <string>    estados1     = new List <string>();
        List <string>    simbolos     = new List <string>();
        List <string[]>  transicao    = new List <string[]> ();
        HashSet <string> tempEstados1 = new HashSet <string> ();
        HashSet <string> tempSimbolos = new HashSet <string> ();

        foreach (var t in temp.transicoes)
        {
            string estado = "";
            foreach (string s in temp.estadosFinais)
            {
                if (t.Value.estado1 == temp.estadoInicial)
                {
                    estado = "+" + t.Value.estado1;
                }
                else if (t.Value.estado1 == s)
                {
                    estado = "*" + t.Value.estado1;
                }
                else if (t.Value.estado1 == temp.estadoInicial && t.Value.estado1 == s)
                {
                    estado = "+*" + t.Value.estado1;
                }
                else
                {
                    estado = t.Value.estado1;
                }
            }
            tempEstados1.Add(estado);
            tempSimbolos.Add(t.Value.simbolo);
            foreach (string h in t.Value.estado2)
            {
                string estado2 = "";
                foreach (string s in temp.estadosFinais)
                {
                    if (h == temp.estadoInicial)
                    {
                        estado2 = "+" + h;
                    }
                    else if (h == s)
                    {
                        estado2 = "*" + h;
                    }
                    else if (h == temp.estadoInicial && h == s)
                    {
                        estado2 = "+*" + h;
                    }
                    else
                    {
                        estado2 = h;
                    }
                }
                string[] chave = { estado, t.Value.simbolo, estado2 };
                transicao.Add(chave);
            }
        }
        foreach (string x in tempEstados1)
        {
            estados1.Add(x);
        }
        foreach (string x in tempSimbolos)
        {
            simbolos.Add(x);
        }
        List <string[]> tempTransicoesNDertermnisticas = new List <string[]> ();

        for (int i = 0; i < transicao.Count; i++)
        {
            string[] novaChave = new string[3];
            string[] chave     = transicao [i];
            for (int j = 0; j < transicao.Count; j++)
            {
                string[] chave2 = transicao [j];
                if (chave[0] == chave2[0] && chave[1] == chave2[1])
                {
                    if (chave[2] != chave2[2] && chave[2] != "" && chave2[2] != "")
                    {
                        novaChave [0] = chave [0];
                        novaChave [1] = chave [1];
                        novaChave [2] = chave [2] + "," + chave2 [2];
                    }
                }
            }
            tempTransicoesNDertermnisticas.Add(novaChave);
        }
        for (int i = 0; i < tempTransicoesNDertermnisticas.Count; i++)
        {
            transicao.Add(tempTransicoesNDertermnisticas[i]);
        }
        tempEstados1.Clear();
        tempSimbolos.Clear();
        foreach (string x in estados1)
        {
            Console.WriteLine("Estados 1: " + x);
        }
        foreach (string x in simbolos)
        {
            Console.WriteLine("Símbolos: " + x);
        }

        /*estados1.Clear ();
         * simbolos.Clear ();
         * transicao.Clear ();*/
        abrirAutomato(estados1, simbolos, transicao);
    }
Ejemplo n.º 13
0
 private void abrirToolStripMenuItem_Click(object sender, EventArgs e)
 {
     OpenFileDialog sfd = new OpenFileDialog();
     sfd.Filter = "XML Files|*.xml";
     sfd.ShowDialog();
     if (sfd.FileName != null && sfd.FileName != "")
     {
         Serializer s = new Serializer();
         SaveDataAutomato sd = (SaveDataAutomato) s.Busca(sfd.FileName, typeof(SaveDataAutomato ));
         AutomatoInstanciado = sd.ConvertSaveDataAutomato(sd);
         AtualizaAutomato();
     }
 }
Ejemplo n.º 14
0
 private void novoToolStripMenuItem_Click(object sender, EventArgs e)
 {
     AutomatoInstanciado = new Automato();
     AtualizaAutomato();
 }
Ejemplo n.º 15
0
        private void btnAFN_ANFDE_Click(object sender, EventArgs e)
        {
            try
            {
                TrasnformaAFND_AFD t = new TrasnformaAFND_AFD();

                t.AutomatoOriginal = AutomatoInstanciado;
                t.Tentativa3();

                AutomatoInstanciado = t.AutomatoNovo;

                AtualizaAutomato();
            }
            catch (Exception err) {
                MessageBox.Show(err.Message);
            }
        }