Ejemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            caracteres.Clear();
            tokens.Clear();
            eat.Clear();
            estados.Clear();
            numEstados.Clear();
            tokencillo.Clear();


            alfabeto.Clear();
            alfabetoNumero.Clear();
            transiciones.Clear();

            finales.Clear();
            lineas.Clear();
            tea.Clear();
            cm = null;
        }
Ejemplo n.º 2
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            // Empieza la lectura de archivo, del lenguaje a utilizar
            var            fileContent    = string.Empty;
            var            filePath       = string.Empty;
            OpenFileDialog openFileDialog = new OpenFileDialog();

            if (openFileDialog.ShowDialog() == DialogResult.OK)
            {
                //Get the path of specified file
                filePath = openFileDialog.FileName;
                //Read the contents of the file into a stream
                var fileStream = openFileDialog.OpenFile();
                using (StreamReader reader = new StreamReader(fileStream))
                {
                    fileContent = reader.ReadToEnd();
                }
            }
            // Termina la lectura de archivo, del lenguaje a utilizar


            /*
             * Empieza el almacenamiento del archivo, la idea aquí es
             * leer el lenguaje del archivo y almacenarlo en
             * las clases de caracteres y tokens ya construidas
             */

            string tokens = fileContent;

            string[] tokens2 = tokens.Split(' ', '\r', '\0', '\n');

            String[] datosnew = new String[tokens2.Length];
            int      j        = 0;

            for (int i = 0; i < tokens2.Length; i++)
            {
                if (tokens2[i] != "")
                {
                    datosnew[j] = tokens2[i];
                    j++;
                }
            }
            int contador       = datosnew.Length;
            int placeForTokens = 0;

            // EMPIEZAN A LLENARSE LOS OBJETOS
            for (int x = 0; x < contador; x++)
            {
                if (datosnew[x] == "CARACTERES")
                {
                    x++;
                    while (datosnew[x] != "TOKENS")
                    {
                        Caracteres c = new Caracteres(datosnew[x], datosnew[x + 2]);
                        caracteres.Add(c);
                        x += 3;
                        Console.WriteLine("C: " + datosnew[x]);
                    }
                    placeForTokens = x + 1;
                    break;
                }
            }

            int placeValueTokens = placeForTokens + 2;

            for (int i = placeForTokens; i < contador; i++)
            {
                while (datosnew[i] != "FINDEGRAMATICA" && datosnew[i] != "RESERVADAS")
                {
                    List <string> valDeToks = new List <string>();
                    placeValueTokens = i + 2;
                    while (datosnew[placeValueTokens] != ",")
                    {
                        Console.WriteLine("ADDED: " + datosnew[placeValueTokens]);
                        valDeToks.Add(datosnew[placeValueTokens]);
                        placeValueTokens++;
                    }
                    Tokens t = new Tokens(datosnew[i], valDeToks);
                    this.tokens.Add(t);
                    i = placeValueTokens + 1;
                    Console.WriteLine(datosnew[i]);
                }
                break;
            }

            for (int i = 0; i < contador; i++)
            {
                if (datosnew[i] == "RESERVADAS")
                {
                    i++;
                    while (datosnew[i] != "FINDEGRAMATICA")
                    {
                        string res = datosnew[i];
                        reservadas.Add(res);
                        i++;
                    }
                    break;
                }
            }


            foreach (string s in reservadas)
            {
                Console.WriteLine("reservada: " + s);
            }

            foreach (Caracteres c in caracteres)
            {
                Console.WriteLine("Variable: " + c.variable + " Caracter: " + c.valor);
            }
            foreach (Tokens t in this.tokens)
            {
                Console.Write("Variable: " + t.variable + " ");
                foreach (string s in t.valoresDeToken)
                {
                    Console.Write("Token: " + s + " ");
                }
                Console.WriteLine();
            }

            Caracteres otro       = new Caracteres("otro", "otro");
            Caracteres espacio    = new Caracteres(" ", " ");
            Caracteres saltoLinea = new Caracteres("\n", "\n");
            Caracteres tabulador  = new Caracteres("\t", "\t");

            caracteres.Add(otro);
            caracteres.Add(espacio);
            caracteres.Add(saltoLinea);
            caracteres.Add(tabulador);
            //linea añadida


            // se crea matriz con un objeto de la ClaseMatriz
            // la clase matriz debe ser modificada para albergar los campos que sean
            // necesarios, al menos debe tener el de Token, para saber qué tipo
            // de token sigió el autómata
            ContarEstadosYhacerTrans();

            foreach (Transiciones t in transiciones)
            {
                Console.WriteLine("EI: " + t.estadoInicial + " Tok: " + t.caracter + " EF: " + t.estadoFinal);
            }


            cm = new ClaseMatriz(numEstados.Count, caracteres.Count);
            // Se deben cambiar posiciones en matriz, modificar funciones de getposEstados
            // y get posicion alfabeto para obtener las posiciones y en efecto, cambiar
            // esa posición con el estado al que conduce esa posicion
            int col = 0;

            foreach (Transiciones s in transiciones)
            {
                col = getPosAlfa(s.caracter);
                cm.CambiarPosicion(Convert.ToInt32(s.estadoInicial), col, Convert.ToInt32(s.estadoFinal));
            }

            cm.ImprimirMatriz();
        }