示例#1
0
        static void Main(string[] args)
        {
            //Generalidades
            Funcion.Ejecutar();

            //Enumeraciones
            Ejercicio_1_y_2_enum.Ejecutar();

            //Conversiones
            Conversion.Ejecutar();

            //Condicionales
            Ejercicio_3_Condicionales.Ejecutar();
            Ejercicio_4_y_5_Condicionales.Ejecutar();
            Ejercicio_6_y_7_Condicionales.Ejecutar();
        }
示例#2
0
        public bool Ejecutar()
        {
            Operar operar = new Operar(this, this);

            //Ejecutará las OPER y ARR de los simbolos
            foreach (var symClass in ClaseSym)
            {
                //Se recupera el tipo de simbolo
                var symClasType = symClass.Value.TipoDato;
                //Si no es null opera el DIMENSIONLST
                if (symClass.Value.Arr != null)
                {
                    var symClassArr = operar.Interpretar(symClass.Value.Arr);
                    symClass.Value.Arreglo = symClassArr.Arreglo;
                }
                //Si no es null opera el OPER
                if (symClass.Value.Oper != null)
                {
                    var symClassOper = operar.Interpretar(symClass.Value.Oper);
                    //Determina si los tipos son los mismo
                    if (symClassOper.TipoDato != symClass.Value.TipoDato)
                    {
                        Main.Imprimir(String.Format("Los tipos no coinciden {0} -> {1} : ({2},{3})", symClassOper.TipoDato, symClass.Value.TipoDato, symClass.Value.Posicion.Fila, symClass.Value.Posicion.Columna));
                        return(true);
                    }
                    //Los tipos coinciden
                    //Se debe determinar si es un arreglo
                    if (symClassOper.TipoDato > Tipo.CLASE)
                    {
                        if (symClassOper.Arreglo.Dimension != symClass.Value.Arreglo.Dimension)
                        {
                            Main.Imprimir(String.Format("Las dimensiones de {0} no coincide con {1}  : ({2},{3})", symClassOper.TipoDato, symClass.Value.TipoDato, symClassOper.Posicion != null ? symClassOper.Posicion.Fila : 0, symClassOper.Posicion != null ? symClassOper.Posicion.Columna : 0));
                            return(true);
                        }
                        //Es un arreglo, debe asegurarse que las dimensiones coincidan
                        if (symClassOper.Arreglo.SizeUni != symClass.Value.Arreglo.SizeUni)
                        {
                            Main.Imprimir(String.Format("El arreglo unidemensional de {0} no coincide con {1}  : ({2},{3})", symClassOper.TipoDato, symClass.Value.TipoDato, symClassOper.Posicion != null ? symClassOper.Posicion.Fila : 0, symClassOper.Posicion != null ? symClassOper.Posicion.Columna : 0));
                            return(true);
                        }
                        if (symClassOper.Arreglo.SizeBi != symClass.Value.Arreglo.SizeBi)
                        {
                            Main.Imprimir(String.Format("El arreglo bidemensional de {0} no coincide con {1}  : ({2},{3})", symClassOper.TipoDato, symClass.Value.TipoDato, symClassOper.Posicion != null ? symClassOper.Posicion.Fila : 0, symClassOper.Posicion != null ? symClassOper.Posicion.Columna : 0));
                            return(true);
                        }
                        if (symClassOper.Arreglo.SizeTri != symClass.Value.Arreglo.SizeTri)
                        {
                            Main.Imprimir(String.Format("El arreglo tridemensional de {0} no coincide con {1}  : ({2},{3})", symClassOper.TipoDato, symClass.Value.TipoDato, symClassOper.Posicion != null ? symClassOper.Posicion.Fila : 0, symClassOper.Posicion != null ? symClassOper.Posicion.Columna : 0));
                            return(true);
                        }
                    }
                    //Asigna el valor de symClassOpera al dato del diccionar de clases actual
                    symClass.Value.Dato = symClassOper.Dato;
                }
                //Si es un arreglo se asegurará de inicializar el arreglo
                else if (symClass.Value.TipoDato > Tipo.CLASE)
                {
                    //Inicializa el dato
                    object arrDato   = null;
                    var    dimArrSym = symClass.Value;
                    //Según las dimensiones
                    switch (dimArrSym.Arreglo.Dimension)
                    {
                    case TipoArreglo.UNI:
                        switch (dimArrSym.TipoDato)
                        {
                        case Tipo.INTARR:
                            arrDato = new int[dimArrSym.Arreglo.SizeUni];
                            break;

                        case Tipo.STRINGARR:
                            arrDato = new string[dimArrSym.Arreglo.SizeUni];
                            break;

                        case Tipo.DOUBLEARR:
                            arrDato = new double[dimArrSym.Arreglo.SizeUni];
                            break;

                        case Tipo.CHARARR:
                            arrDato = new char[dimArrSym.Arreglo.SizeUni];
                            break;

                        case Tipo.BOOLEANARR:
                            arrDato = new bool[dimArrSym.Arreglo.SizeUni];
                            break;

                        case Tipo.CLASEARR:
                            arrDato = new Clase[dimArrSym.Arreglo.SizeUni];
                            break;
                        }
                        break;

                    case TipoArreglo.BI:
                        switch (dimArrSym.TipoDato)
                        {
                        case Tipo.INTARR:
                            arrDato = new int[dimArrSym.Arreglo.SizeBi][];
                            //recorre el arreglo inicializando el arreglo
                            for (int i = 0; i < (arrDato as int[][]).Length; i++)
                            {
                                (arrDato as int[][])[i] = new int[dimArrSym.Arreglo.SizeUni];
                            }
                            break;

                        case Tipo.STRINGARR:
                            arrDato = new string[dimArrSym.Arreglo.SizeBi][];
                            for (int i = 0; i < (arrDato as string[][]).Length; i++)
                            {
                                (arrDato as string[][])[i] = new string[dimArrSym.Arreglo.SizeUni];
                            }
                            break;

                        case Tipo.DOUBLEARR:
                            arrDato = new double[dimArrSym.Arreglo.SizeBi][];
                            for (int i = 0; i < (arrDato as double[][]).Length; i++)
                            {
                                (arrDato as double[][])[i] = new double[dimArrSym.Arreglo.SizeUni];
                            }
                            break;

                        case Tipo.CHARARR:
                            arrDato = new char[dimArrSym.Arreglo.SizeBi][];
                            for (int i = 0; i < (arrDato as char[][]).Length; i++)
                            {
                                (arrDato as char[][])[i] = new char[dimArrSym.Arreglo.SizeUni];
                            }
                            break;

                        case Tipo.BOOLEANARR:
                            arrDato = new bool[dimArrSym.Arreglo.SizeBi][];
                            for (int i = 0; i < (arrDato as bool[][]).Length; i++)
                            {
                                (arrDato as bool[][])[i] = new bool[dimArrSym.Arreglo.SizeUni];
                            }
                            break;

                        case Tipo.CLASEARR:
                            arrDato = new Clase[dimArrSym.Arreglo.SizeBi][];
                            for (int i = 0; i < (arrDato as Clase[][]).Length; i++)
                            {
                                (arrDato as Clase[][])[i] = new Clase[dimArrSym.Arreglo.SizeUni];
                            }
                            break;
                        }
                        break;

                    case TipoArreglo.TRI:
                        switch (dimArrSym.TipoDato)
                        {
                        case Tipo.INTARR:
                            arrDato = new int[dimArrSym.Arreglo.SizeTri][][];
                            for (int i = 0; i < dimArrSym.Arreglo.SizeTri; i++)
                            {
                                (arrDato as int[][][])[i] = new int[dimArrSym.Arreglo.SizeBi][];
                                for (int j = 0; j < dimArrSym.Arreglo.SizeBi; i++)
                                {
                                    (arrDato as int[][][])[i][j] = new int[dimArrSym.Arreglo.SizeUni];
                                }
                            }
                            break;

                        case Tipo.STRINGARR:
                            arrDato = new string[dimArrSym.Arreglo.SizeTri][][];
                            for (int i = 0; i < dimArrSym.Arreglo.SizeTri; i++)
                            {
                                (arrDato as string[][][])[i] = new string[dimArrSym.Arreglo.SizeBi][];
                                for (int j = 0; j < dimArrSym.Arreglo.SizeBi; i++)
                                {
                                    (arrDato as string[][][])[i][j] = new string[dimArrSym.Arreglo.SizeUni];
                                }
                            }
                            break;

                        case Tipo.DOUBLEARR:
                            arrDato = new double[dimArrSym.Arreglo.SizeTri][][];
                            for (int i = 0; i < dimArrSym.Arreglo.SizeTri; i++)
                            {
                                (arrDato as double[][][])[i] = new double[dimArrSym.Arreglo.SizeBi][];
                                for (int j = 0; j < dimArrSym.Arreglo.SizeBi; i++)
                                {
                                    (arrDato as double[][][])[i][j] = new double[dimArrSym.Arreglo.SizeUni];
                                }
                            }
                            break;

                        case Tipo.CHARARR:
                            arrDato = new char[dimArrSym.Arreglo.SizeTri][][];
                            for (int i = 0; i < dimArrSym.Arreglo.SizeTri; i++)
                            {
                                (arrDato as char[][][])[i] = new char[dimArrSym.Arreglo.SizeBi][];
                                for (int j = 0; j < dimArrSym.Arreglo.SizeBi; i++)
                                {
                                    (arrDato as char[][][])[i][j] = new char[dimArrSym.Arreglo.SizeUni];
                                }
                            }
                            break;

                        case Tipo.BOOLEANARR:
                            arrDato = new bool[dimArrSym.Arreglo.SizeTri][][];
                            for (int i = 0; i < dimArrSym.Arreglo.SizeTri; i++)
                            {
                                (arrDato as bool[][][])[i] = new bool[dimArrSym.Arreglo.SizeBi][];
                                for (int j = 0; j < dimArrSym.Arreglo.SizeBi; i++)
                                {
                                    (arrDato as bool[][][])[i][j] = new bool[dimArrSym.Arreglo.SizeUni];
                                }
                            }
                            break;

                        case Tipo.CLASEARR:
                            arrDato = new Clase[dimArrSym.Arreglo.SizeTri][][];
                            for (int i = 0; i < dimArrSym.Arreglo.SizeTri; i++)
                            {
                                (arrDato as Clase[][][])[i] = new Clase[dimArrSym.Arreglo.SizeBi][];
                                for (int j = 0; j < dimArrSym.Arreglo.SizeBi; i++)
                                {
                                    (arrDato as Clase[][][])[i][j] = new Clase[dimArrSym.Arreglo.SizeUni];
                                }
                            }
                            break;
                        }
                        break;
                    }
                    //asigna el dato al symClass
                    symClass.Value.Dato = arrDato;
                }
            }
            //Importar clases
            foreach (var impNameClass in ClaseImpNames)
            {
                //Buscará coincidencias en el diccionario de clases
                if (Recorrido.Clases.ContainsKey(impNameClass))
                {
                    ClaseImp.Add(impNameClass, Clase.Copiar(Recorrido.Clases[impNameClass]));
                }
                else
                {
                    Main.Imprimir(String.Format("No se encontró la importación : {0}", impNameClass));
                    return(true);
                }
            }
            //Verificará que las funciones marcadas como override existan en alguna clase importada
            bool flagOverride = false;

            foreach (var funClass in ClaseEnt)
            {
                if (funClass.Value.Override)
                {
                    //Es una sobrecarga, lo que obliga que exista una función con el mismo nombre en
                    //el listado de entornos de clases importadas
                    foreach (var impClass in ClaseImp)
                    {
                        //Buscará en sus entornos un nombre igual
                        if (impClass.Value.ClaseEnt.ContainsKey(funClass.Key))
                        {
                            flagOverride = true;
                            break;
                        }
                    }
                    //No encontró ninguna coinciden, se termina la operación
                    if (!flagOverride)
                    {
                        Main.Imprimir(String.Format("La función {0} no permite sobrecarga", funClass.Key));
                        return(true);
                    }
                }
            }
            //Buscará una ocurrencia del main
            if (ClaseEnt.ContainsKey("main"))
            {
                //Recupera dicha ocurrencia
                Funcion func = ClaseEnt["main"];
                //Ejecuta la ocurrencia
                Nativa.Print(String.Format("El main terminó en : {0}", func.Ejecutar()));
            }
            //Al finalizar copia las variables que se encuentran en el diccionario de simbolos local
            foreach (var locSym in ClaseSym)
            {
                Main.AgregarSimbolo(locSym.Key, locSym.Value, this.ToString());
            }
            return(false);
        }
        public object getValor(Ambito ambito)
        {
            try
            {
                List <Object> valores = getValoresParam(ambito);
                /// GENERO MI CLAVE PARA PODER OBTENER LA FUNCION QUE DESEO
                Clave clave = new Clave(this.id.ToLower(), getNodoParametros(ambito), "");
                /// LLAMO A LA FUNCION QUE DESEO EJECUTAR
                Ambito  aux = AmbitoDeClase(ambito);
                Funcion f   = aux.GetFuncion(clave);
                if (f != null)
                {
                    this.vibililidad = f.Vibililidad;
                    ///CREO EL AMBITO DE LA FUNCION
                    Ambito auxliar = new Ambito(aux, this.clase.ToLower(), ambito.archivo);
                    this.vibililidad = f.Vibililidad;
                    if (this.vibililidad == Estatico.Vibililidad.PROTEGIDO && !(ambito.idAmbito.ToLower().Contains(Estatico.temporal.idAmbito.ToLower())))
                    {
                        return(new Nulo());
                    }
                    ///SETEO LOS PARAMETROS QUE RECIBE
                    auxliar = f.seteaParametrosLocales(auxliar, valores);

                    ///OBTENGO EL VALOR QUE DEFINE
                    Object valor = f.Ejecutar(auxliar);
                    if (valor is NodoReturn)
                    {
                        Object valorReal    = ((NodoReturn)valor).valor;
                        String tipoEsperado = f.Tipo.ToLower();
                        if (tipoEsperado.Equals(((NodoReturn)valor).tipo.ToLower()) || ((NodoReturn)valor).tipo.ToLower().Equals("nulo"))
                        {
                            this.ValorAux = valorReal;
                            return(valorReal);
                        }
                        else
                        {
                            TError error = new TError("Semantico", "El tipo de retorno no coincide: Tipo de Funcion: \"" + tipoEsperado + "\", encontrado: \"" + ((NodoReturn)valor).tipo.ToLower() + "\" | Clase: " + this.clase + " | " + ambito.archivo, this.linea, this.columna, false);
                            Estatico.errores.Add(error);
                            Estatico.ColocaError(error);
                            return(new Nulo());
                        }
                    }
                }
                else if (this.id.ToLower().Equals("buscar"))
                {
                    Simbolo l = (Simbolo)ambito.getSimbolo("cutz");/// :)
                    if (l != null)
                    {
                        Variable v       = (Variable)l;
                        Opciones listado = (Opciones)v.valor;
                        if (valores.Count == 2)
                        {
                            if (valores.ElementAt(1) is int)
                            {
                                Object index1 = valores.ElementAt(0);
                                int    index2 = (int)valores.ElementAt(1);

                                Object val = listado.obtenerDeLista(index1, index2);

                                NodoReturn n = creaNodoReturn(val);

                                this.ValorAux = n.valor;

                                return(n.valor);
                            }
                        }
                    }
                }
                else if (this.id.ToLower().Equals("obtener"))
                {
                    Simbolo l = (Simbolo)ambito.getSimbolo("cutz");
                    if (l != null)
                    {
                        Variable v       = (Variable)l;
                        Opciones listado = (Opciones)v.valor;
                        if (valores.ElementAt(0) is int && valores.ElementAt(1) is int)
                        {
                            int        index1 = (int)valores.ElementAt(0);
                            int        index2 = (int)valores.ElementAt(1);
                            Object     val    = listado.obtenerDeLista(index1, index2);
                            NodoReturn n      = creaNodoReturn(val);

                            this.ValorAux = n.valor;
                            return(n.valor);
                        }
                    }
                }
                else if (this.id.ToLower().Equals("insertar"))
                {
                    Simbolo l = (Simbolo)ambito.getSimbolo("cutz");
                    if (l != null)
                    {
                        Variable v       = (Variable)l;
                        Opciones listado = (Opciones)v.valor;
                        listado.agregarElementos(valores);/// INSERTA ELEMENTOS VACIOS
                        return(new Vacio());
                    }
                }
                else
                {
                    TError error = new TError("Semantico", "No existe funcion: " + this.id + " que reciba parametro: " + getMensajeError(ambito) + " | Clase: " + this.clase + " | " + ambito.archivo, this.linea, this.columna, false);
                    Estatico.errores.Add(error);
                    Estatico.ColocaError(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Error al Buscar la funcion, en ejecucion | Erro: " + e.Message, this.linea, this.columna, false);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
            return(new Nulo());
        }