コード例 #1
0
 /*
  * Constructor de la clase padre
  * @ts tabla de simbolos padre
  * @user usuario que esta ejecutando las acciones
  * @baseD string por referencia de que base de datos estamos trabajando
  * @mensajes el output de la ejecucion
  */
 public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
 {
     if (condicion == null)
     {
         TablaDeSimbolos ambitoLocal = new TablaDeSimbolos();
         foreach (Simbolo s in ts)
         {
             ambitoLocal.AddLast(s);
         }
         foreach (InstruccionCQL i in cuerpo)
         {
             object r = i.ejecutar(ambitoLocal, ambito, tsT);
             if (r == null)
             {
                 return(r);
             }
         }
         return("");
     }
     else
     {
         Mensaje mensa = new Mensaje();
         object  a     = condicion.ejecutar(ts, ambito, tsT);
         if (a != null)
         {
             if (a.GetType() == typeof(Boolean))
             {
                 flag = (Boolean)a;
                 if ((Boolean)a)
                 {
                     TablaDeSimbolos ambitoLocal = new TablaDeSimbolos();
                     foreach (Simbolo s in ts)
                     {
                         ambitoLocal.AddLast(s);
                     }
                     foreach (InstruccionCQL i in cuerpo)
                     {
                         object r = i.ejecutar(ambitoLocal, ambito, tsT);
                         if (r == null)
                         {
                             return(r);
                         }
                     }
                     return("");
                 }
             }
             else
             {
                 ambito.mensajes.AddLast(mensa.error("La condicion tiene que ser de tipo Bool: " + a.ToString(), l, c, "Semantico"));
                 return(null);
             }
         }
         else
         {
             ambito.mensajes.AddLast(mensa.error("No se aceptan condiciones null ", l, c, "Semantico"));
             return(null);
         }
         return("");
     }
 }
コード例 #2
0
 /*
  * Metodo que se encargara de guardar los valores como variables temporales
  * @atributos es la data a guardar
  * @tsT es la tabla temporal
  */
 private void guardarTemp(LinkedList <Atributo> atributos, TablaDeSimbolos tsT)
 {
     foreach (Atributo atributo in atributos)
     {
         tsT.AddLast(new Simbolo(atributo.tipo, atributo.nombre));
         tsT.setValor(atributo.nombre, atributo.valor);
     }
 }
コード例 #3
0
 /*
  * Metodo que se encargara de guardar los valores como variables temporales
  * @atributos es la data a guardar
  * @tsT es la tabla temporal
  */
 private void setColumnas(LinkedList <Columna> atributos, TablaDeSimbolos tsT)
 {
     foreach (Columna atributo in atributos)
     {
         tsT.AddLast(new Simbolo(atributo.tipo, atributo.name));
         tsT.setValor(atributo.name, atributo.name);
     }
 }
コード例 #4
0
        /*
         * Constructor de la clase padre
         * @ts tabla de simbolos padre
         * @user usuario que esta ejecutando las acciones
         * @baseD string por referencia de que base de datos estamos trabajando
         * @mensajes el output de la ejecucion
         */

        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            object res   = (condicion == null) ? null : condicion.ejecutar(ts, ambito, tsT);
            object condi = verificarCondicion(res, ambito.mensajes);

            if (condi != null)
            {
                TablaDeSimbolos nuevoAmbito = new TablaDeSimbolos();
                foreach (Simbolo s in ts)
                {
                    nuevoAmbito.AddLast(s);
                }
                foreach (InstruccionCQL i in cuerpo)
                {
                    object resultado = i.ejecutar(nuevoAmbito, ambito, tsT);
                    if (resultado == null)
                    {
                        return(null);
                    }
                }
                while ((Boolean)condi)
                {
                    nuevoAmbito = new TablaDeSimbolos();
                    foreach (Simbolo s in ts)
                    {
                        nuevoAmbito.AddLast(s);
                    }
                    //------------------------------------------------------------ INSTRUCCIONES DO WHILE ------------------------------------------
                    foreach (InstruccionCQL i in cuerpo)
                    {
                        object resultado = i.ejecutar(nuevoAmbito, ambito, tsT);
                        if (resultado == null)
                        {
                            return(null);
                        }
                        else if (resultado.GetType() == typeof(Retorno))
                        {
                            return((Retorno)resultado);
                        }
                        else if (i.GetType() == typeof(Continue) || resultado.GetType() == typeof(Continue))
                        {
                            break;
                        }
                    }


                    res   = (condicion == null) ? null : condicion.ejecutar(nuevoAmbito, ambito, tsT);
                    condi = verificarCondicion(res, ambito.mensajes);
                    if (condi == null)
                    {
                        return(null);
                    }
                }
                return("");
            }
            return(null);
        }
コード例 #5
0
        /*
         * Constructor de la clase padre
         * @ts tabla de simbolos padre
         * @user usuario que esta ejecutando las acciones
         * @baseD string por referencia de que base de datos estamos trabajando
         * @mensajes el output de la ejecucion
         */

        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje ms    = new Mensaje();
            object  res   = (condicion == null) ? null : condicion.ejecutar(ts, ambito, tsT);
            object  condi = verificarCondicion(res, ambito.mensajes);

            if (condi != null)
            {
                while ((Boolean)condi)
                {
                    TablaDeSimbolos nuevoAmbito = new TablaDeSimbolos();
                    foreach (Simbolo s in ts)
                    {
                        nuevoAmbito.AddLast(s);
                    }
                    //--------------------------------------------------- INSTRUCCIONES DENTRO DEL WHILE------------------------------------
                    foreach (InstruccionCQL i in cuerpo)
                    {
                        object resultado = i.ejecutar(nuevoAmbito, ambito, tsT);
                        if (resultado == null)
                        {
                            System.Diagnostics.Debug.WriteLine("TIPOWHILE: " + i.GetType());
                            return(null);
                        }
                        else if (resultado.GetType() == typeof(Retorno))
                        {
                            return((Retorno)resultado);
                        }
                        else if (i.GetType() == typeof(Continue) || resultado.GetType() == typeof(Continue))
                        {
                            break;
                        }
                    }


                    res   = (condicion == null) ? null : condicion.ejecutar(nuevoAmbito, ambito, tsT);
                    condi = verificarCondicion(res, ambito.mensajes);
                    if (condi == null)
                    {
                        return(null);
                    }
                }
                return("");
            }
            else
            {
                ambito.listadoExcepciones.AddLast(new Excepcion("exception", "La coindicion no puede ser null"));
                ambito.mensajes.AddLast(ms.error("La coindicion no puede ser null", l, c, "Semantico"));
            }
            return(null);
        }
コード例 #6
0
        /*
         * Constructor de la clase padre
         * @ts tabla de simbolos padre
         * @user usuario que esta ejecutando las acciones
         * @baseD string por referencia de que base de datos estamos trabajando
         * @mensajes el output de la ejecucion
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje ms             = new Mensaje();
            object  existeVariable = ts.getValor(id);

            if (existeVariable.Equals("none"))
            {
                TypeCursor typeCursor;
                if (select.GetType() == typeof(Expresion))
                {
                    object respuesta = (select == null) ? null : select.ejecutar(ts, ambito, tsT);
                    if (respuesta == null)
                    {
                        return(null);
                    }
                    if (respuesta.GetType() == typeof(TypeCursor))
                    {
                        typeCursor = (TypeCursor)respuesta;
                    }
                    else
                    {
                        ambito.mensajes.AddLast(ms.error("A un cursor solo se le puede asignar un tipo Select no se reconoce: " + respuesta, l, c, "Semantico"));
                        return(null);
                    }
                }
                else
                {
                    typeCursor = new TypeCursor(null, (Select)select);
                }
                ts.AddLast(new Simbolo("cursor", id));
                ts.setValor(id, typeCursor);
                return("");
            }
            else
            {
                ambito.mensajes.AddLast(ms.error("Ya existe la variable: " + id + " en este ambito", l, c, "Semantico"));
            }
            return(null);
        }
コード例 #7
0
        public object Ejecutar(TablaDeSimbolos ts)
        {
            TablaDeSimbolos tabla_local = new TablaDeSimbolos();

            tabla_local.addPadre(ts);
            if (variable.Asignacion)
            {
                Tipo      type  = ts.getType(variable.Id);
                Operacion val   = (Operacion)variable.Valor;
                object    valor = val.Ejecutar(ts);
                salida.AddRange(val.getSalida());
                if (valor != null)
                {
                    if (Program.casteos.comprobarCasteo(type, valor))
                    {
                        ts.setValor(variable.Id, valor);
                    }
                    else
                    {
                        salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No se puede convertir a" + ts.tipoAsignado(variable.Id)));
                    }
                }
            }
            else
            {
                Simbolo new_simbol = new Simbolo(Program.getTipo(variable.Tipo.ToLower()), variable.Id);
                new_simbol.Sub_tipo = Tipo.VARIABLE;
                Operacion valor = (Operacion)variable.Valor;
                try
                {
                    new_simbol.Valor = valor.Ejecutar(ts);
                    if (new_simbol.Valor == null)
                    {
                        new_simbol.Valor = variable.Valor;
                    }
                }
                catch (Exception)
                {
                    new_simbol.Valor = valor;
                }
                tabla_local.AddLast(new_simbol);
            }

            while ((bool)expresion.Ejecutar(tabla_local))
            {
                foreach (Instruccion item in instruccions)
                {
                    if (item.getType() == Tipo.BREAK)
                    {
                        return(null);
                    }
                    if (item.getType() == Tipo.USER_TYPES || item.getType() == Tipo.FUNCION || item.getType() == Tipo.METODO || item.getType() == Tipo.PROCEDURE)
                    {
                        salida.Add(Program.buildError(item.getLine(), item.getColumn(), "Semantico", "No puede venir instruccion del tipo: " + item.getType() + " en un ambito local."));
                    }
                    else
                    {
                        item.Ejecutar(tabla_local);

                        salida.AddRange(item.getSalida());
                        item.clearSalida();
                    }
                }
                actualizacion.Ejecutar(tabla_local);
            }
            return(null);
        }
コード例 #8
0
        /*
         * Constructor de la clase padre
         * @ts tabla de simbolos padre
         * @user usuario que esta ejecutando las acciones
         * @baseD string por referencia de que base de datos estamos trabajando
         * @mensajes el output de la ejecucion
         */

        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            TablaDeSimbolos nuevoAmbito = new TablaDeSimbolos();

            foreach (Simbolo s in ts)
            {
                nuevoAmbito.AddLast(s);
            }
            object inici = (inicializacion == null) ? null : ((InstruccionCQL)inicializacion).ejecutar(nuevoAmbito, ambito, tsT);

            if (inici != null)
            {
                System.Diagnostics.Debug.WriteLine("VALOR: " + inici);
                object res   = (condicion == null) ? null : condicion.ejecutar(nuevoAmbito, ambito, tsT);
                object condi = verificarCondicion(res, ambito.mensajes);
                if (condi != null)
                {
                    while ((Boolean)condi)
                    {
                        TablaDeSimbolos nuevoAmbito2 = new TablaDeSimbolos();
                        foreach (Simbolo s in nuevoAmbito)
                        {
                            nuevoAmbito2.AddLast(s);
                        }
                        //---------------------------------------------------- instrucciones del for -----------------------------------------------
                        foreach (InstruccionCQL i in cuerpo)
                        {
                            object resultado = i.ejecutar(nuevoAmbito2, ambito, tsT);
                            if (resultado == null)
                            {
                                return(null);
                            }
                            else if (resultado.GetType() == typeof(Retorno))
                            {
                                return((Retorno)resultado);
                            }
                            else if (i.GetType() == typeof(Continue) || resultado.GetType() == typeof(Continue))
                            {
                                break;
                            }
                        }

                        object actu = (actualizacion == null) ? null : actualizacion.ejecutar(nuevoAmbito, ambito, tsT);
                        if (actu == null)
                        {
                            return(null);
                        }

                        res   = (condicion == null) ? null : condicion.ejecutar(nuevoAmbito, ambito, tsT);
                        condi = verificarCondicion(res, ambito.mensajes);
                        if (condi == null)
                        {
                            return(null);
                        }
                    }
                    return("");
                }
            }



            return(null);
        }
コード例 #9
0
        /*
         * Metodo de la implementacion
         * @ts tabla de simbolos global
         * @user usuario que ejecuta la accion
         * @baseD base de datos donde estamos ejecutando todo
         * @mensajes linkedlist con la salida deseada
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje         ms        = new Mensaje();
            TablaDeSimbolos newAmbito = new TablaDeSimbolos();

            foreach (Simbolo s in ambito.tablaPadre)
            {
                newAmbito.AddLast(s);
            }

            if (tamanioTotalParametros() == valores.Count())
            {
                int index = 0;
                //-------------------------------------------- CREACION Y ASIGNACION DE PARAMETROS --------------------------------------------------------------
                for (int i = 0; i < parametros.Count(); i++)
                {
                    LinkedList <InstruccionCQL> parametro = parametros.ElementAt(i).lista;

                    for (int j = 0; j < parametro.Count(); j++)
                    {
                        Declaracion d = (Declaracion)parametro.ElementAt(j);
                        d.parametro = true;
                        object rd = d.ejecutar(newAmbito, ambito, tsT);
                        if (rd == null)
                        {
                            return(null);
                        }
                        Asignacion a = new Asignacion(d.id, l, c, valores.ElementAt(index), "ASIGNACION");
                        a.tPadre = ts;
                        object ra = a.ejecutar(newAmbito, ambito, tsT);
                        if (ra == null)
                        {
                            return(null);
                        }
                        index++;
                    }
                }
                //--------------------------------------------------- INSTRUCCIONES DEL PROCEDURE ----------------------------------------------
                foreach (InstruccionCQL ins in cuerpo)
                {
                    object r = ins.ejecutar(newAmbito, ambito, tsT);
                    if (r == null)
                    {
                        return(null);
                    }
                    else if (r.GetType() == typeof(Retorno))
                    {
                        object re = ((Retorno)r).valor;
                        if (re != null)
                        {
                            LinkedList <object> temp;
                            if (re.GetType() == typeof(LinkedList <object>))
                            {
                                temp = (LinkedList <object>)re;
                            }
                            else
                            {
                                temp = new LinkedList <object>();
                                temp.AddLast(re);
                            }
                            string idGenerado = idOut(temp);
                            if (idGenerado == null)
                            {
                                return(null);
                            }
                            if (idGenerado.Equals(identificadorRetornos))
                            {
                                return(temp);
                            }
                            else
                            {
                                ambito.listadoExcepciones.AddLast(new Excepcion("numberreturnsexception", "La cantidad de valores retornados no concuerda con el valor de parametros se esperaba: " + identificadorRetornos + " se obtuvo " + idGenerado));
                                ambito.mensajes.AddLast(ms.error("La cantidad de valores retornados no concuerda con el valor de parametros se esperaba: " + identificadorRetornos + " se obtuvo " + idGenerado, l, c, "Semantico"));
                                return(null);
                            }
                        }
                        return(null);
                    }
                }
                if (identificadorRetornos.Equals(""))
                {
                    return("");
                }
                else
                {
                    ambito.listadoExcepciones.AddLast(new Excepcion("numberreturnsexception", "Se necesita retornar valores de tipo: " + identificadorRetornos));
                    ambito.mensajes.AddLast(ms.error("Se necesita retornar valores de tipo: " + identificadorRetornos, l, c, "Semantico"));
                    return(null);
                }
            }
            else
            {
                ambito.mensajes.AddLast(ms.error("La cantidad de valores no concuerda con la cantidad de parametros", l, c, "Semantico"));
            }

            return(null);
        }
コード例 #10
0
        public object Ejecutar(TablaDeSimbolos ts)
        {
            if (!global)
            {
                foreach (Variable item in variables_asignar)
                {
                    if (!ts.existID_AA(item.Id.ToLower()))
                    {
                        Simbolo new_simbol = new Simbolo(real_type, item.Id);
                        new_simbol.Tipo_asignado = type;
                        string name = item.Valor.GetType().Name;
                        if (item.Instanciada)
                        {
                            if (real_type == Tipo.USER_TYPES)
                            {
                                if (name.Equals("Tipo_Objeto"))
                                {
                                    Tipo_Objeto        objext = (Tipo_Objeto)item.Valor;
                                    List <Tipo_Objeto> objeto = (List <Tipo_Objeto>)Program.sistema.buildObject(objext.Name.ToLower());
                                    new_simbol.Valor = objeto;
                                }
                                else
                                {
                                    List <Tipo_Collection> objeto = (List <Tipo_Collection>)item.Valor;
                                    new_simbol.Valor = Program.sistema.getValor(type.ToLower(), objeto, ts);
                                }
                            }
                            else if (real_type == Tipo.NUMERO || real_type == Tipo.ENTERO)
                            {
                                if (name.Equals("Variable"))
                                {
                                    Variable aux_var = (Variable)item.Valor;

                                    object valor = ts.getValorByAttr(aux_var.Id, aux_var.Atributos);
                                    new_simbol.Valor = valor;
                                }
                                else
                                {
                                    Operacion valor = (Operacion)item.Valor;
                                    try
                                    {
                                        new_simbol.Valor = valor.Ejecutar(ts);
                                        if (new_simbol.Valor == null)
                                        {
                                            new_simbol.Valor = item.Valor;
                                        }
                                    }
                                    catch (Exception)
                                    {
                                        new_simbol.Valor = valor;
                                    }
                                }
                            }
                            else if (real_type == Tipo.MAP)
                            {
                                Map objeto = (Map)item.Valor;
                                new_simbol.Valor = objeto;
                            }
                            else if (real_type == Tipo.LIST)
                            {
                                Lista objeto = (Lista)item.Valor;
                                new_simbol.Valor = objeto;
                            }
                        }
                        else
                        {
                            if (real_type == Tipo.NUMERO)
                            {
                                new_simbol.Valor = 0;
                            }
                            if (real_type == Tipo.USER_TYPES || real_type == Tipo.MAP || real_type == Tipo.LIST)
                            {
                                new_simbol.Valor = null;
                            }
                        }
                        ts.AddLast(new_simbol);
                    }
                    else
                    {
                        salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", item.Id + " ObjectAlreadyExists3"));
                    }
                }
            }
            return(null);
        }
コード例 #11
0
        /*
         * Metodo de la implementacion
         * @ts tabla de simbolos global
         * @user usuario que ejecuta la accion
         * @baseD base de datos donde estamos ejecutando todo
         * @mensajes linkedlist con la salida deseada
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje         ms        = new Mensaje();
            TablaDeSimbolos newAmbito = new TablaDeSimbolos();

            foreach (Simbolo s in ambito.tablaPadre)
            {
                newAmbito.AddLast(s);
            }

            if (parametros.Count() == valores.Count())
            {
                //-------------------------------------- CREACION Y ASIGNACION DE PARAMETROS -----------------------------------------------------
                for (int i = 0; i < parametros.Count(); i++)
                {
                    Declaracion d = (Declaracion)parametros.ElementAt(i);
                    d.parametro = true;
                    object rd = d.ejecutar(newAmbito, ambito, tsT);
                    if (rd == null)
                    {
                        return(null);
                    }
                    Asignacion a = new Asignacion(d.id, l, c, valores.ElementAt(i), "ASIGNACION");
                    a.tPadre = ts;
                    object ra = a.ejecutar(newAmbito, ambito, tsT);
                    if (ra == null)
                    {
                        return(null);
                    }
                }
                //---------------------------------------- INSTRUCCIONES DE LA FUNCION -----------------------------------------------------------
                foreach (InstruccionCQL ins in cuerpo)
                {
                    object r = ins.ejecutar(newAmbito, ambito, tsT);
                    if (r == null)
                    {
                        ambito.mensajes.AddLast(ms.error("Problema en la Funcion: " + id, l, c, "Semantico"));
                        return(null);
                    }
                    else if (r.GetType() == typeof(Retorno))
                    {
                        object re = ((Retorno)r).valor;
                        if (re != null)
                        {
                            if (re.GetType() == typeof(int) && tipo.Equals("int"))
                            {
                                return((int)re);
                            }
                            else if (re.GetType() == typeof(string) && tipo.Equals("string"))
                            {
                                return((String)re);
                            }
                            else if (re.GetType() == typeof(Boolean) && tipo.Equals("boolean"))
                            {
                                return((Boolean)re);
                            }
                            else if (re.GetType() == typeof(double) && tipo.Equals("double"))
                            {
                                return((Double)re);
                            }
                            else if (re.GetType() == typeof(DateTime) && tipo.Equals("date"))
                            {
                                return((DateTime)re);
                            }
                            else if (re.GetType() == typeof(TimeSpan) && tipo.Equals("time"))
                            {
                                return((TimeSpan)re);
                            }
                            else if (re.GetType() == typeof(Map) && tipo.Equals("map"))
                            {
                                return((Map)re);
                            }
                            else if (re.GetType() == typeof(List) && tipo.Equals("list"))
                            {
                                return((List)re);
                            }
                            else if (re.GetType() == typeof(Set) && tipo.Equals("set"))
                            {
                                return((Set)re);
                            }
                            else if (re.GetType() == typeof(TypeCursor) && tipo.Equals("cursor"))
                            {
                                return((TypeCursor)re);
                            }
                            else if (re.GetType() == typeof(InstanciaUserType))
                            {
                                InstanciaUserType temp = (InstanciaUserType)re;
                                if (temp.tipo.Equals(tipo))
                                {
                                    return(temp);
                                }
                                else
                                {
                                    ambito.mensajes.AddLast(ms.error("No coincide el tipo de USERTYPE", l, c, "Semantico"));
                                }
                            }
                            else
                            {
                                ambito.mensajes.AddLast(ms.error("No coincide el tipo: " + tipo + " con el valor: " + re, l, c, "Semantico"));
                            }
                            return(null);
                        }
                    }
                }
                ambito.mensajes.AddLast(ms.error("La funcion no posee ningun return", l, c, "Semantico"));
                return(null);
            }
            else
            {
                ambito.mensajes.AddLast(ms.error("No coinciden el numero de parametros con el numero de valores", l, c, "Semantico"));
            }

            return(null);
        }
コード例 #12
0
        /*
         * Metodo de la implementacion
         * @ts tabla de simbolos global
         * @user usuario que ejecuta la accion
         * @baseD base de datos donde estamos ejecutando todo
         * @mensajes linkedlist con la salida deseada
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje ms  = new Mensaje();
            object  res = ts.getValor(id);

            if (!res.Equals("none"))
            {
                if (res.GetType() == typeof(TypeCursor))
                {
                    TypeCursor tabla = (TypeCursor)res;
                    if (tabla.tabla != null)
                    {
                        generarIdentificador(tabla.tabla);
                        if (tabla.tabla.columnas.Count() == parametros.Count())
                        {
                            string identificadorParametros = generarIdentificadorDeclaracion();
                            if (identificadorParametros.Equals(identificador))
                            {
                                foreach (Data data in tabla.tabla.datos)
                                {
                                    TablaDeSimbolos newAmbito = new TablaDeSimbolos();
                                    foreach (Simbolo s in ambito.tablaPadre)
                                    {
                                        newAmbito.AddLast(s);
                                    }
                                    //-------------------------------------- ASIGNARLE A LOS PARAMETROS LOS VALORES DE LA CONSULTA ----------------------------
                                    for (int i = 0; i < parametros.Count(); i++)
                                    {
                                        Declaracion d = (Declaracion)parametros.ElementAt(i);
                                        d.parametro = true;
                                        object rd = d.ejecutar(newAmbito, ambito, tsT);
                                        if (rd == null)
                                        {
                                            return(null);
                                        }
                                        Atributo atributo = data.valores.ElementAt(i);
                                        newAmbito.setValor(d.id, atributo.valor);
                                    }
                                    //---------------------------------------- EJECUTAR INSTRUCCIONES DENTRO DEL FOREACH -----------------------------------------
                                    foreach (InstruccionCQL i in cuerpo)
                                    {
                                        object resultado = i.ejecutar(newAmbito, ambito, tsT);
                                        if (resultado == null)
                                        {
                                            return(null);
                                        }
                                        else if (resultado.GetType() == typeof(Retorno))
                                        {
                                            return((Retorno)resultado);
                                        }
                                        else if (i.GetType() == typeof(Continue) || resultado.GetType() == typeof(Continue))
                                        {
                                            break;
                                        }
                                    }
                                }
                                return("");
                            }
                            else
                            {
                                ambito.mensajes.AddLast(ms.error("No coinciden el tipo de parametros con el tipo de columnas", l, c, "Semantico"));
                            }
                        }
                        else
                        {
                            ambito.mensajes.AddLast(ms.error("No coincide la cantidad de parametros con la cantidad de columnas", l, c, "Semantico"));
                        }
                    }
                    else
                    {
                        ambito.mensajes.AddLast(ms.error("El cursor: " + id + " no ha sido abierto", l, c, "Semantico"));
                    }
                }
                else
                {
                    ambito.mensajes.AddLast(ms.error("La variable tiene que ser de tipo Cursor  no se reconoce: " + res, l, c, "Semantico"));
                }
            }
            else
            {
                ambito.mensajes.AddLast(ms.error("La variable : " + id + " no existe en este ambito", l, c, "Semantico"));
            }
            return(null);
        }
コード例 #13
0
        /*
         * METODO DE LA CLASE PADRE QUE SE IMPLEMENTA
         * @param {ts} tabla de simbolos del padre
         * @param {ambito} ambito de atributos a manejar
         * @param {tsT} tabla de simbolos(CQL) del padre
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje         ms        = new Mensaje();
            TablaDeSimbolos newAmbito = new TablaDeSimbolos();
            Boolean         flagCatch = false;

            foreach (Simbolo s in ts)
            {
                newAmbito.AddLast(s);
            }

            foreach (InstruccionCQL ins in cuerpoTry)
            {
                object res = ins.ejecutar(newAmbito, ambito, tsT);
                if (res == null)
                {
                    System.Diagnostics.Debug.WriteLine("TIPO: " + ins.GetType());
                    flagCatch = true;
                    break;
                }
                else if (ins.GetType() == typeof(Return))
                {
                    return((Retorno)res);
                }
            }

            if (flagCatch)
            {
                if (ambito.listadoExcepciones.Count() > 0)
                {
                    Excepcion e = (Excepcion)ambito.listadoExcepciones.Last.Value;
                    if (e.tipo.Equals(tipo) || e.tipo.Equals("exception"))
                    {
                        ambito.listadoExcepciones.RemoveLast();
                        ambito.mensajes.RemoveLast();
                        newAmbito = new TablaDeSimbolos();
                        foreach (Simbolo s in ts)
                        {
                            newAmbito.AddLast(s);
                        }
                        newAmbito.AddLast(new Simbolo("exception", id));
                        newAmbito.setValor(id, e);
                        foreach (InstruccionCQL ins in cuerpoCatch)
                        {
                            object res = ins.ejecutar(newAmbito, ambito, tsT);
                            if (res == null)
                            {
                                System.Diagnostics.Debug.WriteLine("TIPO2: " + ins.GetType());
                                return(null);
                            }
                            else if (ins.GetType() == typeof(Return))
                            {
                                return((Retorno)res);
                            }
                        }
                        return("");
                    }
                    else
                    {
                        ambito.mensajes.AddLast(ms.error("No coinciden el tipo de Excepcion en el catch con la Excepcion lanzada: " + tipo + " con: " + e.tipo, l, c, "Semantico"));
                    }
                }
            }
            else
            {
                return("");
            }

            return(null);
        }
コード例 #14
0
        /*
         * Constructor de la clase padre
         * @ts tabla de simbolos padre
         * @user usuario que esta ejecutando las acciones
         * @baseD string por referencia de que base de datos estamos trabajando
         * @mensajes el output de la ejecucion
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            flagCondicion = false;
            object a = (condicion == null) ? null : condicion.ejecutar(ts, ambito, tsT);

            Mensaje men = new Mensaje();

            //----------------------------------------------------------- ELSE -----------------------------------------------------------
            if (condicion == null)
            {
                TablaDeSimbolos ambitoLocal = new TablaDeSimbolos();
                foreach (Simbolo s in ts)
                {
                    ambitoLocal.AddLast(s);
                }
                TablaDeSimbolos tablaTemp = new TablaDeSimbolos();
                foreach (Simbolo s in tsT)
                {
                    tablaTemp.AddLast(s);
                }
                foreach (InstruccionCQL i in cuerpo)
                {
                    object r = i.ejecutar(ambitoLocal, ambito, tablaTemp);
                    if (r == null)
                    {
                        System.Diagnostics.Debug.WriteLine("ACCION: " + i.GetType());
                        return(r);
                    }
                    else if (r.GetType() == typeof(Retorno))
                    {
                        return(r);
                    }
                }
                return("");
            }
            //--------------------------------------------------------------------------------- IF ELSE IF
            else
            {
                if (a != null)
                {
                    if (a.GetType() == typeof(Boolean))
                    {
                        flagCondicion = (Boolean)a;
                        if (flagCondicion)
                        {
                            TablaDeSimbolos ambitoLocal = new TablaDeSimbolos();
                            foreach (Simbolo s in ts)
                            {
                                ambitoLocal.AddLast(s);
                            }
                            TablaDeSimbolos tablaTemp = new TablaDeSimbolos();
                            foreach (Simbolo s in tsT)
                            {
                                tablaTemp.AddLast(s);
                            }
                            //------------------------------------------------- INSTRUCCIONES DEL IF -----------------------------------------------
                            foreach (InstruccionCQL i in cuerpo)
                            {
                                object r = i.ejecutar(ambitoLocal, ambito, tablaTemp);
                                if (r == null)
                                {
                                    return(r);
                                }
                                else if (r.GetType() == typeof(Retorno))
                                {
                                    return((Retorno)r);
                                }
                                else if (i.GetType() == typeof(Continue))
                                {
                                    return(i);
                                }
                            }
                        }
                        return("");
                    }
                    else
                    {
                        ambito.mensajes.AddLast(men.error("La condicion tiene que ser de tipo boolean no se reconoce: " + a.ToString(), l, c, "Semantico"));
                    }
                }
                else
                {
                    ambito.mensajes.AddLast(men.error("No se acepta un null como condicion", l, c, "Semantico"));
                }
            }


            return(null);
        }
コード例 #15
0
        /*
         * Metodo de la implementacion
         * @ts tabla de simbolos global
         * @user usuario que ejecuta la accion
         * @baseD base de datos donde estamos ejecutando todo
         * @mensajes linkedlist con la salida deseada
         */
        public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT)
        {
            Mensaje             mensa    = new Mensaje();
            object              a        = (valor == null) ? null : valor.ejecutar(ts, ambito, tsT);
            LinkedList <string> mensajes = ambito.mensajes;
            object              res      = ts.getValor(id);
            string              baseD    = ambito.baseD;
            string              existe   = (res == null) ? "si" : res.ToString();

            if (parametro)
            {
                ts.AddLast(new Simbolo(tipo, id));
                if (tipo.Equals("list"))
                {
                    ts.setValor(id, new List("none", new LinkedList <object>()));
                }
                else if (tipo.Equals("set"))
                {
                    ts.setValor(id, new Set("none", new LinkedList <object>()));
                }
                else if (tipo.Equals("map"))
                {
                    ts.setValor(id, new Map("none", new LinkedList <KeyValue>()));
                }
                else if (tipo.Equals("string") || tipo.Equals("int") || tipo.Equals("double") || tipo.Equals("date") || tipo.Equals("time") || tipo.Equals("boolean") || tipo.Equals("cursor"))
                {
                }
                else
                {
                    ts.setValor(id, new InstanciaUserType("none", new LinkedList <Atributo>()));
                }

                return("");
            }
            else if (existe.Equals("none"))
            {
                if (valor == null)
                {
                    if (tipo.Equals("int"))
                    {
                        ts.AddLast(new Simbolo(tipo, id));
                        ts.setValor(id, 0);
                    }
                    else if (tipo.Equals("double"))
                    {
                        ts.AddLast(new Simbolo(tipo, id));
                        ts.setValor(id, 0.0);
                    }
                    else if (tipo.Equals("boolean"))
                    {
                        ts.AddLast(new Simbolo(tipo, id));
                        ts.setValor(id, false);
                    }
                    else if (tipo.Equals("string") || tipo.Equals("date") || tipo.Equals("time"))
                    {
                        ts.AddLast(new Simbolo(tipo, id));
                        ts.setValor(id, null);
                        return("");
                    }
                    else if (tipo.Equals("map"))
                    {
                        mensajes.AddLast(mensa.error("El tipo MAP necesita ser instanciado", l, c, "Semantico"));
                        return(null);
                    }
                    else if (tipo.Equals("list"))
                    {
                        mensajes.AddLast(mensa.error("El tipo LIST necesita ser instanciado", l, c, "Semantico"));
                        return(null);
                    }
                    else if (tipo.Equals("set"))
                    {
                        mensajes.AddLast(mensa.error("El tipo SET necesita ser instanciado", l, c, "Semantico"));
                        return(null);
                    }
                    else if (tipo.Equals("cursor"))
                    {
                        mensajes.AddLast(mensa.error("El tipo CURSOR necesita ser instanciado", l, c, "Semantico"));
                        return(null);
                    }
                    else
                    {
                        BaseDeDatos bd = TablaBaseDeDatos.getBase(baseD);
                        if (bd != null)
                        {
                            if (TablaBaseDeDatos.getUserType(tipo.ToLower(), bd))
                            {
                                ts.AddLast(new Simbolo(tipo, id));
                                ts.setValor(id, new InstanciaUserType(tipo, null));
                            }
                            else
                            {
                                mensajes.AddLast(mensa.error("El tipo " + tipo + " no es un userType en esta base de datos: " + baseD, l, c, "Semantico"));
                                return(null);
                            }
                        }
                        return("");
                    }
                }
                else
                {
                    if (a != null)
                    {
                        if (tipo.Equals("string") && a.GetType() == typeof(string))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (string)a);
                        }
                        else if (tipo.Equals("int") && a.GetType() == typeof(int))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (int)a);
                        }
                        else if (tipo.Equals("int") && a.GetType() == typeof(Double))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, Convert.ToInt32((Double)a));
                        }
                        else if (tipo.Equals("double") && a.GetType() == typeof(Double))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (Double)a);
                        }
                        else if (tipo.Equals("double") && a.GetType() == typeof(int))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, Convert.ToDouble((int)a));
                        }
                        else if (tipo.Equals("boolean") && a.GetType() == typeof(Boolean))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (Boolean)a);
                        }
                        else if (tipo.Equals("date") && a.GetType() == typeof(DateTime))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (DateTime)a);
                        }
                        else if (tipo.Equals("time") && a.GetType() == typeof(TimeSpan))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (TimeSpan)a);
                        }
                        else if (tipo.Equals("map") && a.GetType() == typeof(Map))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (Map)a);
                        }
                        else if (tipo.Equals("list") && a.GetType() == typeof(List))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (List)a);
                        }
                        else if (tipo.Equals("set") && a.GetType() == typeof(Set))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            Set    temp = (Set)a;
                            object resp = temp.buscarRepetidos(mensajes, l, c);
                            if (resp == null)
                            {
                                return(null);
                            }
                            temp.order();
                            ts.setValor(id, temp);
                        }
                        else if (tipo.Equals("cursor") && a.GetType() == typeof(TypeCursor))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, (TypeCursor)a);
                        }
                        else if (a.GetType() == typeof(InstanciaUserType))
                        {
                            InstanciaUserType ins = (InstanciaUserType)a;
                            if (tipo.Equals(ins.tipo.ToLower()))
                            {
                                ts.AddLast(new Simbolo(tipo, id));
                                ts.setValor(id, ins);
                            }
                            else
                            {
                                Mensaje me = new Mensaje();
                                mensajes.AddLast(me.error("La variable " + id + " es de Tipo: " + tipo + " no se puede instanciar al tipo: " + ins.tipo, l, c, "Semantico"));
                            }
                        }
                        else
                        {
                            Mensaje me = new Mensaje();
                            mensajes.AddLast(me.error("La variable " + id + " no se le puede asignar este valor " + a.ToString(), l, c, "Semantico"));
                            return(null);
                        }
                        return("");
                    }
                    else
                    {
                        if (tipo.Equals("string") || tipo.Equals("date") || tipo.Equals("time"))
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, null);
                        }
                        else if (tipo.Equals("int") || tipo.Equals("double") || tipo.Equals("map") || tipo.Equals("set") || tipo.Equals("list") || tipo.Equals("cursor") || tipo.Equals("boolean"))
                        {
                            mensajes.AddLast(mensa.error("No se le puede asignar un valor null al tipo: " + tipo, l, c, "Semantico"));
                            return(null);
                        }
                        else
                        {
                            ts.AddLast(new Simbolo(tipo, id));
                            ts.setValor(id, new InstanciaUserType(tipo, null));
                        }
                        return("");
                    }
                }
            }
            else
            {
                Mensaje me = new Mensaje();
                ambito.listadoExcepciones.AddLast(new Excepcion("objectalreadyexists", "La variable " + id + " ya existe en este ambito"));
                mensajes.AddLast(me.error("La variable " + id + " ya existe en este ambito", l, c, "Semantico"));
            }

            return(null);
        }