Example #1
0
 protected void match(clasificaciones espera)
 {
     //Console.WriteLine(getContenido() + " = " + espera);
     if (espera == getClasificacion())
     {
         NextToken();
     }
     else
     {
         bitacora.WriteLine("ERROR DE SINTAXIS EN LINEA {0}, EN CARACTER {1}", linea, caracter);
         bitacora.WriteLine("ERROR DE SINTAXIS: SE ESPERA UN " + espera);
         Console.WriteLine("ERROR DE SINTAXIS EN LINEA {0}, EN CARACTER {1}", linea, caracter);
         throw new Exception("ERROR DE SINTAXIS: SE ESPERA UN " + espera);
     }
 }
        protected void NextToken()
        {
            char   transicion;
            string palabra = "";
            int    estado  = 0;

            while (estado >= 0)
            {
                transicion = (char)archivo.Peek();

                estado = trand6x[estado, columna(transicion)];
                clasificar(estado);

                if (estado >= 0)
                {
                    archivo.Read();
                    caracter++;

                    if (transicion == 10)
                    {
                        linea++;
                        caracter = 1;
                    }

                    if ((estado > 0 && estado < 33) || estado >= 36)
                    {
                        palabra += transicion;
                    }
                    else
                    {
                        palabra = "";
                    }
                }
            }

            if (estado == E)
            {
                clasificaciones Clasif = getClasificacion();
                if (Clasif == clasificaciones.numero)
                {
                    bitacora.WriteLine("ERROR LEXICO ENCONTRADO, SE ESPERA DIGITO.");
                    bitacora.WriteLine("HAY UN ERROR EN LA LINEA {0}, EN CARACTER {1}", linea, caracter);
                    Console.WriteLine("HAY UN ERROR EN LA LINEA {0}, EN CARACTER {1}", linea, caracter);
                    throw new Exception("ERROR LEXICO ENCONTRADO, SE ESPERA DIGITO.");
                }
                else if (Clasif == clasificaciones.cadena)
                {
                    bitacora.WriteLine("ERROR LEXICO ENCONTRADO, SE ESPERA COMILLA O COMILLAS.");
                    bitacora.WriteLine("HAY UN ERROR EN LA LINEA {0}, EN CARACTER {1}", linea, caracter);
                    Console.WriteLine("HAY UN ERROR EN LA LINEA {0}, EN CARACTER {1}", linea, caracter);
                    throw new Exception("ERROR LEXICO ENCONTRADO, SE ESPERA COMILLA O COMILLAS.");
                }
                else
                {
                    bitacora.WriteLine("ERROR LEXICO ENCONTRADO, NO SE CERRO COMENTARIO.");
                    bitacora.WriteLine("HAY UN ERROR EN LA LINEA {0}, EN CARACTER {1}", linea, caracter);
                    Console.WriteLine("HAY UN ERROR EN LA LINEA {0}, EN CARACTER {1}", linea, caracter);
                    throw new Exception("ERROR LEXICO ENCONTRADO, NO SE CERRO COMENTARIO.");
                }
            }
            else if (palabra != "")
            {
                setContenido(palabra);
                switch (palabra)
                {
                case "char":
                case "int":
                case "float":
                case "string":
                    setClasificacion(clasificaciones.tipoDato);
                    break;

                case "private":
                case "public":
                case "protected":
                    setClasificacion(clasificaciones.zona);
                    break;

                case "if":
                case "else":
                case "switch":
                    setClasificacion(clasificaciones.condicion);
                    break;

                case "for":
                case "while":
                case "do":
                    setClasificacion(clasificaciones.ciclo);
                    break;
                }

                bitacora.WriteLine("Token = " + getContenido());
                bitacora.WriteLine("Clasificacion = " + getClasificacion());
            }
        }
Example #3
0
 public void setClasificacion(clasificaciones clasificacion)
 {
     this.clasificacion = clasificacion;
 }
Example #4
0
        public void NextToken()
        {
            char   transicion;
            string palabra  = "";
            int    estado   = 0;
            int    anterior = 0;

            while (estado >= 0)
            {
                anterior   = estado;
                transicion = (char)archivo.Peek();

                estado = trand6x[estado, columna(transicion)];
                clasificar(estado);

                if (estado >= 0)
                {
                    archivo.Read();
                    caracter++;

                    if (transicion == 10)
                    {
                        linea++;
                        caracter = 1;
                    }

                    if (estado > 0)
                    {
                        palabra += transicion;
                    }

                    else
                    {
                        palabra = "";
                    }
                }
            }

            if (estado == E)
            {
                clasificaciones clas = getClasificacion();

                if (clas == clasificaciones.numero)
                {
                    bitacora.WriteLine("\nError lexico en la linea {0}, en el caracter {1}, se espera un digito", linea, caracter);
                    throw new Exception("Error lexico: Se espera un digito");
                }
                else if (clas == clasificaciones.cadena)
                {
                    if (anterior == 22)
                    {
                        bitacora.WriteLine("\nError lexico en la linea {0}, en el caracter {1}, se esperan comillas dobles", linea, caracter);
                        throw new Exception("Error lexico: Se espera cierre de comillas dobles");
                    }
                    else if (anterior == 24)
                    {
                        bitacora.WriteLine("\nError lexico en la linea {0}, en el caracter {1}, se esperan comillas simples", linea, caracter);
                        throw new Exception("Error lexico: Se espera cierre de comillas simples");
                    }
                }
                else
                {
                    bitacora.WriteLine("\nError lexico: No se cerrĂ³ el comentario de manera correcta");
                    throw new Exception("Error lexico: No se cerrĂ³ el comentario de manera correcta");
                }
            }

            if (palabra != "")
            {
                setContenido(palabra);
                switch (palabra)
                {
                case "char":
                case "int":
                case "float":
                    setClasificacion(clasificaciones.tipoDato);
                    break;

                case "private":
                case "public":
                case "protected":
                    setClasificacion(clasificaciones.zona);
                    break;

                case "if":
                case "else":
                case "switch":
                    setClasificacion(clasificaciones.condicion);
                    break;

                case "for":
                case "while":
                case "do":
                    setClasificacion(clasificaciones.ciclo);
                    break;
                }

                //if para evitar la escritura de un token vacio en nuestro archivo prueba.log
                bitacora.WriteLine("Token = " + getContenido());
                bitacora.WriteLine("Clasificacion = " + getClasificacion());
            }
        }