public void MueveX_a(List <String> lis_cerraduras, Transiciones transicion, List <String> mueve_ira)
        {
            for (int i = 0; i < lis_cerraduras.Count; ++i)
            {
                NodeAFN nod_stado = return_nodoMueve(lis_cerraduras.ElementAt(i));

                //if (transicion.transicion.Equals(nod_stado.Tran_left))
                if (transicion.transicion.Equals(nod_stado.Tran_left) &&
                    nod_stado.Tran_left_Tipo == Tipo.TipoN.NORMAL && transicion.tipo.Equals(nod_stado.tipo))
                {
                    if (nod_stado.left != null)
                    {
                        //MessageBox.Show(nod_stado.left.lexema, transicion.transicion + " izq");
                        mueve_ira.Add(nod_stado.left.lexema);
                    }
                }
                ////if (transicion.transicion.Equals(nod_stado.Tran_right))
                //if (transicion.transicion.Equals(nod_stado.Tran_right) &&
                //    nod_stado.Tran_left_Tipo == Tipo.TipoN.NORMAL)
                //{
                //    if (nod_stado.right != null)
                //    {
                //        //MessageBox.Show(nod_stado.right.lexema, transicion.transicion + " der");
                //        mueve_ira.Add(nod_stado.right.lexema);
                //    }

                //}
            }
        }
        //public NodeAFN(String lexema, int id, String Anulable, int identificador, String primeros, String ultimos, String tipo)
        public NodeAFN(String lexema, int id, String tipo, Tipo.TipoN tipo_n)
        {
            this.id     = id;
            this.lexema = lexema;
            this.left   = null;
            this.right  = null;

            this.Tran_left  = null;
            this.Tran_right = null;

            this.ultimo_ref = null;

            this.visitado     = false;
            this.nod_visitado = "N";

            this.tempo_copy = null;

            //this.Anulable = Anulable;
            //this.identificador = identificador;
            //this.primeros = primeros;
            //this.ultimos = ultimos;

            this.tipo   = tipo;
            this.tipo_n = tipo_n;

            this.Tran_left_Tipo  = Tipo.TipoN.NULL;
            this.Tran_right_Tipo = Tipo.TipoN.NULL;

            this.height = 1;
        }
        public Boolean graficando_Thomson()
        {
            StringBuilder graf = new StringBuilder();      //grafica total

            StringBuilder automatas = new StringBuilder(); // para las transiciones
            StringBuilder finales   = new StringBuilder(); // para los estados finales

            graf.Append("digraph finite_state_machine {\n");
            graf.Append("rankdir=LR;\n");
            graf.Append("size=\"8,5\"");
            graf.Append("\n");

            //for (int i = 0; i < tab_transiciones.size(); i++)
            //{

            //    if (tab_transiciones.get(i).terminal.equals("F"))
            //    {
            //        finales.Append(" " + tab_transiciones.get(i).name_estado);
            //    }

            //    for (int j = 0; j < tab_transiciones.get(i).ir_a.size(); j++)
            //    {

            //        automatas.Append(tab_transiciones.get(i).name_estado + " -> " + tab_transiciones.get(i).ir_a.get(j).Ir_a_Estado);
            //        automatas.Append("[ label = \"" + tab_transiciones.get(i).ir_a.get(j).terminal + "\" ];");
            //        automatas.Append("\n");

            //    }
            //}
            VerArbol(automatas);

            //////VerArbol(graf);

            //graf.Append("node [shape = doublecircle]; ");
            //graf.Append(finales);
            graf.Append("\n");
            graf.Append("node [shape = circle];\n");
            graf.Append(automatas);

            graf.Append("\n}");


            ////////////////////////MessageBox.Show(graf.ToString());
            File.WriteAllText("thom_" + name_expre + ".txt", graf.ToString());

            ////////////////////System.Diagnostics.Process.Start("thom.txt");
            //return this.graf_arbolavl(graf.toString(), "graf_automata_" + name_expre);

            //System.Diagnostics.Process.Start("dot -Tpng " + name_g + ".txt -o " + name_g + ".jpg");

            //////////////////////MessageBox.Show(root.lexema, "ultimo root.lexema ");***
            //////////////////////MessageBox.Show(root.ultimo_ref.lexema, "ultimo root.ultimo_ref.lexema ");***
            nod_inicial = root;
            nod_final   = root.ultimo_ref;
            return(CreateImage("thom_" + name_expre));
            //return true;
        }
Exemplo n.º 4
0
        public NodeAFN copiandoEstructura(NodeAFN orinal)
        {
            IniciarVisitado(orinal);
            //MessageBox.Show(orinal.lexema, "copiandoNodos(orinal)");
            copiandoNodos(orinal);

            IniciarVisitado(orinal);
            //MessageBox.Show(orinal.lexema, "copiandoEnlaces(orinal)");
            copiandoEnlaces(orinal);
            return(orinal.tempo_copy);
        }
        NodeAFN nod_final;    ///nodo final thomson
        public Thompson(NodeAFN root, String name_expre, List <Transiciones> Listado_Tran)
        {
            this.root         = root;
            index             = 0;
            lis_Nodos_thomson = new List <NodeAFN>();

            tab_transiciones = new List <TTransiciones_Cerraduras>();


            this.Listado_Tran = Listado_Tran;
            this.name_expre   = name_expre;

            //tabla_siguientes = new LinkedList<>();

            //resul_expresiones = new LinkedList<>();
        }
Exemplo n.º 6
0
 public void IniciarVisitado(NodeAFN root_ac)
 {
     if (root_ac != null)
     {
         if (root_ac.visitado == true)
         {
             root_ac.visitado = false;
         }
         if (root_ac.left != null && root_ac.left.visitado == true)
         {
             this.IniciarVisitado(root_ac.left);
         }
         if (root_ac.right != null && root_ac.right.visitado == true)
         {
             this.IniciarVisitado(root_ac.right);
         }
     }
 }
Exemplo n.º 7
0
        public void copiandoNodos(NodeAFN root_ac)
        {
            if (root_ac != null)
            {
                //MessageBox.Show("root_ac.lexema = " + root_ac.lexema);
                //MessageBox.Show("root_ac.Tran_left = " + root_ac.Tran_left);
                //MessageBox.Show("root_ac.Tran_right = " + root_ac.Tran_right);
                ///*copiando valores*/
                NodeAFN new_tem = new NodeAFN("N", 0, "E", Tipo.TipoN.EPSILON);
                new_tem.id = root_ac.id;
                ////////////MessageBox.Show(root_ac.lexema, "creando nodo--lexema");
                //new_tem.lexema = root_ac.lexema;
                new_tem.lexema = "N";
                //new_tem.left = root_ac.left;
                //new_tem.right = root_ac.right;

                //new_tem.Tran_left = root_ac.Tran_left + "_c"; ;
                //new_tem.Tran_right = root_ac.Tran_right + "_c"; ;
                new_tem.Tran_left  = root_ac.Tran_left;
                new_tem.Tran_right = root_ac.Tran_right;

                new_tem.Tran_left_Tipo  = root_ac.Tran_left_Tipo;
                new_tem.Tran_right_Tipo = root_ac.Tran_right_Tipo;

                ////////new_tem.ultimo_ref = root_ac.ultimo_ref;
                new_tem.tipo   = root_ac.tipo;
                new_tem.tipo_n = root_ac.tipo_n;

                ///guardo la refencia el nodo nuevo
                root_ac.tempo_copy = new_tem;

                root_ac.visitado = true;

                if (root_ac.left != null && root_ac.left.visitado == false)
                {
                    this.copiandoNodos(root_ac.left);
                }
                if (root_ac.right != null && root_ac.right.visitado == false)
                {
                    this.copiandoNodos(root_ac.right);
                }
            }
        }
        //public void MueveX_a(NodeAFN nod_stado, List<String> mueve_ira)
        //{
        //    for (int i = 0; i < Listado_Tran.Count; ++i)
        //    {
        //        //Listado_Tran.ElementAt(i).transicion;
        //        //Listado_Tran.ElementAt(i).tipo;
        //        if (Listado_Tran.ElementAt(i).transicion.Equals(nod_stado.Tran_left) )
        //        {
        //           if (nod_stado.left != null) {
        //                mueve_ira.Add(nod_stado.left.lexema);
        //            }
        //        }
        //        if (Listado_Tran.ElementAt(i).transicion.Equals(nod_stado.Tran_right))
        //        {
        //            if (nod_stado.right != null)
        //            {
        //                mueve_ira.Add(nod_stado.right.lexema);
        //            }

        //        }
        //    }
        //}
        /*creando las cerraduras*/
        public void Cerradura_X(NodeAFN root_ac, List <String> lis_cerraduras)
        {
            //if (root_ac != null)
            if (root_ac != null)
            {
                ////////////////////////MessageBox.Show("Cerradura* " + root_ac.lexema, root_ac.tipo_n.ToString());**
                ////////////////lis_cerraduras.Add(root_ac.lexema);

                if (lis_cerraduras.Contains(root_ac.lexema) == false)
                {
                    lis_cerraduras.Add(root_ac.lexema);
                }
                if (root_ac.left != null)
                {
                    //if (root_ac.Tran_left_Tipo == Tipo.TipoN.EPSILON)
                    //{
                    //    //cerra_x.Add(root_ac.left.lexema);
                    //    MessageBox.Show("left ->* " + root_ac.left.lexema, root_ac.Tran_left_Tipo.ToString());
                    //}
                }
                if (root_ac.right != null)
                {
                    //if (root_ac.Tran_right_Tipo == Tipo.TipoN.EPSILON)
                    //{
                    //    //cerra_x.Add(root_ac.right.lexema);
                    //    MessageBox.Show("right ->* " + root_ac.right.lexema, root_ac.Tran_right_Tipo.ToString());
                    //}
                }

                root_ac.visitado = true;

                if (root_ac.left != null && root_ac.left.visitado == false && root_ac.Tran_left_Tipo == Tipo.TipoN.EPSILON)
                {
                    this.Cerradura_X(root_ac.left, lis_cerraduras);
                }

                if (root_ac.right != null && root_ac.right.visitado == false && root_ac.Tran_right_Tipo == Tipo.TipoN.EPSILON)
                {
                    this.Cerradura_X(root_ac.right, lis_cerraduras);
                }
            }
        }
Exemplo n.º 9
0
        //////////////////////
        public void copiandoEnlaces(NodeAFN root_ac)
        {
            if (root_ac != null)
            {
                ///*copiando enlaces*/

                NodeAFN new_tem;
                new_tem = root_ac.tempo_copy;
                //////////////////MessageBox.Show(root_ac.lexema, "enlzanado nodito nodo ++ lexema root_ac.lexema");

                //MessageBox.Show(new_tem.lexema, "enlzanado nodito nodo ++ lexema new_tem.lexema");
                //new_tem.left = root_ac.left.tempo_copy;
                //new_tem.right = root_ac.right.tempo_copy;
                //new_tem.ultimo_ref = root_ac.ultimo_ref.tempo_copy;

                if (root_ac.left != null)
                {
                    new_tem.left = root_ac.left.tempo_copy;
                }
                if (root_ac.right != null)
                {
                    new_tem.right = root_ac.right.tempo_copy;
                }
                if (root_ac.ultimo_ref != null)
                {
                    new_tem.ultimo_ref = root_ac.ultimo_ref.tempo_copy;
                }

                root_ac.visitado = true;

                if (root_ac.left != null && root_ac.left.visitado == false)
                {
                    //new_tem.left = root_ac.left.tempo_copy;
                    this.copiandoEnlaces(root_ac.left);
                }
                if (root_ac.right != null && root_ac.right.visitado == false)
                {
                    //new_tem.right = root_ac.right.tempo_copy;
                    this.copiandoEnlaces(root_ac.right);
                }
            }
        }
        ///////////////////////////////////////
        public void IniciarVisitado(NodeAFN root_ac)
        {
            if (root_ac != null)
            {
                ////////////MessageBox.Show("root_ac.lexema: " + root_ac.lexema, "root_ac.visitado: " + root_ac.visitado);
                if (root_ac.visitado == true)
                {
                    root_ac.visitado = false;
                }

                if (root_ac.left != null && root_ac.left.visitado == true)
                {
                    this.IniciarVisitado(root_ac.left);
                }
                if (root_ac.right != null && root_ac.right.visitado == true)
                {
                    this.IniciarVisitado(root_ac.right);
                }
            }
        }
Exemplo n.º 11
0
        public void SetIndex_soloprueba(NodeAFN root_ac)
        {
            if (root_ac != null)
            {
                if (root_ac.lexema.Equals("N"))
                {
                    index++;
                    MessageBox.Show(index.ToString(), "set_lex");

                    root_ac.lexema = index.ToString();
                }


                if (root_ac.left != null && root_ac.left.lexema.Equals("N"))
                {
                    this.SetIndex_soloprueba(root_ac.left);
                }
                if (root_ac.right != null && root_ac.right.lexema.Equals("N"))
                {
                    this.SetIndex_soloprueba(root_ac.right);
                }
            }
        }
        public void SetIndex(NodeAFN root_ac)
        {
            if (root_ac != null)
            {
                if (root_ac.lexema.Equals("N"))
                {
                    index++;
                    //////////////////MessageBox.Show("index: "+root_ac.lexema, index.ToString());

                    root_ac.lexema = index.ToString();
                    lis_Nodos_thomson.Add(root_ac);
                }


                if (root_ac.left != null && root_ac.left.lexema.Equals("N"))
                {
                    this.SetIndex(root_ac.left);
                }
                if (root_ac.right != null && root_ac.right.lexema.Equals("N"))
                {
                    this.SetIndex(root_ac.right);
                }
            }
        }
Exemplo n.º 13
0
        private void button2_Click(object sender, EventArgs e)
        {
            NodeAFN N1 = new NodeAFN("N", 1, "E", Tipo.TipoN.EPSILON);
            NodeAFN N2 = new NodeAFN("N", 2, "E", Tipo.TipoN.EPSILON);

            NodeAFN f1 = new NodeAFN("N", 2, "E", Tipo.TipoN.EPSILON);
            NodeAFN f2 = new NodeAFN("N", 2, "E", Tipo.TipoN.EPSILON);

            f1.Tran_left = "f1";
            f2.Tran_left = "f2";


            NodeAFN N3 = new NodeAFN("N", 2, "E", Tipo.TipoN.EPSILON);
            NodeAFN N4 = new NodeAFN("N", 2, "E", Tipo.TipoN.EPSILON);

            N1.Tran_left  = "1";
            N1.ultimo_ref = N1;

            N2.Tran_left  = "2";
            N2.ultimo_ref = N2;
            ///////
            N3.Tran_left  = "a";
            N3.ultimo_ref = N3;

            N4.Tran_left  = "b";
            N4.ultimo_ref = N4;

            //N1.left = N2;
            N1.ultimo_ref.left = N2;
            //N2.left = f1;
            N2.ultimo_ref.left = f1;

            N1.ultimo_ref = f1;

            ///////f1.left = N3;

            //N3.left = N4;
            N3.ultimo_ref.left = N4;
            //N4.left = f2;
            N4.ultimo_ref.left = f2;
            N3.ultimo_ref      = f2;

            ///concatenando
            //N2.left = N3;

            MessageBox.Show(f1.Tran_left, "1 f1.Tran_left");
            MessageBox.Show(N2.left.Tran_left, "1 N2.left.Tran_left");
            MessageBox.Show(N1.ultimo_ref.Tran_left, "1 N1.ultimo_ref.Tran_left");
            //f1 = N3;
            N1.ultimo_ref.lexema     = N3.lexema;
            N1.ultimo_ref.left       = N3.left;
            N1.ultimo_ref.Tran_left  = N3.Tran_left;
            N1.ultimo_ref.ultimo_ref = N3.ultimo_ref;

            MessageBox.Show(f1.Tran_left, "2 f1.Tran_left");
            MessageBox.Show(N2.left.Tran_left, "2 N2.left.Tran_left");
            MessageBox.Show(N1.ultimo_ref.Tran_left, "1 N1.ultimo_ref.Tran_left");

            //MessageBox.Show(f1.Tran_left, "1 f1.Tran_left");
            //MessageBox.Show(N2.left.Tran_left, "1 N2.left.Tran_left");
            ////f1 = N3;
            //f1.lexema = N3.lexema;
            //f1.left = N3.left;
            //f1.Tran_left = N3.Tran_left;

            //MessageBox.Show(f1.Tran_left, "2 f1.Tran_left");
            //MessageBox.Show(N2.left.Tran_left, "2 N2.left.Tran_left");


            Thompson tree = new Thompson(N1, "prub", null);

            tree.SetIndex();
            tree.IniciarVisitado();
            tree.graficando_Thomson();
        }
Exemplo n.º 14
0
        public NodeAFN leyendo_expresiones()
        {
            //String eleDer, eleIzq;
            NodeAFN eleDer, eleIzq;

            /*recorriendo listado de expresiores regulares*/
            //for (String expre : pref_expresiones) {

            //for (int i = 0; i < pref_expresiones.size(); ++i){
            for (int i = pref_expresiones.Count - 1; i >= 0; i--)
            {
                ////////////            JOptionPane.showMessageDialog(null,pref_expresiones.get(i).er);

                /*verificando si es operador*/

                //if (IsOperador(expre)) {

                //if (IsOperador(pref_expresiones.get(i))) {
                if (pref_expresiones.ElementAt(i).tipo.Equals("O"))
                {
                    int tipo = TipoOperador(pref_expresiones.ElementAt(i).er);

                    if (tipo == 2)
                    {
                        //eleDer = pila.Pop();
                        eleIzq = pila.Pop();
                        if (!pila.Any())
                        {
                            MessageBox.Show("Faltan Elementos para armar arbol");
                            i = pref_expresiones.Count;
                        }

                        eleDer = pila.Pop();
                        //eleIzq = pila.Pop();
                        NodeAFN resultado = operar(eleIzq, pref_expresiones.ElementAt(i).er, eleDer, i);
                        //odeAFN resultado = operar(eleIzq, pref_expresiones.get(i).er, eleDer, i);
                        pila.Push(resultado);
                    }
                    else if (tipo == 1)
                    {
                        //                    //eleDer = pila.pop();
                        //                    eleIzq = pila.pop();
                        if (!pila.Any())
                        {
                            MessageBox.Show("Faltan Elementos para armar arbol");
                            i = pref_expresiones.Count;
                        }
                        //eleIzq = pila.pop();
                        eleDer = pila.Pop();
                        //NodeArbol resultado = operar_1(pref_expresiones.get(i).er, eleDer, i);
                        NodeAFN resultado = operar(eleDer, pref_expresiones.ElementAt(i).er, null, i);
                        pila.Push(resultado);
                    }
                }
                else
                {
                    //pila.push(pref_expresiones.get(i));
                    //this.root = new NodeAVL(nombre, contenido, user, fecha_creacion);

                    //NodeArbol n_nodo = new NodeArbol(pref_expresiones.get(i).er, i, "F", 0, 0, 0);

                    //NodeArbol n_nodo = new NodeArbol(pref_expresiones.get(i).er, i, "A", 0, "-", "-");

                    //NodeAFN n_nodo = new NodeAFN(pref_expresiones.ElementAt(i).er, i,  pref_expresiones.ElementAt(i).tipo, Tipo.TipoN.NORMAL);
                    NodeAFN n_nodo = new NodeAFN("N", i, pref_expresiones.ElementAt(i).tipo, Tipo.TipoN.NORMAL);
                    n_nodo.Tran_left      = pref_expresiones.ElementAt(i).er;
                    n_nodo.Tran_left_Tipo = Tipo.TipoN.NORMAL;
                    n_nodo.ultimo_ref     = n_nodo;
                    pila.Push(n_nodo);
                    //MessageBox.Show(pref_expresiones.ElementAt(i).er, pref_expresiones.ElementAt(i).tipo);
                    //MessageBox.Show(Existe_transicion(pref_expresiones.ElementAt(i).er, pref_expresiones.ElementAt(i).tipo).ToString(), "Existe_transicion");

                    if (Existe_transicion(pref_expresiones.ElementAt(i).er, pref_expresiones.ElementAt(i).tipo) == false)
                    {
                        Transiciones tran_new = new Transiciones(pref_expresiones.ElementAt(i).er, pref_expresiones.ElementAt(i).tipo);
                        Listado_Tran.Add(tran_new);
                    }

                    listado_Nodos.Add(n_nodo); ///agregar ref de nodos

                    //////JOptionPane.showMessageDialog(null,"("+i+") "+pref_expresiones.get(i));
                }
            }

            //nodo final
            return(pila.Pop());
        }
Exemplo n.º 15
0
        public NodeAFN operar(NodeAFN eleIzq, String oper, NodeAFN eleDer, int i)
        {
            NodeAFN OR        = null;
            NodeAFN Cerradura = null;

            NodeAFN AND      = null;
            NodeAFN MAS      = null;
            NodeAFN PREGUNTA = null;

            if (oper.Equals("|"))
            {
                //NodeAFN N1 = new NodeAFN("N1", i, "E", Tipo.TipoN.EPSILON);
                //NodeAFN N4 = new NodeAFN("N4", i, "E", Tipo.TipoN.EPSILON);
                //NodeAFN N5 = new NodeAFN("N5", i, "E", Tipo.TipoN.EPSILON);
                //NodeAFN N6 = new NodeAFN("N6", i, "E", Tipo.TipoN.EPSILON);

                NodeAFN N1 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
                NodeAFN N4 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
                NodeAFN N5 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
                NodeAFN N6 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);


                /*armando OR*/
                //MessageBox.Show(eleIzq.Tran_left, "eleIzq.Tran_left");
                N1.left           = eleIzq;
                N1.Tran_left      = "e";
                N1.Tran_left_Tipo = Tipo.TipoN.EPSILON;
                //N1.Tran_left = "ε";

                //MessageBox.Show(eleDer.Tran_left, "eleDer.Tran_left");
                N1.right           = eleDer;
                N1.Tran_right      = "e";
                N1.Tran_right_Tipo = Tipo.TipoN.EPSILON;

                ////eleIzq.left = N4;
                ////eleDer.left = N5;
                //MessageBox.Show("---------");
                //MessageBox.Show(eleIzq.ultimo_ref.Tran_left, "eleIzq.ultimo_ref.Tran_left");
                //MessageBox.Show(eleIzq.ultimo_ref.tipo_n.ToString(), "eleIzq.ultimo_ref.tipo_n");
                if (eleIzq.ultimo_ref.tipo_n == Tipo.TipoN.NORMAL)
                {
                    eleIzq.ultimo_ref.left = N4;
                    N4.left           = N6;
                    N4.Tran_left      = "e";
                    N4.Tran_left_Tipo = Tipo.TipoN.EPSILON;
                }
                else if (eleIzq.ultimo_ref.tipo_n == Tipo.TipoN.EPSILON)
                {
                    eleIzq.ultimo_ref.left           = N6;
                    eleIzq.ultimo_ref.Tran_left      = "e";
                    eleIzq.ultimo_ref.Tran_left_Tipo = Tipo.TipoN.EPSILON;
                }

                //MessageBox.Show(eleDer.ultimo_ref.Tran_left, "uu eleDer.ultimo_ref.Tran_left");
                //MessageBox.Show(eleDer.ultimo_ref.tipo_n.ToString(), "uu eleDer.ultimo_ref.tipo_n");

                if (eleDer.ultimo_ref.tipo_n == Tipo.TipoN.NORMAL)
                {
                    eleDer.ultimo_ref.left = N5;
                    N5.left           = N6;
                    N5.Tran_left      = "e";
                    N5.Tran_left_Tipo = Tipo.TipoN.EPSILON;
                }
                else if (eleDer.ultimo_ref.tipo_n == Tipo.TipoN.EPSILON)
                {
                    eleDer.ultimo_ref.left           = N6;
                    eleDer.ultimo_ref.Tran_left      = "e";
                    eleDer.ultimo_ref.Tran_left_Tipo = Tipo.TipoN.EPSILON;
                }


                N1.ultimo_ref = N6;
                OR            = N1;

                return(OR);
            }
            if (oper.Equals("*"))
            {
                NodeAFN N1 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
                NodeAFN N2 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
                NodeAFN N3 = new NodeAFN("N", 99, "E", Tipo.TipoN.EPSILON);

                //eleIzq
                N1.left            = eleIzq;
                N1.Tran_left       = "e";
                N1.Tran_left_Tipo  = Tipo.TipoN.EPSILON;
                N1.right           = N3;
                N1.Tran_right      = "e";
                N1.Tran_right_Tipo = Tipo.TipoN.EPSILON;

                if (eleIzq.ultimo_ref.tipo_n == Tipo.TipoN.NORMAL)
                {
                    //eleIzq.left = N2;
                    eleIzq.ultimo_ref.left = N2;
                    N2.left           = N3;
                    N2.Tran_left      = "e";
                    N2.Tran_left_Tipo = Tipo.TipoN.EPSILON;

                    N2.right           = eleIzq;
                    N2.Tran_right      = "e";
                    N2.Tran_right_Tipo = Tipo.TipoN.EPSILON;
                }
                else if (eleIzq.ultimo_ref.tipo_n == Tipo.TipoN.EPSILON)
                {
                    eleIzq.ultimo_ref.left = N3;
                    //N2.left = N3;
                    eleIzq.ultimo_ref.Tran_left      = "e";
                    eleIzq.ultimo_ref.Tran_left_Tipo = Tipo.TipoN.EPSILON;

                    eleIzq.ultimo_ref.right           = eleIzq;
                    eleIzq.ultimo_ref.Tran_right      = "e";
                    eleIzq.ultimo_ref.Tran_right_Tipo = Tipo.TipoN.EPSILON;
                }

                N1.ultimo_ref = N3;
                Cerradura     = N1;

                return(Cerradura);
            }
            //MessageBox.Show(OR.leema, "Or-inicio");
            //MessageBox.Show(OR.ultimo_ref.lexema, "Or-ultimo_ref.lexema");

            if (oper.Equals("."))
            {
                NodeAFN N3 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
                //eleIzq.left = eleDer;
                //eleDer.left = N3;

                NodeAFN tempo_der;

                if (eleIzq.ultimo_ref.tipo_n == Tipo.TipoN.NORMAL)
                {
                    eleIzq.ultimo_ref.left = eleDer;
                    tempo_der = eleDer;
                }
                else
                {
                    //////////////////////MessageBox.Show(eleIzq.ultimo_ref.Tran_left, "eleIzq.ultimo_ref.Tran_left  sin asignacion");
                    //////////////////////MessageBox.Show(eleDer.Tran_left, "eleDer.Tran_left  ");


                    //eleIzq.ultimo_ref = eleDer;
                    eleIzq.ultimo_ref.id         = eleDer.id;
                    eleIzq.ultimo_ref.lexema     = eleDer.lexema;
                    eleIzq.ultimo_ref.left       = eleDer.left;
                    eleIzq.ultimo_ref.right      = eleDer.right;
                    eleIzq.ultimo_ref.Tran_left  = eleDer.Tran_left;
                    eleIzq.ultimo_ref.Tran_right = eleDer.Tran_right;
                    /////////
                    eleIzq.ultimo_ref.Tran_left_Tipo  = eleDer.Tran_left_Tipo;
                    eleIzq.ultimo_ref.Tran_right_Tipo = eleDer.Tran_right_Tipo;
                    ////////
                    eleIzq.ultimo_ref.ultimo_ref = eleDer.ultimo_ref;
                    //eleIzq.ultimo_ref.visitado = false;
                    eleIzq.ultimo_ref.visitado = eleDer.visitado;
                    eleIzq.ultimo_ref.tipo     = eleDer.tipo;
                    eleIzq.ultimo_ref.tipo_n   = eleDer.tipo_n;

                    //tempo_der = eleIzq;
                    tempo_der = eleIzq.ultimo_ref;



                    //////////////////MessageBox.Show(eleIzq.ultimo_ref.Tran_left, "eleIzq.ultimo_ref.Tran_left  yayayay");
                    //////////////////MessageBox.Show(eleDer.Tran_left, "eleDer.Tran_left  yayayay 2 ");
                }

                ////////////////////////MessageBox.Show(tempo_der.ultimo_ref.tipo_n.ToString(), "***No2 tran -" + tempo_der.ultimo_ref.Tran_left);
                //////////////////////MessageBox.Show(tempo_der.ultimo_ref.tipo_n.ToString(), "***tempo_der.ultimo_ref.tipo_n tran -" + tempo_der.ultimo_ref.Tran_left);
                //////////////////////MessageBox.Show(eleDer.ultimo_ref.tipo_n.ToString(), "**eleDer.ultimo_ref.tipo_n tran -" + eleDer.ultimo_ref.Tran_left);

                if (tempo_der.ultimo_ref.tipo_n == Tipo.TipoN.NORMAL)
                {
                    //eleDer.ultimo_ref.left = N3;

                    tempo_der.ultimo_ref.left = N3; ////este funciono antes
                    tempo_der.left            = N3;
                    //eleIzq.ultimo_ref.left = N3;
                }
                else
                {
                    //N3 = tempo_der.ultimo_ref;
                    N3 = eleDer.ultimo_ref;
                }



                //MessageBox.Show(eleDer.ultimo_ref.tipo_n.ToString(), "No2 tran -" + eleDer.ultimo_ref.Tran_left);
                //if (eleDer.ultimo_ref.tipo_n == Tipo.TipoN.NORMAL)
                //{
                //    eleDer.ultimo_ref.left = N3;
                //    //eleIzq.ultimo_ref.left = N3;
                //}
                //else
                //{
                //    N3 = eleDer.ultimo_ref;
                //}

                AND            = eleIzq;
                AND.ultimo_ref = N3;
                return(AND);
            }

            if (oper.Equals("+"))
            {
                //NodeAFN a1 = new NodeAFN("N", i, "E", Tipo.TipoN.NORMAL);
                ////NodeAFN a2 = new NodeAFN("N", i, "E", Tipo.TipoN.NORMAL);
                //a1.Tran_left = "a1";
                //a1.ultimo_ref = a1;

                //a2.Tran_left = "a2";
                //a2.ultimo_ref = a2;

                NodeAFN a2 = copiandoEstructura(eleIzq);


                //MessageBox.Show(eleIzq.tipo_n.ToString(), "primero eleIzq.tipo_n ");
                //MessageBox.Show(eleIzq.ultimo_ref.tipo_n.ToString(), "ultimo eleIzq.ultimo_ref.tipo_n ");

                //MessageBox.Show(a2.tipo_n.ToString(), "primero a2.tipo_n ");
                //MessageBox.Show(a2.ultimo_ref.tipo_n.ToString(), "ultimo a2.ultimo_ref.tipo_n ");

                //NodeAFN conca = operar(eleIzq, ".", a2, i);

                IniciarVisitado(a2);
                IniciarVisitado(eleIzq);
                NodeAFN kleen = operar(eleIzq, "*", null, i);
                NodeAFN conca = operar(a2, ".", kleen, i);
                MAS = conca;

                //SetIndex_soloprueba(MAS);
                return(MAS);
            }

            ///*******************inicio solo pureba****************************************************/
            //if (oper.Equals("+"))
            //{
            //    NodeAFN N1 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
            //    NodeAFN N2 = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
            //    NodeAFN N3 = new NodeAFN("N", 99, "E", Tipo.TipoN.EPSILON);

            //    //eleIzq
            //    N1.left = eleIzq;
            //    N1.Tran_left = "e";
            //    N1.Tran_left_Tipo = Tipo.TipoN.EPSILON;
            //    //////N1.right = N3;
            //    //////N1.Tran_right = "e";
            //    //////N1.Tran_right_Tipo = Tipo.TipoN.EPSILON;

            //    if (eleIzq.ultimo_ref.tipo_n == Tipo.TipoN.NORMAL)
            //    {
            //        //eleIzq.left = N2;
            //        eleIzq.ultimo_ref.left = N2;
            //        N2.left = N3;
            //        N2.Tran_left = "e";
            //        N2.Tran_left_Tipo = Tipo.TipoN.EPSILON;

            //        N2.right = eleIzq;
            //        N2.Tran_right = "e";
            //        N2.Tran_right_Tipo = Tipo.TipoN.EPSILON;

            //    }
            //    else if (eleIzq.ultimo_ref.tipo_n == Tipo.TipoN.EPSILON)
            //    {
            //        eleIzq.ultimo_ref.left = N3;
            //        //N2.left = N3;
            //        eleIzq.ultimo_ref.Tran_left = "e";
            //        eleIzq.ultimo_ref.Tran_left_Tipo = Tipo.TipoN.EPSILON;

            //        eleIzq.ultimo_ref.right = eleIzq;
            //        eleIzq.ultimo_ref.Tran_right = "e";
            //        eleIzq.ultimo_ref.Tran_right_Tipo = Tipo.TipoN.EPSILON;
            //    }

            //    N1.ultimo_ref = N3;
            //    Cerradura = N1;

            //    return Cerradura;
            //}
            ///*******************fin solo pureba****************************************************/

            if (oper.Equals("?"))
            {
                NodeAFN epsilon = new NodeAFN("N", i, "E", Tipo.TipoN.EPSILON);
                //epsilon.Tran_left = "e";
                //epsilon.Tran_left = "ε";
                epsilon.ultimo_ref = epsilon;

                //NodeAFN or_ita = operar(epsilon, ".", eleIzq, i);
                NodeAFN or_ita = operar(eleIzq, "|", epsilon, i);
                PREGUNTA = or_ita;
                return(PREGUNTA);
            }
            return(null);
        }
        public void VerArbol(NodeAFN root_ac, StringBuilder graf)
        {
            if (root_ac != null)
            {
                //////////////////MessageBox.Show(root_ac.lexema, "lexema**************");
                NodeAFN tempo = root_ac;
                if (tempo.left != null)
                {
                    //MessageBox.Show(root_ac.lexema, root_ac.Tran_left + " left");
                    graf.Append(root_ac.lexema + " -> " + tempo.left.lexema);
                    if (root_ac.Tran_left_Tipo == Tipo.TipoN.NORMAL)
                    {
                        graf.Append("[ label = \"" + root_ac.Tran_left + "\" ];");
                    }
                    else if (root_ac.Tran_left_Tipo == Tipo.TipoN.EPSILON)
                    {
                        graf.Append("[ label = \"" + "ε" + "\" ];");
                    }

                    graf.Append("\n");
                }
                if (tempo.right != null)
                {
                    //MessageBox.Show(root_ac.lexema, root_ac.Tran_right + " right");
                    graf.Append(root_ac.lexema + " -> " + tempo.right.lexema);
                    if (root_ac.Tran_right_Tipo == Tipo.TipoN.NORMAL)
                    {
                        graf.Append("[ label = \"" + root_ac.Tran_right + "\" ];");
                    }
                    else if (root_ac.Tran_right_Tipo == Tipo.TipoN.EPSILON)
                    {
                        graf.Append("[ label = \"" + "ε" + "\" ];");
                    }
                    graf.Append("\n");
                }

                //if (tempo.right != null)
                //{
                //    //MessageBox.Show(root_ac.lexema, root_ac.Tran_right + " right");
                //    graf.Append(root_ac.lexema + " -> " + tempo.right.lexema);
                //    graf.Append("[ label = \"" + root_ac.Tran_right + "\" ];");
                //    graf.Append("\n");
                //}
                //if (tempo.left != null)
                //{
                //    //MessageBox.Show(root_ac.lexema, root_ac.Tran_left + " left");
                //    graf.Append(root_ac.lexema + " -> " + tempo.left.lexema);
                //    graf.Append("[ label = \"" + root_ac.Tran_left + "\" ];");
                //    graf.Append("\n");
                //}
                root_ac.visitado = true;

                if (root_ac.left != null && root_ac.left.visitado == false)
                {
                    this.VerArbol(root_ac.left, graf);
                }

                if (root_ac.right != null && root_ac.right.visitado == false)
                {
                    this.VerArbol(root_ac.right, graf);
                }
            }
        }
        public void MetedoCerradura()
        {
            IEnumerable <Transiciones> Listado_Tran_sort = Listado_Tran.OrderBy(trn => trn.transicion);

            Listado_Tran = Listado_Tran_sort.ToList();

            ///cerradura inicial
            List <String> lis_cerraduras_inicial = new List <String>(); ///A

            Cerradura_X(nod_inicial, lis_cerraduras_inicial);



            String cerx = "";

            cerx = "";
            for (int i = 0; i < Listado_Tran.Count; ++i)
            {
                cerx = cerx + Listado_Tran[i].transicion + ", ";
            }
            //////////////////////MessageBox.Show(cerx, "transiciones");**

            IEnumerable <String> lis_cerraduras_sort = lis_cerraduras_inicial.OrderBy(idnod => idnod);

            lis_cerraduras_inicial = lis_cerraduras_sort.ToList();

            List <tran_a_estados> ir_a_estados = new List <tran_a_estados>();
            char name_cerradura = 'A';

            String tip_nodin = EsFinal(lis_cerraduras_inicial);

            if (tip_nodin.Equals("N"))
            {
                tip_nodin = "I";
            }
            TTransiciones_Cerraduras transi = new TTransiciones_Cerraduras(name_cerradura.ToString(), lis_cerraduras_inicial, tip_nodin, "N", ir_a_estados);

            //TTransiciones_Cerraduras transi = new TTransiciones_Cerraduras(name_cerradura.ToString(), lis_cerraduras_inicial, "I", "N", ir_a_estados);
            tab_transiciones.Add(transi);

            /////////////////////////////////
            for (int tb = 0; tb < tab_transiciones.Count; ++tb)
            {
                if (tab_transiciones.ElementAt(tb).tipo_estado.Equals("N"))
                {
                    ////////////////////reset_Visitador_cerradura();
                    List <String> lis_cerraduras = tab_transiciones.ElementAt(tb).cerradura;
                    /***********************************************************/
                    cerx = "";
                    for (int i = 0; i < lis_cerraduras.Count; ++i)
                    {
                        //NodeAFN nod_stado = return_nodoMueve(lis_cerraduras.ElementAt(i));
                        //List<String> mueve_ira = new List<String>();
                        //MueveX_a(nod_stado, mueve_ira);
                        cerx = cerx + lis_cerraduras[i] + ", ";
                    }
                    //////////////////MessageBox.Show(cerx, "Leyendo cerr NAME: " + tab_transiciones.ElementAt(tb).name_estado);**

                    /*mueve a/ ir a
                     * verifica en la cerradura si hay en el listado de transiciones*/
                    for (int i = 0; i < Listado_Tran.Count; ++i)
                    {
                        //Listado_Tran.ElementAt(i).transicion;
                        //Listado_Tran.ElementAt(i).tipo;

                        //reset_Visitador_cerradura(); ///reiniciar visitados
                        //////////////////MessageBox.Show(Listado_Tran.ElementAt(i).transicion, "00 terminar = " + Listado_Tran.ElementAt(i).tipo);**
                        List <String> mueve_ira = new List <String>();
                        MueveX_a(lis_cerraduras, Listado_Tran.ElementAt(i), mueve_ira);

                        /*mueve_ira con el mueve resultando
                         * se busca las cerraduras para cada nodo
                         * encontrado en el lexema */

                        List <String> lis_cerraduras_ac = new List <String>(); ///B, C, D
                        for (int m = 0; m < mueve_ira.Count; m++)
                        {
                            reset_Visitador_cerradura(); ///reiniciar visitados
                            //////////////////////MessageBox.Show(mueve_ira.ElementAt(m), "haciendo Cerradura de ---- mueve_ira-");**
                            NodeAFN nod_cerra = return_nodoMueve(mueve_ira.ElementAt(m));

                            Cerradura_X(nod_cerra, lis_cerraduras_ac);
                        }
                        /****fin creando cerraduras****/

                        /********mueve_ira*********/
                        /////////////////   aqui deberia de guardar moeve a mi
                        ////tabla de estados
                        //IEnumerable<String> mueve_sort = mueve_ira.OrderBy(idnod => idnod);
                        //mueve_ira = mueve_sort.ToList();
                        IEnumerable <String> lis_cerraduras_ac_sort = lis_cerraduras_ac.OrderBy(idnod => idnod);
                        lis_cerraduras_ac = lis_cerraduras_ac_sort.ToList();

                        ///
                        cerx = "";
                        for (int i2 = 0; i2 < lis_cerraduras_ac.Count; ++i2)
                        {
                            cerx = cerx + lis_cerraduras_ac[i2] + ", ";
                        }
                        //////MessageBox.Show(cerx, "lis_cerraduras_ac.Count: " + lis_cerraduras_ac.Count);
                        ///
                        /*verificando si tiene contenido y que no este repedido*/
                        if (lis_cerraduras_ac.Count > 0)
                        {
                            ////////////////////////MessageBox.Show(cerx, "lis_cerraduras_ac.Count: " + lis_cerraduras_ac.Count);**
                            ////////////////////////MessageBox.Show(ExisteCerradura(lis_cerraduras_ac).ToString(), "ExisteCerradura(lis_cerraduras_ac)");**
                            if (ExisteCerradura(lis_cerraduras_ac) == false)
                            {
                                char new_name_cerradura = tab_transiciones.Last().name_estado[0];
                                new_name_cerradura++;
                                //////////////////////////MessageBox.Show(new_name_cerradura.ToString(), "new estado");**
                                ////lis_cerraduras_ac son las tranciciones

                                //TTransiciones_Cerraduras new_transi = new TTransiciones_Cerraduras(new_name_cerradura.ToString(), mueve_ira, "N", "N" /*, ir_a_estados*/);
                                //tab_transiciones.Add(new_transi);
                                List <tran_a_estados> ir_a_estados_tem = new List <tran_a_estados>();

                                String tip_nod = EsFinal(lis_cerraduras_ac);
                                TTransiciones_Cerraduras new_transi = new TTransiciones_Cerraduras(new_name_cerradura.ToString(), lis_cerraduras_ac, tip_nod, "N", ir_a_estados_tem);
                                tab_transiciones.Add(new_transi);

                                //////MessageBox.Show("1 agregando terminar " + Listado_Tran.ElementAt(i).transicion, Listado_Tran.ElementAt(i).tipo);
                                tab_transiciones.ElementAt(tb).ir_a.Add(new tran_a_estados(Listado_Tran.ElementAt(i).transicion, new_name_cerradura.ToString(), Listado_Tran.ElementAt(i).tipo));
                            }
                            else    //// si si existe, solo lo ingreso a ir a estado
                            {
                                ////MessageBox.Show("2 agregando terminar " + Listado_Tran.ElementAt(i).transicion,  Listado_Tran.ElementAt(i).tipo);
                                String name_cerr = Obtengo_Ir_A_Estado(lis_cerraduras_ac);
                                tab_transiciones.ElementAt(tb).ir_a.Add(new tran_a_estados(Listado_Tran.ElementAt(i).transicion, name_cerr, Listado_Tran.ElementAt(i).tipo));
                            }
                        }
                    }
                    tab_transiciones.ElementAt(tb).tipo_estado = "S";
                    /***********************************************************/
                }
            }

            /*mostrando datos en el datagrid view*/
        }
 public void Set_Start_End_nodos()
 {
     nod_inicial = root;
     nod_final   = root.ultimo_ref;
 }
Exemplo n.º 19
0
 public Cerradura_Mueve(String id, NodeAFN node)
 {
     this.id   = id;
     this.node = node;
 }