Esempio n. 1
0
        private static void IdentificarToken(List <char> C, ref string token, int EstadoFinal)
        {
            string Palabra = "";

            foreach (char a in C)
            {
                Palabra += a;
            }
            switch (EstadoFinal)
            {
            case 201:
                Identificador unIdentificador = new Identificador();
                unIdentificador.Nombre = Palabra.Trim();
                foreach (Identificador otroIdentificador in Identificadores)
                {
                    if (otroIdentificador.Equals(unIdentificador))
                    {
                        token += otroIdentificador.Index.ToString(); return;
                    }
                }
                unIdentificador.Index = Identificadores.Count + 1;
                token += unIdentificador.Index.ToString();
                Identificadores.Add(unIdentificador);
                break;

            case 212:
                NumericoEntero unNumericoEntero = new NumericoEntero();
                unNumericoEntero.Contenido = int.Parse(Palabra);
                foreach (NumericoEntero otroNE in ConstantesNumericasEnteras)
                {
                    if (otroNE.Equals(unNumericoEntero))
                    {
                        token += otroNE.Index.ToString(); return;
                    }
                }
                unNumericoEntero.Index = ConstantesNumericasEnteras.Count + 1;
                token += unNumericoEntero.Index.ToString();
                ConstantesNumericasEnteras.Add(unNumericoEntero);
                break;

            case 211:
                NumericoReal unNumericoReal = new NumericoReal();
                unNumericoReal.Contenido = double.Parse(Palabra);
                foreach (NumericoReal otroNR in ConstantesNumericasReales)
                {
                    if (otroNR.Equals(unNumericoReal))
                    {
                        token += otroNR.Index.ToString(); return;
                    }
                }
                unNumericoReal.Index = ConstantesNumericasReales.Count + 1;
                token += unNumericoReal.Index.ToString();
                ConstantesNumericasReales.Add(unNumericoReal);
                break;

            case 216:
                NumericoExponencial unNumericoExponencial = new NumericoExponencial();
                string[]            partesExponente       = Palabra.Split('E');
                unNumericoExponencial.Contenido = int.Parse(partesExponente[0]);
                foreach (NumericoExponencial otroNEX in ConstantesNumericasExponenciales)
                {
                    if (otroNEX.Equals(unNumericoExponencial))
                    {
                        token += otroNEX.Index.ToString(); return;
                    }
                }
                unNumericoExponencial.Index = ConstantesNumericasExponenciales.Count + 1;
                token += unNumericoExponencial.Index.ToString();
                unNumericoExponencial.Exponencial = int.Parse(partesExponente[1]);
                ConstantesNumericasExponenciales.Add(unNumericoExponencial);
                break;

            case 210:
                NumericoExpReal unNumericoExpReal   = new NumericoExpReal();
                string[]        partesExponentereal = Palabra.Split('E');
                unNumericoExpReal.Contenido = double.Parse(partesExponentereal[0]);
                foreach (NumericoExpReal otroNER in ConstantesNumericasExpReales)
                {
                    if (otroNER.Equals(unNumericoExpReal))
                    {
                        token += otroNER.Index.ToString(); return;
                    }
                }
                unNumericoExpReal.Index = ConstantesNumericasExpReales.Count + 1;
                token += unNumericoExpReal.Index.ToString();
                unNumericoExpReal.Exponencial = int.Parse(partesExponentereal[1]);
                ConstantesNumericasExpReales.Add(unNumericoExpReal);
                break;
            }
        }
Esempio n. 2
0
        public static List <string> PrimeraPasada(List <string> LineasTokens)
        {
            List <string> LineasSemantica = new List <string>();
            string        strActual       = "";

            try
            {
                foreach (string cadena in LineasTokens)
                {
                    strActual = cadena;
                    strActual = strActual.Substring(0, strActual.Length - 2);
                    string[] combinacionesde2 = CrearCombinaciones(2, strActual); //Metodo que crea combinaciones de 2 dos para descubrir los TDD1 ID
                    foreach (string str in combinacionesde2)
                    {
                        string[] arreglo1 = str.Split(' ');

                        if (arreglo1[0].Substring(0, 3) == "TDD" && arreglo1[1].Substring(0, 2) == "ID")  //if para veificar si es un TDD1 IDX
                        {
                            string        strIndex1 = arreglo1[1];
                            int           index     = int.Parse(strIndex1.Replace("ID", ""));
                            Identificador elemento  = MetodosAL.Identificadores.Find(x => x.Index == index);
                            MetodosAL.Identificadores.Remove(elemento);
                            switch (arreglo1[0])
                            {
                            case "TDD1":
                                elemento.Tipo = "ENTE";     //Cambialos por los que vayas a usar
                                break;

                            case "TDD2":
                                elemento.Tipo = "REAL";
                                break;

                            case "TDD3":
                                elemento.Tipo = "CADE";
                                break;

                            case "TDD4":
                                elemento.Tipo = "CHAR";
                                break;

                            case "TDD5":
                                elemento.Tipo = "BOOL";
                                break;

                            default:
                                throw new Exception("Tipo de dato erroneo");
                            }
                            MetodosAL.Identificadores.Add(elemento);
                        }
                    }
                }
                foreach (string d in LineasTokens)
                {
                    LineasSemantica.Add(ObtenerArchivoTemporal(d)); //Obtiene el archivo intermedio
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
            return(LineasSemantica);
        }