Exemple #1
0
        private void declaracionApartirExp(Ambito ambito)
        {
            if (!ambito.existeVariable(this.idArr.ToLower()))
            {
                //TENGO QUE VER SI LO QUE ME RETORNA LA EXPRESION ES UN ARREGLO Y SI HACE MATCH CON LOS DATOS QUE TENGO
                Object arr     = this.exp.getValor(ambito);
                String tipoaux = this.exp.getTipo(ambito);
                if (arr is Arreglo)
                {
                    Arreglo arreglo = (Arreglo)arr;

                    if (this.NumDim == arreglo.numDimensiones)
                    {
                        if (arreglo.Tipo.Equals("nuevo"))
                        {
                            arreglo.setID(this.idArr);
                            arreglo.setTipo(this.tipo.ToLower());
                            arreglo.setVisibilidad(this.visibilidad);

                            ambito.agregarVariableAlAmbito(this.idArr.ToLower(), arreglo);
                        }
                        else if (arreglo.Tipo.ToLower().Equals(this.tipo.ToLower()))
                        {
                            ambito.agregarVariableAlAmbito(this.idArr.ToLower(), arreglo);
                        }
                        else
                        {
                            TError error = new TError("Semantico", "Los tipos del arreglo no concuerdan, se esperaba: \"" + this.tipo + "\" y se econtro: \"" + arreglo.Tipo.ToLower() + "\"" + "  | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                            Estatico.errores.Add(error);
                            Estatico.ColocaError(error);
                        }
                    }
                    else
                    {
                        TError error = new TError("Semantico", "Para \"" + this.idArr.ToLower() + "\", Las dimensiones no concuerdan se esperaba: " + this.NumDim + ", dimensiones y se encontraron: " + arreglo.numDimensiones + "  | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                        Estatico.errores.Add(error);
                        Estatico.ColocaError(error);
                    }
                }
                else if (arr is Nulo)
                {
                    ambito.agregarVariableAlAmbito(this.idArr.ToLower(), new Arreglo(new List <object>(), new List <int>(), this.NumDim, this.idArr.ToLower(), true, this.visibilidad, this.tipo));
                }
                else
                {
                    TError error = new TError("Semantico", "Se esperaba un arreglo como valor para: \"" + this.idArr + "\", se encontro: \"" + tipoaux + "\"  | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                    Estatico.errores.Add(error);
                    Estatico.ColocaError(error);
                }
            }
            else
            {
                TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idArr + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
        }
Exemple #2
0
        public object Ejecutar(Ambito ambito)
        {
            /// YA QUE LO VOY A TRATAR COMO UN OBJETO:
            /// 1) DEBO DE COLOCARLE UN CONSTRUCTOR AL CUAL ME VA A SERVIR PARA PODER MANDARLE LOS PARAMETROS CUANDO ESTA SE LLAME
            /// 2) AL MOMENTO DE LLAMAR LA PREGUNTA DEBO DE MANDARLE LOS MISMOS PARAMETROS PARA INSTANCIAR LA PREGUNTA QUE EN TEORIA DEBERIAN SER LOS MISMOS
            /// 3) LA PREGUNTA LA VOY A GUARDAR COMO UN OBJETO DENTRO DEL AMBITO DE LA CLASE LA CUAL VA A GUARDAR COMO UNA VARIABLE QUE A GUARDAR COMO VALOR OBJETO DE TIPO
            /// PREGUNTA
            try
            {
                if (!ambito.existeVariable(this.identificador.ToLower()))
                {
                    Ambito amPregunta = new Ambito(ambito, this.identificador.ToLower(), ambito.archivo);

                    /*CREO EL CONSTRUCTOR DE LA PREGUNTA QUE ME VA A SERVIR PARA PODER DECLARAR EN EL AMBITO LAS VARIABLES*/
                    Constructor c = new Constructor(this.parametros, new List <Instruccion>(), linea, columna, clase);

                    /*AGREGO EL CONSTRUCTOR DE LA PREGUNTA AL AMBITO*/
                    amPregunta.agregarConstructor(new ClaveFuncion(this.identificador.ToLower(), "vacio", parametros), c);

                    /*VOY A A GREGAR UNA VARIABLE TEMPORAL PARA QUE ENTONCES PUEDA GUARDAR LAS INSTRUCCIONES :) */
                    Variable v = new Variable("instr", "vale", Estatico.Vibililidad.PRIVADO, this.declaraciones);

                    /*LA AGREGO AL AMBITO DE ESTA PREGUNTA :)*/
                    amPregunta.agregarVariableAlAmbito("instr", v);

                    /*CREO EL OBJETO DE TIPO PREGUNTA*/
                    Objeto pregunta = new Objeto("pregunta", amPregunta);

                    /*AGREGO LA VARIABLE AL AMBITO ACTUAL PARA PODER ACCERDER A LA PREGUNTA EN UN LLAMADO A LA MISMA*/
                    Variable p = new Variable(this.identificador.ToLower(), "pregunta", Estatico.Vibililidad.PRIVADO, pregunta);

                    /*AGREGO LA VARIABLE EN EL AMBITO Y TERMINA*/
                    ambito.agregarVariableAlAmbito(this.identificador.ToLower(), p);

                    return(new Nulo());
                }
                else
                {
                    TError error = new TError("Semantico", "Ya existe una definicion de un simbolo: \"" + identificador + "\", las preguntas se tratan como objetos por lo que no pueden haber multiples definiciones de un objeto con el mismo nombre | Clase"
                                              + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.ColocaError(error);
                    Estatico.errores.Add(error);
                }
            }
            catch (Exception e)
            {
                TError erro = new TError("Ejecucion", "Error al intentar ejecutar la declaracion de una pregunta | Clase: " + clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna, false);
                Estatico.errores.Add(erro);
                Estatico.ColocaError(erro);
            }
            return(new Nulo());
        }
Exemple #3
0
 private void declaracionVacia(Ambito ambito)
 {
     if (!ambito.existeVariable(this.idArr.ToLower()))
     {
         Arreglo arr = new Arreglo(new List <object>(), new List <object>(), new List <int>(), this.NumDim, this.idArr.ToLower(), true, this.visibilidad, this.tipo);
         ambito.agregarVariableAlAmbito(this.idArr.ToLower(), arr);
     }
     else
     {
         TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idArr + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
         Estatico.errores.Add(error);
         Estatico.ColocaError(error);
     }
 }
Exemple #4
0
 private void declaracionApartirDeArbol(Ambito ambito)
 {
     if (!ambito.existeVariable(this.idArr.ToLower()))
     {
         GeneradorArreglo gen = new GeneradorArreglo(this.arbolArreglo);
         if (!gen.huboError)
         {
             int numaux = gen.numDimensiones;
             if (NumDim == gen.numDimensiones)
             {
                 ///FALTA COMPROBAR SI TODOS LOS ELEMENTOS DEL ARREGLO SON DEL MISMO TIPO
                 ///
                 List <Object> valores = linealizadaValores(gen.linealizacion, ambito);
                 if (valores != null)
                 {
                     Arreglo arr = new Arreglo(this.arbolArreglo, valores, gen.dimensiones, this.NumDim, this.idArr.ToLower(), true, this.visibilidad, this.tipo);
                     ambito.agregarVariableAlAmbito(this.idArr.ToLower(), arr);
                 }
                 else
                 {
                     TError error = new TError("Semantico", "El Arreglo: \"" + this.idArr + "\" no concuerda con el tipo esperado: " + this.tipo + " | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                     Estatico.errores.Add(error);
                     Estatico.ColocaError(error);
                 }
             }
             else
             {
                 TError error = new TError("Semantico", "Las dimensiones declaradas para: \"" + this.idArr + "\" No concuerdan, Se esperaban: " + this.NumDim + " y se encontro: " + gen.numDimensiones + " | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                 Estatico.errores.Add(error);
                 Estatico.ColocaError(error);
             }
         }
         else
         {
             TError error = new TError("Semantico", "Declaracion erreonea de Arreglo: \"" + this.idArr + "\" en este Ambito | Error: " + gen.mensajesError + " | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
             Estatico.errores.Add(error);
             Estatico.ColocaError(error);
         }
     }
     else
     {
         TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idArr + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
         Estatico.errores.Add(error);
         Estatico.ColocaError(error);
     }
 }
Exemple #5
0
        public object getValor(Ambito ambito)
        {
            try
            {
                Ambito ambitoOpcs = new Ambito(null, this.clase, ambito.archivo);                   //CREO EL AMBITO DEL OBJETO

                Opciones listado = new Opciones("opciones", null);                                  // CREO EL LISTADO QUE VA A MANEJAR LOS VALORES

                Variable v = new Variable("cutz", "opciones", Estatico.Vibililidad.LOCAL, listado); // SETEO LA VARIABLE QUE ME VA A GUARDAR EL LISTADO

                ambitoOpcs.agregarVariableAlAmbito("cutz", v);                                      /// LO AGREGO AL AMBITO

                Objeto opciones = new Objeto("opciones", ambitoOpcs);                               /// CREO EL OBJETO OPCIONES


                return(opciones); //LO RETORNO
            }
            catch
            {
            }
            return(new Nulo());
        }
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                Simbolo s = (Simbolo)ambito.getSimbolo(this.identificador.ToLower());
                if (s != null)
                {
                    if (s is Variable)
                    {
                        Variable v     = (Variable)s;
                        Object   valor = v.valor;
                        if (valor is Objeto)
                        {
                            Objeto ob = (Objeto)valor;

                            List <Object> valores = getValoresParams(ambito);

                            if (ob.idClase.ToLower().Equals("pregunta"))
                            {
                                Ambito ambitoPregunta = ob.ambito; // obtengo el ambito de la pregunta

                                /*obtendre el constructor de la pregunta para poder setear los parametros que hagan falta*/
                                ClaveFuncion clave       = new ClaveFuncion(this.identificador.ToLower(), "vacio", getNodosParametros(ambito));
                                Constructor  constructor = (Constructor)ambitoPregunta.getConstructor(clave);
                                if (constructor != null)
                                {
                                    Variable           instruc       = (Variable)ambitoPregunta.getSimbolo("instr");
                                    List <Instruccion> declaraciones = (List <Instruccion>)instruc.valor;/*ya tengo las instrucciones que hacen la ejecucion de delcaraciones*/

                                    if (existePropiedad("etiqueta", ambitoPregunta))
                                    {
                                        /*EN CASO QUE LA PROPIEDAD YA EXISTA EN LA PREGUNTA: RESETEO EL AMBITO*/
                                        ambitoPregunta = new Ambito(ambitoPregunta.Anterior, ambitoPregunta.idAmbito, ambitoPregunta.archivo);
                                        ambitoPregunta.agregarConstructor(clave, constructor);
                                        ambitoPregunta.agregarVariableAlAmbito("instr", instruc);
                                    }
                                    /*aqui ya setee los parametros que venian en la pregunta en el ambito global ahora voy a ejecutar las declaraciones sobre este ambito*/
                                    ambitoPregunta = constructor.seteaParametrosLocales(ambitoPregunta, valores);
                                    ejecutaLasDeclaracionesPregunta(ambitoPregunta, declaraciones);                       /*carga todo lo de la pregunta*/

                                    Pregunta p = new Pregunta(ambitoPregunta, this.identificador.ToLower(), this.numero); // formo la pregunta

                                    Nota n = new Nota(p);

                                    n.ShowDialog();

                                    if (llamaMostar)
                                    {
                                        Ambito aux = ambitoPregunta.Anterior;
                                        ambitoPregunta.Anterior = null;
                                        LLamadaFuncion l = new LLamadaFuncion(clase, linea, columna, new Llamada("mostrar", linea, columna, clase));
                                        l.Ejecutar(ambitoPregunta);
                                        ambitoPregunta.Anterior = aux;
                                    }

                                    ob.ambito = ambitoPregunta; /*ASIGNO EL NUEVO AMBITO A OB*/

                                    if (n.salir != null)
                                    {
                                        return(n.salir);
                                    }
                                }
                                else
                                {
                                    TError error = new TError("Semantico", "Para el simbolo: \"" + identificador + "\" No existe una pregunta de tipo Nota que rebiba los parametros especificados | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                                    Estatico.ColocaError(error);
                                    Estatico.errores.Add(error);
                                }
                            }
                            else
                            {
                                TError error = new TError("Semantico", "El simbolo: \"" + identificador + "\" No es un objeto de tipo Pregunta, por lo que no es aplicable la instrucccion | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                                Estatico.ColocaError(error);
                                Estatico.errores.Add(error);
                            }
                        }
                        else
                        {
                            TError error = new TError("Semantico", "El simbolo: \"" + identificador + "\" No es un objeto de tipo Nota, por lo que no es aplicable la instrucccion | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                            Estatico.ColocaError(error);
                            Estatico.errores.Add(error);
                        }
                    }
                    else
                    {
                        TError error = new TError("Semantico", "El simbolo: \"" + identificador + "\" No es un objeto de tipo Nota, por lo que no es aplicable la instrucccion | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                        Estatico.ColocaError(error);
                        Estatico.errores.Add(error);
                    }
                }
                else
                {
                    TError error = new TError("Semantico", "La referencia a la pregunta de tipo Nota: \"" + identificador + "\" es Nulo, no existe en este ambito | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.ColocaError(error);
                    Estatico.errores.Add(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Error al ejecutar la Instrccion Nota() | Clase: " + clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna, false);
                Estatico.ColocaError(error);
                Estatico.errores.Add(error);
            }
            return(new Nulo());
        }
Exemple #7
0
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                Simbolo s = (Simbolo)ambito.getSimbolo(this.identificador.ToLower());
                if (s != null)
                {
                    if (s is Variable)
                    {
                        Variable vari           = (Variable)s;
                        String   tipoEsperado   = vari.Tipo;
                        Object   val            = this.valor.getValor(ambito);
                        String   tipoEncontrado = this.valor.getTipo(ambito);
                        if (tipoEncontrado.ToLower().Equals(tipoEsperado.ToLower()) || tipoEncontrado.ToLower().Equals("nulo"))
                        {
                            vari.valor = val;//ASIGNO EL NUEVO VALOR
                        }
                        ////////////////////////////////////////////////////////////////
                        else if (tipoEsperado.ToLower().Equals("entero") && val is double)
                        {
                            Double valor = (Double)val;
                            int    real  = Convert.ToInt32(valor);
                            vari.valor = real;
                        }
                        else if (tipoEsperado.ToLower().Equals("decimal") && val is int)
                        {
                            int    valor = (int)val;
                            double real  = Convert.ToDouble(valor);
                            vari.valor = real;
                        }
                        else if (tipoEsperado.ToLower().Equals("entero") && val is bool)
                        {
                            Boolean valor = (Boolean)val;
                            int     real  = Convert.ToInt32(valor);
                            vari.valor = real;
                        }
                        else if (tipoEsperado.ToLower().Equals("booleano") && val is int)
                        {
                            int     valor = (int)val;
                            Boolean real  = false;
                            if (valor == 1)
                            {
                                real = true;
                            }
                            vari.valor = real;
                        }
                        ////////////////////////////////////////////////////////////////
                        else
                        {
                            TError error = new TError("Semantico", "Tipos no Coinciden al Asignar, Esperado: \"" + tipoEsperado + "\", Encontrado: " + tipoEncontrado + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                            Estatico.errores.Add(error);
                            Estatico.ColocaError(error);
                        }
                    }
                    else if (s is Arreglo)
                    {
                        Arreglo a = (Arreglo)s;
                        Object  v = this.valor.getValor(ambito);
                        String  tipoEncontrado = this.valor.getTipo(ambito);
                        if (v is Arreglo)
                        {
                            Arreglo asig = (Arreglo)v;

                            if (a.numDimensiones == asig.numDimensiones && a.Tipo.ToLower().Equals(asig.Tipo.ToLower()))
                            {
                                Ambito aux = buscarAmbitoDondeEsta(this.identificador.ToLower(), ambito);
                                aux.removerArreglo(this.identificador.ToLower());
                                aux.agregarVariableAlAmbito(this.identificador.ToLower(), new Arreglo(asig.linealizacion, asig.dimensiones, asig.numDimensiones, a.idSimbolo, true, a.Visibilidad, a.Tipo));
                            }
                            else
                            {
                                TError error = new TError("Semantico", " Arreglos no tienen la misma caracteristicas, Se esperaba arreglo: Dimensiones: " + a.numDimensiones + " y Tipo: " + a.Tipo + ", Se econtro: Dimensiones: " + asig.numDimensiones + " y Tipo: " + asig.Tipo + "| Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                                Estatico.errores.Add(error);
                                Estatico.ColocaError(error);
                            }
                        }
                        else
                        {
                            TError error = new TError("Semantico", "Tipos no Coinciden al Asignar, Esperado: \"" + "Arreglo" + "\", Encontrado: " + tipoEncontrado + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                            Estatico.errores.Add(error);
                            Estatico.ColocaError(error);
                        }
                    }
                    else
                    {
                        throw new NotImplementedException();
                    }
                }
                else
                {
                    TError error = new TError("Semantico", "Referencia a Simbolo: \"" + this.identificador + "\" inexistente | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.errores.Add(error);
                    Estatico.ColocaError(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecuccion", "Error al ejecutar la asignacion a Var: \"" + this.identificador + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | " + e.Message, linea, columna, false);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
            return(null);
        }
Exemple #8
0
 public object Ejecutar(Ambito ambito)
 {
     try
     {
         if (this.asignaValor)
         {
             //OBT EL VALOR
             Object valor   = this.expresion.getValor(ambito);                                      //LLAMADA AL VALOR
             String tipoaux = this.expresion.getTipo(ambito);
             if (this.tipo.ToLower().Equals(tipoaux.ToLower()) || tipoaux.ToLower().Equals("nulo")) //SON DEL MISMO TIPO? ESTO ME PERMITE ASIGNARLE NULO COMO TIPO VALIDO
             {
                 //AQUI ASGINO LA VARIABLE
                 if (!ambito.existeVariable(this.idVar.ToLower())) //YA EXISTE?
                 {
                     Variable variable = new Variable(this.idVar.ToLower(), this.tipo.ToLower(), this.visibilidad, valor);
                     ambito.agregarVariableAlAmbito(this.idVar.ToLower(), variable);
                     //ambito.ImprimeAmbito();
                 }
                 else
                 {
                     TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idVar + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                     Estatico.errores.Add(error);
                     Estatico.ColocaError(error);
                 }
             }
             ////////////////////////////////////////////////////
             else if (this.tipo.ToLower().Equals("entero") && valor is Double) // si espero un entero y llega un double
             {
                 Double val  = (Double)valor;
                 int    real = Convert.ToInt32(val);
                 //AQUI ASGINO LA VARIABLE
                 if (!ambito.existeVariable(this.idVar.ToLower())) //YA EXISTE?
                 {
                     Variable variable = new Variable(this.idVar.ToLower(), this.tipo.ToLower(), this.visibilidad, real);
                     ambito.agregarVariableAlAmbito(this.idVar.ToLower(), variable);
                     //ambito.ImprimeAmbito();
                 }
                 else
                 {
                     TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idVar + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                     Estatico.errores.Add(error);
                     Estatico.ColocaError(error);
                 }
             }
             else if (this.tipo.ToLower().Equals("decimal") && valor is int) //SI ESPERO UN DOUBLE Y LLEGA UN ENTERO
             {
                 int    val  = (int)valor;
                 double real = Convert.ToDouble(val);
                 //AQUI ASGINO LA VARIABLE
                 if (!ambito.existeVariable(this.idVar.ToLower())) //YA EXISTE?
                 {
                     Variable variable = new Variable(this.idVar.ToLower(), this.tipo.ToLower(), this.visibilidad, real);
                     ambito.agregarVariableAlAmbito(this.idVar.ToLower(), variable);
                     //ambito.ImprimeAmbito();
                 }
                 else
                 {
                     TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idVar + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                     Estatico.errores.Add(error);
                     Estatico.ColocaError(error);
                 }
             }
             else if (this.tipo.ToLower().Equals("entero") && valor is Boolean) //SI ESPERO UN DOUBLE Y LLEGA UN ENTERO
             {
                 Boolean val  = (Boolean)valor;
                 int     real = Convert.ToInt32(val);
                 //AQUI ASGINO LA VARIABLE
                 if (!ambito.existeVariable(this.idVar.ToLower())) //YA EXISTE?
                 {
                     Variable variable = new Variable(this.idVar.ToLower(), this.tipo.ToLower(), this.visibilidad, real);
                     ambito.agregarVariableAlAmbito(this.idVar.ToLower(), variable);
                     //ambito.ImprimeAmbito();
                 }
                 else
                 {
                     TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idVar + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                     Estatico.errores.Add(error);
                     Estatico.ColocaError(error);
                 }
             }
             else if (this.tipo.ToLower().Equals("booleano") && valor is int) //SI ESPERO UN DOUBLE Y LLEGA UN ENTERO
             {
                 int     val  = (int)valor;
                 Boolean real = false;
                 if (val == 1)
                 {
                     real = true;
                 }
                 //AQUI ASGINO LA VARIABLE
                 if (!ambito.existeVariable(this.idVar.ToLower())) //YA EXISTE?
                 {
                     Variable variable = new Variable(this.idVar.ToLower(), this.tipo.ToLower(), this.visibilidad, real);
                     ambito.agregarVariableAlAmbito(this.idVar.ToLower(), variable);
                     //ambito.ImprimeAmbito();
                 }
                 else
                 {
                     TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idVar + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                     Estatico.errores.Add(error);
                     Estatico.ColocaError(error);
                 }
             }
             ////////////////////////////////////////////////////
             else
             {
                 //AQUI MUESTRO EL ERROR QUE SUCEDA
                 TError error = new TError("Semantico", "El valor Asignado a \"" + this.idVar + "\" no concuerda, Esperado: \"" + this.tipo + "\", encontrado: \"" + tipoaux + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                 Estatico.errores.Add(error);
                 Estatico.ColocaError(error);
             }
         }//ACA TENGO QUE ARREGLAR LA ASIGNACION DE TIPOS
         else
         {
             if (!ambito.existeVariable(this.idVar.ToLower()))// EXISTE YA UNA DEFINICION DE LA VARIABLE?
             {
                 Variable variable = new Variable(this.idVar.ToLower(), this.tipo, this.visibilidad, new Nulo());
                 ambito.agregarVariableAlAmbito(this.idVar.ToLower(), variable);
             }
             else//SI SI EXISTE... ERROR..
             {
                 TError error = new TError("Semantico", "Ya existe una declaracion de: \"" + this.idVar + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false);
                 Estatico.errores.Add(error);
                 Estatico.ColocaError(error);
             }
         }
     }
     catch (Exception e)
     {
         TError error = new TError("Ejecucion", "Error en la declaracion de variable: \"" + this.idVar + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | " + e.Message, this.linea, this.columna, false);
         Estatico.errores.Add(error);
         Estatico.ColocaError(error);
     }
     return(null);
 }
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                Simbolo s = (Simbolo)ambito.getSimbolo(this.identificador.ToLower());
                if (s != null)
                {
                    if (s is Variable)
                    {
                        Variable v     = (Variable)s;
                        Object   valor = v.valor;
                        if (valor is Objeto)
                        {
                            Objeto ob = (Objeto)valor;

                            List <Object> valores = getValoresParams(ambito);

                            if (ob.idClase.ToLower().Equals("pregunta"))
                            {
                                Ambito ambitoPregunta = ob.ambito; /*oteniendo el ambito de la pregunta*/
                                /*obtendre el constructor de la pregunta para poder setear los parametros que hagan falta*/
                                ClaveFuncion clave       = new ClaveFuncion(this.identificador.ToLower(), "vacio", getNodosParametros(ambito));
                                Constructor  constructor = (Constructor)ambitoPregunta.getConstructor(clave);
                                if (constructor != null)
                                {
                                    Variable           instruc       = (Variable)ambitoPregunta.getSimbolo("instr");
                                    List <Instruccion> declaraciones = (List <Instruccion>)instruc.valor;/*ya tengo las instrucciones que hacen la ejecucion de delcaraciones*/
                                    if (existePropiedad("etiqueta", ambitoPregunta))
                                    {
                                        /*EN CASO QUE LA PROPIEDAD YA EXISTA EN LA PREGUNTA: RESETEO EL AMBITO*/
                                        ambitoPregunta = new Ambito(ambitoPregunta.Anterior, ambitoPregunta.idAmbito, ambitoPregunta.archivo);
                                        ambitoPregunta.agregarConstructor(clave, constructor);
                                        ambitoPregunta.agregarVariableAlAmbito("instr", instruc);
                                    }

                                    ambitoPregunta = constructor.seteaParametrosLocales(ambitoPregunta, valores);
                                    ejecutaLasDeclaracionesPregunta(ambitoPregunta, declaraciones);                       /*carga todo lo de la pregunta*/

                                    Pregunta p = new Pregunta(ambitoPregunta, this.identificador.ToLower(), this.numero); // formo la pregunta

                                    if (this.extensiones != null)
                                    {
                                        /*AQUI CUANDO ADMITEN SOLO CIERTAS EXTENSIONES*/
                                        Object ext = this.extensiones.getValor(ambito);
                                        if (ext is String)
                                        {
                                            this.numero = Estatico.numPregunta;
                                            Estatico.numPregunta++;
                                            Fichero f = new Fichero(p, (String)ext, linea, columna, clase, ambito.archivo);
                                            f.ShowDialog();
                                            String resp = f.rutaArchivo;
                                            if (resp.Equals(""))
                                            {
                                                resp = "No se subio ningun Archivo!";
                                            }

                                            PreguntaAlmacenada pr = new PreguntaAlmacenada(p.idPregunta, p.etiqueta, this.numero);
                                            pr.addAnswer(" Archivo Almacenado en: " + resp);
                                            Estatico.resps.Add(pr);

                                            ob.ambito = ambitoPregunta;/*ASIGNO EL NUEVO AMBITO A OB*/

                                            if (f.salir != null)
                                            {
                                                return(f.salir);
                                            }
                                        }
                                        else
                                        {
                                            TError error = new TError("Semantico", "Para el simbolo: \"" + identificador + "\", Se espera una cadena especificando el formato de las Extensiones de Archivos | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                                            Estatico.ColocaError(error);
                                            Estatico.errores.Add(error);
                                        }
                                    }
                                    else
                                    {
                                        /*AQUI CUANDO ADMITEN CUALQUIER EXTENSION*/
                                        this.numero = Estatico.numPregunta;
                                        Estatico.numPregunta++;

                                        Fichero f = new Fichero(p, "", linea, columna, clase, ambito.archivo);
                                        f.ShowDialog();
                                        String resp = f.rutaArchivo;
                                        if (resp.Equals(""))
                                        {
                                            resp = "No se subio ningun Archivo!";
                                        }

                                        PreguntaAlmacenada pr = new PreguntaAlmacenada(p.idPregunta, p.etiqueta, this.numero);
                                        pr.addAnswer(" Archivo Almacenado en: " + resp);
                                        Estatico.resps.Add(pr);

                                        ob.ambito = ambitoPregunta;/*ASIGNO EL NUEVO AMBITO A OB*/

                                        if (f.salir != null)
                                        {
                                            return(f.salir);
                                        }
                                    }
                                }
                                else
                                {
                                    TError error = new TError("Semantico", "Para el simbolo: \"" + identificador + "\" No existe una pregunta de tipo Fichero que rebiba los parametros especificados | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                                    Estatico.ColocaError(error);
                                    Estatico.errores.Add(error);
                                }
                            }
                            else
                            {
                                TError error = new TError("Semantico", "El simbolo: \"" + this.identificador + "\"  no es de tipo Pregunta | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                                Estatico.ColocaError(error);
                                Estatico.errores.Add(error);
                            }
                        }
                        else
                        {
                            TError error = new TError("Semantico", "El simbolo: \"" + this.identificador + "\"  no es de tipo Pregunta | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                            Estatico.ColocaError(error);
                            Estatico.errores.Add(error);
                        }
                    }
                    else
                    {
                        TError error = new TError("Semantico", "El simbolo: \"" + this.identificador + "\"  no es de tipo Pregunta | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                        Estatico.ColocaError(error);
                        Estatico.errores.Add(error);
                    }
                }
                else
                {
                    TError error = new TError("Semantico", "No existe la pregunta de tipo Fichero: \"" + this.identificador + "\" | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.ColocaError(error);
                    Estatico.errores.Add(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Error al ejecutar el guardar un Fichero | Clase: " + clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna, false);
                Estatico.ColocaError(error);
                Estatico.errores.Add(error);
            }
            return(new Nulo());
        }
Exemple #10
0
        public Pregunta getPregunta(Ambito ambito)
        {
            try
            {
                Simbolo s = (Simbolo)ambito.getSimbolo(this.identificador.ToLower());
                if (s != null)
                {
                    if (s is Variable)
                    {
                        Variable v     = (Variable)s;
                        Object   valor = v.valor;
                        if (valor is Objeto)
                        {
                            Objeto        ob      = (Objeto)valor;
                            List <Object> valores = getValoresParams(ambito);
                            this.ob = ob;
                            if (ob.idClase.ToLower().Equals("pregunta"))
                            {
                                Ambito       ambitoPregunta = ob.ambito; /*oteniendo el ambito de la pregunta*/
                                ClaveFuncion clave          = new ClaveFuncion(this.identificador.ToLower(), "vacio", getNodosParametros(ambito));
                                Constructor  constructor    = (Constructor)ambitoPregunta.getConstructor(clave);
                                if (constructor != null)
                                {
                                    Variable           instruc       = (Variable)ambitoPregunta.getSimbolo("instr");
                                    List <Instruccion> declaraciones = (List <Instruccion>)instruc.valor;/*ya tengo las instrucciones que hacen la ejecucion de delcaraciones*/
                                    if (existePropiedad("etiqueta", ambitoPregunta))
                                    {
                                        /*EN CASO QUE LA PROPIEDAD YA EXISTA EN LA PREGUNTA: RESETEO EL AMBITO*/
                                        ambitoPregunta = new Ambito(ambitoPregunta.Anterior, ambitoPregunta.idAmbito, ambitoPregunta.archivo);
                                        ambitoPregunta.agregarConstructor(clave, constructor);
                                        ambitoPregunta.agregarVariableAlAmbito("instr", instruc);
                                    }

                                    ambitoPregunta = constructor.seteaParametrosLocales(ambitoPregunta, valores);
                                    ejecutaLasDeclaracionesPregunta(ambitoPregunta, declaraciones);                       /*carga todo lo de la pregunta*/

                                    Pregunta p = new Pregunta(ambitoPregunta, this.identificador.ToLower(), this.numero); // formo la pregunta

                                    this.ambPregu = ambitoPregunta;

                                    return(p);
                                }
                                else
                                {
                                    TError error = new TError("Semantico", "Para el simbolo: \"" + identificador + "\" No existe una pregunta de tipo " + this.tipoPregunta + " que rebiba los parametros especificados | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, col, false);
                                    Estatico.ColocaError(error);
                                    Estatico.errores.Add(error);
                                }
                            }
                            else
                            {
                                TError error = new TError("Semantico", "Error Al Mostrar Pregunta: \"" + this.identificador + "\" ya que El simbolo  no es de Tipo " + this.tipoPregunta + " | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, col, false);
                                Estatico.errores.Add(error);
                                Estatico.ColocaError(error);
                            }
                        }
                        else
                        {
                            TError error = new TError("Semantico", "Error Al Mostrar Pregunta: \"" + this.identificador + "\" ya que El simbolo  no es de Tipo " + this.tipoPregunta + " | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, col, false);
                            Estatico.errores.Add(error);
                            Estatico.ColocaError(error);
                        }
                    }
                    else
                    {
                        TError error = new TError("Semantico", "Error Al Mostrar Pregunta: \"" + this.identificador + "\" ya que El simbolo  no es de Tipo " + this.tipoPregunta + " | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, col, false);
                        Estatico.errores.Add(error);
                        Estatico.ColocaError(error);
                    }
                }
                else
                {
                    TError error = new TError("Semantico", "Error Al Mostrar Pregunta: \"" + this.identificador + "\" ya que este Simbolo no Existe en este Contexto | Clase: " + clase + " | Archivo: " + ambito.archivo, linea, col, false);
                    Estatico.errores.Add(error);
                    Estatico.ColocaError(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Error al ejecutar Pregunta: " + this.identificador + " | Clase: " + clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, col, false);
                Estatico.ColocaError(error);
                Estatico.errores.Add(error);
            }
            return(null);
        }