Esempio n. 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Codigo"></param>
        /// <returns></returns>
        private int ANALIZAR_DECLARACIONES(List <string> Codigo)
        {
            if (Dimensionales.Count == 0)
            {
                return(1);
            }

            Dictionary <string, string[]> tokens_analizar = new Dictionary <string, string[]>();

            string[] lista_tokens = new string[] {
                "entero",
                "decimal",
                "objeto",
                "flotante",
                "cadena"
            };

            while (Dimensionales.Count >= 1)
            {
                string dim = Dimensionales.Dequeue();
                foreach (string tokens in lista_tokens)
                {
                    bool c = dim.Contains(tokens);
                    if (c)
                    {
                        string[] trozo = dim.Replace(tokens, "").Replace("publico", "").Replace("privado", "").Replace("protegido", "").Replace("virtual", "").Replace(" ", "").Replace(";", "").Split('=');
                        try
                        {
                            try
                            {
                                tokens_analizar.Add(trozo[0], new string[] { tokens, trozo[1] });
                            }
                            catch { tokens_analizar.Add(trozo[0], new string[] { tokens, null }); }
                        }
                        catch
                        {
                            this.ERRORES_.Add("Existe un error:  ya se ha declarado una variable con el nombre de "
                                              + trozo[0] + " y de tipo " + tokens + " , Cambia el nombre  para que compile tu chumpe");
                        }
                    }
                }
            }

            List <string> expresion_error = new List <string>();
            List <int>    dim_err         = new List <int>();
            int           err_salida      = AnalizadorLexico.ANALIZADOR__DIMENSIONES_EXACTAS(tokens_analizar, Codigo,
                                                                                             out expresion_error, out dim_err);

            switch (err_salida)
            {
            case (int)ERR_SECUENCIA.DIMENSION_INCORRECTA:
                for (int i = 0; i < dim_err.Count; i++)
                {
                    switch (dim_err[i])
                    {
                    case (int)ERR_DIMENSIONES.DIM_NOES_CADENA:
                        this.ERRORES_.Add("el nombre [" + expresion_error[i] +
                                          "] declarado como cadena [no es de ese tipo en algun lugar del contexto] [ERR:" + dim_err[i] + "]");
                        break;

                    case (int)ERR_DIMENSIONES.DIM_NOES_DECIMAL:
                        this.ERRORES_.Add("el nombre [" + expresion_error[i] +
                                          "] declarado como decimal [no es de ese tipo en algun lugar del contexto] [ERR:" + dim_err[i] + "]");
                        break;

                    case (int)ERR_DIMENSIONES.DIM_NOES_ENTERO:
                        this.ERRORES_.Add("el nombre [" + expresion_error[i] +
                                          "] declarado como entero [no es de ese tipo en algun lugar del contexto] [ERR:" + dim_err[i] + "]");
                        break;

                    case (int)ERR_DIMENSIONES.DIM_NOES_FLOTANTE:
                        this.ERRORES_.Add("el nombre [" + expresion_error[i] +
                                          "] declarado como flotante [no es de ese tipo en algun lugar del contexto] [ERR:" + dim_err[i] + "]");
                        break;

                    case (int)ERR_DIMENSIONES.DIM_SIN_DELIMITADOR_PUNTOCOMA:
                        this.ERRORES_.Add("el nombre [" + expresion_error[i] +
                                          "] le falta el delimitador [;] en algun contexto [ERR:" + dim_err[i] + "]");
                        break;
                    }
                }
                break;

            case (int)ERR_SECUENCIA.EXPRESION_NOIDENTIFICADA:
                this.ERRORES_.Add("La expresion " + expresion_error + " No ha sido identificada");
                break;
            }

            return(0);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="Codigo"></param>
        /// <returns></returns>
        private bool ANALIZAR_EXPRESIONES(List <string> Codigo)
        {
            try
            {
                Stack <string> PilaExpresion = new Stack <string>();
                int            i             = 0;
                for (i = 0; i < Codigo.Count; i++)
                {
                    foreach (string exp  in EXPRESIONES_)
                    {
                        int index = Codigo[i].IndexOf(exp);
                        int d1    = Codigo[i].IndexOf("(");
                        int d2    = Codigo[i].IndexOf(")");
                        if (index != -1 && d1 != -1 && d2 != -1)
                        {
                            PilaExpresion.Push(Codigo[i]);
                            break;
                        }
                        else if (index != -1)
                        {
                            continue;
                        }
                        else
                        {
                            bool bandera = false;
                            foreach (string delim in DELIMITADORES)
                            {
                                int index_de = Codigo[i].IndexOf(delim);
                                if (index_de != -1)
                                {
                                    PilaExpresion.Push(Codigo[i]);
                                    bandera = true;
                                    break;
                                }
                                else
                                {
                                    bandera = false;
                                }
                            }
                            if (bandera == true)
                            {
                                break;
                            }
                        }
                    }
                }
                string err_expresion = null;
                int    valor_err     = AnalizadorLexico.ANALIZADOREXPRESIONES_RESERVADAS(PilaExpresion, out err_expresion);
                switch (valor_err)
                {
                case (int)ERR_SECUENCIA.ESPRESION_PARENTESIS:
                    this.ERRORES_.Add("Error en expresiones de parentesis cerca de " + err_expresion);
                    break;

                case (int)ERR_SECUENCIA.EXPRESION_CIERRE_MIENTRAS:
                    this.ERRORES_.Add("Error se esperaba un cierre en el ciclo mientras");
                    break;

                case (int)ERR_SECUENCIA.EXPRESION_CIERRE_PARA:
                    this.ERRORES_.Add("Error se esperaba un cierre en el ciclo para ");
                    break;

                case (int)ERR_SECUENCIA.EXPRESION_CIERRE_SI:
                    this.ERRORES_.Add("Error se esperaba un cierre en la condicion si ");
                    break;

                case (int)ERR_SECUENCIA.EXPRESION_MIENTRAS:
                    this.ERRORES_.Add("Error en ciclo mientras se esperaba una expresion aceptada cerca de  [" + err_expresion + "]");
                    break;

                case (int)ERR_SECUENCIA.EXPRESION_PARA:
                    this.ERRORES_.Add("Error en ciclo para se esperaba una expresion aceptada cerca de  [" + err_expresion + "]");
                    break;

                case (int)ERR_SECUENCIA.EXPRESION_SI:
                    this.ERRORES_.Add("Error en la condicion si se esperaba una expresion aceptada cerca de  [" + err_expresion + "]");
                    break;

                case (int)ERR_SECUENCIA.EXPRESION_NOIDENTIFICADA:
                    this.ERRORES_.Add("Error cerca de la expresion  [" + err_expresion + "] no se ha identificado (¿ha perdido algun chumpe?)");
                    break;
                }
                if (valor_err != 1)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch { return(true); }
        }