private void btnAnalizar_Click(object sender, EventArgs e)
        {
            //throw new System.NotImplementedException();
            //MessageBox.Show("Analizando...");
            TextBox tmptb;

            tmptb = (TextBox)tabControl.SelectedTab.Controls["tab"];
            //AnalisisLexico x = new AnalisisLexico(tmptb.Text);
            Analisis x = new Analisis(tmptb.Text);

            // x.imprimir();
            // x.imprimirError();
            //x.htmlT();
            x.htmlT();
            x.htmlE();
            //AnalisisER er = new AnalisisER();
            //er.analisis(x.getTablaTokens().getTablaT().getPrimero());

            Thompson t = new Thompson();

            t.Mas("a");

            //AnalisisER er = new AnalisisER();
            //er.analisisTokens(x.getTablaTokens());

            /*Thompson t = new Thompson();
             * t.Or("a", "b");
             * t.testOr();
             * t.graficar();*/
        }
Beispiel #2
0
        public void ShouldResolveThompsonGraph(string posfixedExp, string[] expectedOutput)
        {
            var t = new Thompson(posfixedExp);

            t.Resolve();
            Assert.Equal(expectedOutput, t.PrintGraph().ToArray());
        }
        private void DEFEXPR()
        {
            if (preAnalysis.TypeToken == Token.Type.ASSIGNMENT_SIGN)
            {
                Symbol     symbol     = GetSymbol(ListToken[index - 1].Value);
                Expression expression = GetExpression(ListToken[index - 1].Value);
                Parser(Token.Type.ASSIGNMENT_SIGN);
                symbol.Value     = STRUCEXPR();
                expression.Value = symbol.Value;

                // Thompson's construction
                Thompson  nfa       = new Thompson(symbol);
                NFAReport nfaReport = new NFAReport();

                nfa.Construction();
                nfaReport.ReportNFA(symbol.Name, nfa.Transitions);

                nfa.RemoveUnnecessaryT();
                nfaReport.ReportNFA(symbol.Name + "Optimized", nfa.Transitions);

                string imageRoute          = Directory.GetCurrentDirectory() + "\\" + symbol.Name + ".png";
                string imageRouteOptimized = Directory.GetCurrentDirectory() + "\\" + symbol.Name + "Optimized.png";
                if (File.Exists(imageRoute) && File.Exists(imageRouteOptimized))
                {
                    RoutesNFA.Add(imageRoute);
                    RoutesNFA.Add(imageRouteOptimized);
                }

                // Subset Construction
                SubsetConstruction subsetConstruction = new SubsetConstruction(nfa.Transitions, nfa.States, nfa.Terminals);
                DFAReport          dfaReport          = new DFAReport();
                SubsetReport       subsetReport       = new SubsetReport();

                subsetConstruction.Construction();
                expression.Transitions.AddRange(subsetConstruction.Transitions);

                subsetReport.ReportSubset("T_" + symbol.Name, subsetConstruction.StatesMatrix());
                imageRoute = Directory.GetCurrentDirectory() + "\\" + "T_" + symbol.Name + ".png";
                if (File.Exists(imageRoute))
                {
                    RoutesTables.Add(imageRoute);
                }

                dfaReport.ReportDFA("DFA_" + symbol.Name, subsetConstruction.Transitions);
                imageRoute = Directory.GetCurrentDirectory() + "\\" + "DFA_" + symbol.Name + ".png";
                if (File.Exists(imageRoute))
                {
                    RoutesNFA.Add(imageRoute);
                }
            }
            else
            {
                AddError(preAnalysis.Row, preAnalysis.Column, preAnalysis.toStringTypeToken, "Was expected 'ID'");
            }
        }
        public void resumirThompson()
        {
            this.resumen_subconjuntos = new List <Thompson>();

            foreach (EstadoD estado in this.estadosD)
            {
                Thompson t = new Thompson();
                t.setEstado(estado.num);
                t.setSubconjunto(estado.suconjunto);
                t.setMovimientos(estado.movimientos);
                this.resumen_subconjuntos.Add(t);
            }
        }
Beispiel #5
0
 public State GetNfa(RulePath path)
 {
     if (hex1 != null)
     {
         if (hex2 == null)
         {
             return(Thompson.Create(hex1.Value));
         }
         else
         {
             return(Thompson.Create(hex1.Value, hex2.Value));
         }
     }
     else
     {
         return(Thompson.Create(hexs.ToArray()));
     }
 }
 public void prueba()
 {
     txtConsola.Clear();
     txtConsola.AppendText("--------------------------- \n");
     txtConsola.AppendText("-------- CONJUNTOS -------- \n");
     txtConsola.AppendText("--------------------------- \n");
     for (int i = 0; i < Conjuntos.Count; i++)
     {
         Conjunto temp = (Conjunto)Conjuntos[i];
         txtConsola.AppendText("Nombre: " + temp.getNombre() + " ");
         for (int j = 0; j < temp.getConjunt().Count; j++)
         {
             txtConsola.AppendText("" + temp.getConjunt()[j] + " ");
         }
         txtConsola.AppendText(" \n");
     }
     txtConsola.AppendText(" \n");
     txtConsola.AppendText("--------------------------------- \n");
     txtConsola.AppendText("----- Expresiones Regulares -------- \n");
     txtConsola.AppendText("---------------------------------- \n");
     for (int i = 0; i < Expresiones.Count; i++)
     {
         ExpReg temporal = (ExpReg)Expresiones[i];
         txtConsola.AppendText("Nombre: " + temporal.getNombre() + " ");
         for (int j = 0; j < temporal.getThompson().Count; j++)
         {
             Thompson t = (Thompson)temporal.getThompson()[j];
             txtConsola.AppendText("De " + t.getInicio() + " a " + t.getFinal() + " se traslada con " + t.getTransicion());
         }
         txtConsola.AppendText(" \n");
         for (int j = 1; j < temporal.getTokens().Count; j++)
         {
             Token tok = (Token)temporal.getTokens()[j];
             txtConsola.AppendText(tok.getLexema());
         }
         txtConsola.AppendText(" \n");
     }
 }
Beispiel #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            Console.WriteLine("***************INTERPRETA TXT************");
            String texto = textBox1.Text;

            _OLC1_PROYECT1.AnalizadorTexto.AnalizadorTexto lex = new AnalizadorTexto.AnalizadorTexto();
            lex.escanear(texto);
            lex.imprimirLista(lex.salida);
            foreach (PilaExpresion pilas in lex.Pila)
            {
                Console.WriteLine("----------------->        " + pilas.getIdentificador_expresion());
                Thompson a        = new Thompson();
                Automata graficar = a.Analizarentrada(pilas.getPilita());

                Console.WriteLine(graficar);
                Hashtable alfabeto = graficar.getAlfabeto();
                alfabeto.Add(AnalizadorTexto.AnalizadorTexto.EPSILON, 145);
                graficar.setAlfabeto(alfabeto);
                Transformador AFD      = new Transformador();
                AFD_GRAFICA   automata = (AFD_GRAFICA)AFD.minimizar(graficar);
                textBox4.Text = automata.CreandoTabla();
                //AFD.minimizar(graficar);
                //Algoritmo simularAFD = new Algoritmo(graficar,"");
                Graphviz.FileDotEngine.Run1(pilas.getIdentificador_expresion(), crandoautomata(graficar));
                listBox1.Items.Add(pilas.getIdentificador_expresion());
            }
            PDF creando = new PDF();

            if (lex.errores.Count() > 0)
            {
                creando.crearPDFErrores(lex.errores);
            }
            else
            {
                creando.crearPDFLexico(lex.salida);
            }
        }
Beispiel #8
0
 public State GetNfa(RulePath path, GetNfaParams param)
 {
     return(param.OnMarkRule(Thompson.Create(chars), path + chars));
 }
Beispiel #9
0
 public State GetNfa(RulePath path)
 {
     return(OnMarkRule(Thompson.Create(chars), path + chars));
 }
Beispiel #10
0
        void funcionamiento(string entrada)
        {
            Lexico analisisLexico = new Lexico();

            lexemas = analisisLexico.analizar(entrada);

            /*foreach (var item in lexemas)
             * {
             *    consola += item.tipo + " ----> " + item.info+"\n";
             *
             * }
             * richTextBox1.Text = consola;
             */


            if (analisisLexico.getErrores() == 0)
            {
                Graficador grafico = new Graficador();
                grafico.eliminarArchivos();
                contadores();                   //Vuelve a colocar los contadores de imagenes en cero



                Arbol arbol = new Arbol();
                LinkedList <ExpresionRegular> expresiones;
                expresiones = arbol.analizar(lexemas);
                LinkedList <Lexema> evaluar = arbol.getEvaluar();
                conjuntos = arbol.getConjuntos();


                Thompson          thompson      = new Thompson();
                LinkedList <Nodo> listaThompson = new LinkedList <Nodo>();


                foreach (var item in expresiones)
                {
                    Nodo temp = thompson.AFN(item.nodo, item.cont);
                    generarAFN(AFN(temp));
                    listaThompson.AddLast(temp);
                }



                int cont = 0;
                foreach (var item in listaThompson)
                {
                    Subconjuntos        subconjuntos = new Subconjuntos();
                    LinkedList <Estado> estados      = subconjuntos.AFD(item.transiciones, expresiones.ElementAt(cont).terminales);
                    generarTabla(tablaTransiciones(estados));
                    generarAFD(AFD(estados));
                    Final temp = new Final(expresiones.ElementAt(cont).nombre, estados);
                    expresionesFinal.AddLast(temp);
                    cont++;
                }


                foreach (var item in evaluar)
                {
                    consola += item.evaluar + " -> " + item.info;
                    if (evaluarLexema(item.info, buscarFinal(item.evaluar)))
                    {
                        consola          += "  Correcto! \r";
                        richTextBox1.Text = consola;
                    }
                    else
                    {
                        consola          += "  Incorrecto... \r";
                        richTextBox1.Text = consola;
                    }
                }


                reiniciarMas();     //Reinicio variables utilizadas en la evaluación
                conjuntos.Clear();
                expresionesFinal.Clear();
            }
            else
            {
                generarPDF(lexemas);
                //MessageBox.Show("Entrada con errores", "Advertencia");
            }
        }