/*
         * 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 = ts.getValor(id);
            Mensaje ms  = new Mensaje();

            if (!res.Equals("none"))
            {
                if (res.GetType() == typeof(TypeCursor))
                {
                    if (operacion.Equals("open"))
                    {
                        object tabla = ((TypeCursor)res).consulta.ejecutar(ts, ambito, tsT);
                        if (tabla != null)
                        {
                            ambito.mensajes.RemoveLast();
                            if (tabla.GetType() == typeof(TablaSelect))
                            {
                                ((TypeCursor)res).tabla = (TablaSelect)tabla;
                            }
                        }
                    }
                    else
                    {
                        ((TypeCursor)res).tabla = null;
                    }

                    return("");
                }
                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("No se encuentra la variable: " + id + " en este ambito", l, c, "Semantico"));
            }
            return(null);
        }
        /*
         * 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);
        }
Beispiel #3
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);
        }
Beispiel #4
0
        public object Ejecutar(TablaDeSimbolos ts)
        {
            bool   is_ok   = true;
            string salida2 = "";

            foreach (Valor item in valores)
            {
                if (item.Sub_tipo == Tipo.VARIABLE)
                {
                    if (ts.existID(item.Val.ToString()))
                    {
                        try
                        {
                            salida2 += ((Operacion)ts.getValor(item.Val.ToString())).Ejecutar(ts);
                        }
                        catch (Exception)
                        {
                            salida2 += ts.getValor(item.Val.ToString());
                        }
                    }
                    else
                    {
                        salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "Variable " + item.Val + " no se ha declarado."));
                        is_ok = false;
                    }
                    if (!is_ok)
                    {
                        break;
                    }
                }
                else if (item.Sub_tipo == Tipo.VARIABLE_ATRIBUTOS)
                {
                    Variable aux_var = (Variable)item.Val;
                    if (ts.existID(aux_var.Id))
                    {
                        object result = ts.getValorByAttr(aux_var.Id, aux_var.Atributos);
                        if (result != null)
                        {
                            salida2 += result.ToString();
                        }
                        else
                        {
                            salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "NO EXISTE ATRIBUTO"));
                        }
                    }
                    else
                    {
                        salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "Variable " + item.Val + " no se ha declarado."));
                        is_ok = false;
                    }
                    if (!is_ok)
                    {
                        break;
                    }
                }
                else if (item.Sub_tipo == Tipo.VARIABLE_METODOS)
                {
                    Variable aux_var = (Variable)item.Val;
                    if (ts.existID(aux_var.Id))
                    {
                        Tipo   tipo = ts.getType(aux_var.Id);
                        object aux  = Program.getValor(tipo, aux_var.Id, aux_var.Valor, ts);
                        if (aux != null)
                        {
                            salida2 += aux;
                        }
                        else
                        {
                            salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", " IndexOutException."));
                            is_ok = false;
                        }
                    }
                    else
                    {
                        salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "Variable " + item.Val + " no se ha declarado."));
                        is_ok = false;
                    }
                    if (!is_ok)
                    {
                        break;
                    }
                }
                else
                {
                    salida2 += item.Val.ToString();
                }
            }
            if (is_ok)
            {
                salida.Add(Program.buildMessage(salida2));
            }
            return(null);
        }
Beispiel #5
0
        public static object getValor(Tipo tipo, string id, object valor, TablaDeSimbolos ts)
        {
            switch (tipo)
            {
            case Tipo.MAP:
                Map             map_actual = (Map)ts.getValor(id);
                Variable_Metodo aux        = (Variable_Metodo)valor;
                string          clave;
                if (aux.Metodo.ToLower().Equals("get"))
                {
                    clave = aux.Clave.Ejecutar(ts).ToString();

                    if (map_actual.containsKey(clave))
                    {
                        Tipo_Collection val = (Tipo_Collection)map_actual.Get(clave);

                        if (val.Real_type == Tipo.OPERACION)
                        {
                            Operacion op = (Operacion)val.Valor;
                            return(op.Ejecutar(ts));
                        }
                    }
                }
                else if (aux.Metodo.ToLower().Equals("insert"))
                {
                    clave = aux.Clave.Ejecutar(ts).ToString();
                    bool salida = map_actual.insert(clave, aux.Valor);
                    ts.setValor(id, map_actual.Mapita);
                    return(salida);
                }
                else if (aux.Metodo.ToLower().Equals("set"))
                {
                    clave = aux.Clave.Ejecutar(ts).ToString();
                    bool salida = map_actual.Set(clave, aux.Valor);
                    ts.setValor(id, map_actual.Mapita);
                    return(salida);
                }
                else if (aux.Metodo.ToLower().Equals("remove"))
                {
                    clave = aux.Clave.Ejecutar(ts).ToString();
                    bool salida = map_actual.Remove(clave);
                    ts.setValor(id, map_actual.Mapita);
                    return(salida);
                }
                else if (aux.Metodo.ToLower().Equals("clear"))
                {
                    map_actual.clear();
                    ts.setValor(id, map_actual.Mapita);
                    return(true);
                }
                else if (aux.Metodo.ToLower().Equals("size"))
                {
                    return(Convert.ToDouble(map_actual.Size()));
                }
                else if (aux.Metodo.ToLower().Equals("contains"))
                {
                    clave = aux.Clave.Ejecutar(ts).ToString();
                    return(map_actual.containsKey(clave));
                }
                break;

            case Tipo.LIST:
                Lista lista_actual = (Lista)ts.getValor(id);
                aux = (Variable_Metodo)valor;
                if (aux.Metodo.ToLower().Equals("get"))
                {
                    int clave2 = Convert.ToInt32(aux.Clave.Ejecutar(ts).ToString());


                    Tipo_Collection val = (Tipo_Collection)lista_actual.Get(clave2);
                    if (val != null)
                    {
                        if (val.Real_type == Tipo.OPERACION)
                        {
                            Operacion op = (Operacion)val.Valor;
                            return(op.Ejecutar(ts));
                        }
                    }
                }
                else if (aux.Metodo.ToLower().Equals("insert"))
                {
                    lista_actual.Insert(aux.Valor);
                    ts.setValor(id, lista_actual.Lista_valores);
                    return(true);
                }
                else if (aux.Metodo.ToLower().Equals("set"))
                {
                    int  clave2 = Convert.ToInt32(aux.Clave.Ejecutar(ts).ToString());
                    bool salida = lista_actual.Set(clave2, aux.Valor);
                    ts.setValor(id, lista_actual.Lista_valores);
                    return(salida);
                }
                else if (aux.Metodo.ToLower().Equals("remove"))
                {
                    int  clave2 = Convert.ToInt32(aux.Clave.Ejecutar(ts).ToString());
                    bool salida = lista_actual.Remove(clave2);
                    ts.setValor(id, lista_actual.Lista_valores);
                    return(salida);
                }
                else if (aux.Metodo.ToLower().Equals("clear"))
                {
                    lista_actual.Clear();
                    ts.setValor(id, lista_actual.Lista_valores);
                }
                else if (aux.Metodo.ToLower().Equals("size"))
                {
                    return(Convert.ToDouble(lista_actual.Size()));
                }
                else if (aux.Metodo.ToLower().Equals("contains"))
                {
                    return(lista_actual.Contains(aux.Valor));
                }
                break;

            default:
                return(null);
            }
            return(null);
        }
Beispiel #6
0
 public object Ejecutar(TablaDeSimbolos ts)
 {
     try {
         if (Tipo == Tipo.DIVISION)
         {
             return((Double)operadorIzq.Ejecutar(ts) / (Double)operadorDer.Ejecutar(ts));
         }
         else if (Tipo == Tipo.MODULAR)
         {
             return((Double)operadorIzq.Ejecutar(ts) % (Double)operadorDer.Ejecutar(ts));
         }
         else if (Tipo == Tipo.POTENCIA)
         {
             return((Double)Math.Pow((Double)operadorIzq.Ejecutar(ts), (Double)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.MULTIPLICACION)
         {
             return((Double)operadorIzq.Ejecutar(ts) * (Double)operadorDer.Ejecutar(ts));
         }
         else if (Tipo == Tipo.RESTA)
         {
             return((Double)operadorIzq.Ejecutar(ts) - (Double)operadorDer.Ejecutar(ts));
         }
         else if (Tipo == Tipo.SUMA)
         {
             return((Double)operadorIzq.Ejecutar(ts) + (Double)operadorDer.Ejecutar(ts));
         }
         else if (Tipo == Tipo.NEGATIVO)
         {
             return((Double)operadorIzq.Ejecutar(ts) * -1);
         }
         else if (Tipo == Tipo.NUMERO)
         {
             return(Double.Parse(valor.ToString()));
         }
         else if (Tipo == Tipo.VARIABLE)
         {
             return(ts.getValor(valor.ToString()));
         }
         else if (Tipo == Tipo.CADENA)
         {
             return(valor.ToString());
         }
         else if (Tipo == Tipo.INCREMENTO)
         {
             Double aux;
             if (ts.existID(valor.ToString()))
             {
                 if (ts.getType(valor.ToString()) == Tipo.ENTERO || ts.getType(valor.ToString()) == Tipo.DECIMAL)
                 {
                     aux = (Double)ts.getValor(valor.ToString());
                     ts.setValor(valor.ToString(), aux + 1);
                     return(aux);
                 }
                 else
                 {
                     salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No es un numero."));
                 }
             }
             else
             {
                 salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", valor.ToString() + " No existe en el ambito actual"));
             }
             return(null);
         }
         else if (Tipo == Tipo.DECREMENTO)
         {
             Double aux;
             if (ts.existID(valor.ToString()))
             {
                 if (ts.getType(valor.ToString()) == Tipo.ENTERO || ts.getType(valor.ToString()) == Tipo.DECIMAL)
                 {
                     aux = (Double)ts.getValor(valor.ToString());
                     ts.setValor(valor.ToString(), aux - 1);
                     return(aux);
                 }
                 else
                 {
                     salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No es un numero."));
                 }
             }
             else
             {
                 salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", valor.ToString() + " No existe en el ambito actual"));
             }
             return(null);
         }
         else if (Tipo == Tipo.MASIGUAL)
         {
             //(Double)operadorIzq.Ejecutar(ts);
             if (ts.existID(valor.ToString()))
             {
                 if (ts.getType(valor.ToString()) == Tipo.ENTERO || ts.getType(valor.ToString()) == Tipo.DECIMAL)
                 {
                     Double aux = (Double)ts.getValor(valor.ToString()) + (Double)operadorIzq.Ejecutar(ts);
                     ts.setValor(valor.ToString(), aux);
                 }
                 else
                 {
                     salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No es un numero."));
                 }
             }
             else
             {
                 salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", valor.ToString() + " No existe en el ambito actual"));
             }
             return(null);
         }
         else if (Tipo == Tipo.MENOSIGUAL)
         {
             //(Double)operadorIzq.Ejecutar(ts);
             if (ts.existID(valor.ToString()))
             {
                 if (ts.getType(valor.ToString()) == Tipo.ENTERO || ts.getType(valor.ToString()) == Tipo.DECIMAL)
                 {
                     Double aux = (Double)ts.getValor(valor.ToString()) - (Double)operadorIzq.Ejecutar(ts);
                     ts.setValor(valor.ToString(), aux);
                 }
                 else
                 {
                     salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No es un numero."));
                 }
             }
             else
             {
                 salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", valor.ToString() + " No existe en el ambito actual"));
             }
             return(null);
         }
         else if (Tipo == Tipo.MULIGUAL)
         {
             //(Double)operadorIzq.Ejecutar(ts);
             if (ts.existID(valor.ToString()))
             {
                 if (ts.getType(valor.ToString()) == Tipo.ENTERO || ts.getType(valor.ToString()) == Tipo.DECIMAL)
                 {
                     Double aux = (Double)ts.getValor(valor.ToString()) * (Double)operadorIzq.Ejecutar(ts);
                     ts.setValor(valor.ToString(), aux);
                 }
                 else
                 {
                     salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No es un numero."));
                 }
             }
             else
             {
                 salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", valor.ToString() + " No existe en el ambito actual"));
             }
             return(null);
         }
         else if (Tipo == Tipo.DIVIGUAL)
         {
             //(Double)operadorIzq.Ejecutar(ts);
             if (ts.existID(valor.ToString()))
             {
                 if (ts.getType(valor.ToString()) == Tipo.ENTERO || ts.getType(valor.ToString()) == Tipo.DECIMAL)
                 {
                     Double aux = (Double)ts.getValor(valor.ToString()) / (Double)operadorIzq.Ejecutar(ts);
                     ts.setValor(valor.ToString(), aux);
                 }
                 else
                 {
                     salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No es un numero."));
                 }
             }
             else
             {
                 salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", valor.ToString() + " No existe en el ambito actual"));
             }
             return(null);
         }
         else if (Tipo == Tipo.MAYOR_QUE)
         {
             return(((Double)operadorIzq.Ejecutar(ts)) > ((Double)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.MAYOR_IGUAL)
         {
             return(((Double)operadorIzq.Ejecutar(ts)) >= ((Double)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.MENOR_QUE)
         {
             return(((Double)operadorIzq.Ejecutar(ts)) < ((Double)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.MENOR_IGUAL)
         {
             return(((Double)operadorIzq.Ejecutar(ts)) <= ((Double)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.IGUAL)
         {
             return(((Double)operadorIzq.Ejecutar(ts)) == ((Double)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.DIFERENTE)
         {
             return(((Double)operadorIzq.Ejecutar(ts)) != ((Double)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.AND)
         {
             return(((bool)operadorIzq.Ejecutar(ts)) && ((bool)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.OR)
         {
             return(((bool)operadorIzq.Ejecutar(ts)) || ((bool)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.XOR)
         {
             return(((bool)operadorIzq.Ejecutar(ts)) ^ ((bool)operadorDer.Ejecutar(ts)));
         }
         else if (Tipo == Tipo.NOT)
         {
             return(!(bool)operadorIzq.Ejecutar(ts));
         }
         else if (Tipo == Tipo.CONCATENACION)
         {
             return(operadorIzq.Ejecutar(ts).ToString() + operadorDer.Ejecutar(ts).ToString());
         }
         else if (Tipo == Tipo.BOOLEANO)
         {
             return(Convert.ToBoolean(valor));
         }
         else if (Tipo == Tipo.VARIABLE_METODOS)
         {
             Variable var  = (Variable)valor;
             Tipo     tipo = ts.getType(var.Id);
             object   aux  = Program.getValor(tipo, var.Id, var.Valor, ts);
             if (aux != null)
             {
                 return(aux);
             }
             else
             {
                 salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", " IndexOutException."));
                 return(null);
             }
         }
         else
         {
             return(null);
         }
     } catch {
         salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", " No se puede operar el tipo."));
         return(null);
     }
 }
        /*
         * METODO QUE VERIFICA LOS VALORES A GUARDAR
         * @param {op1} valor a guardar
         * @param {tipo} tipo de variable
         * @param {a} expresion original
         * @param {mensajes} output
         * @param {ts} tabla de variables
         */
        private object checkValues(object op1, string tipo, LinkedList <string> mensajes, TablaDeSimbolos ts, string id)
        {
            Mensaje mensa = new Mensaje();


            if (op1 != null)
            {
                if (op1.GetType() == typeof(string) && tipo.Equals("string"))
                {
                    ts.setValor(id, (string)op1);
                }
                else if (op1.GetType() == typeof(int) && tipo.Equals("int"))
                {
                    ts.setValor(id, (int)op1);
                }
                else if (op1.GetType() == typeof(int) && tipo.Equals("double"))
                {
                    ts.setValor(id, Convert.ToInt32((Double)op1));
                }
                else if (op1.GetType() == typeof(Double) && tipo.Equals("double"))
                {
                    ts.setValor(id, (Double)op1);
                }
                else if (op1.GetType() == typeof(Double) && tipo.Equals("int"))
                {
                    ts.setValor(id, Convert.ToDouble((int)op1));
                }
                else if (op1.GetType() == typeof(Boolean) && tipo.Equals("boolean"))
                {
                    ts.setValor(id, (Boolean)op1);
                }
                else if (op1.GetType() == typeof(DateTime) && tipo.Equals("date"))
                {
                    ts.setValor(id, (DateTime)op1);
                }
                else if (op1.GetType() == typeof(TimeSpan) && tipo.Equals("time"))
                {
                    ts.setValor(id, (TimeSpan)op1);
                }
                else if (op1.GetType() == typeof(Map) && tipo.Equals("map"))
                {
                    Map temp  = (Map)op1;
                    Map valor = (Map)ts.getValor(id);
                    if (valor.id.Equals(temp.id) || valor.id.Equals("none"))
                    {
                        ts.setValor(id, temp);
                        return("");
                    }
                    else
                    {
                        mensajes.AddLast(mensa.error("No coincide los tipos: " + valor.id + " con: " + temp.id, l, c, "Semantico"));
                        return(null);
                    }
                }
                else if (op1.GetType() == typeof(List) && tipo.Equals("list"))
                {
                    List temp = (List)op1;

                    List valor = (List)ts.getValor(id);
                    if (valor.id.Equals(temp.id) || valor.id.Equals("none"))
                    {
                        ts.setValor(id, temp);
                        return("");
                    }
                    else
                    {
                        mensajes.AddLast(mensa.error("No coincide los tipos: " + valor.id + " con: " + temp.id, l, c, "Semantico"));
                        return(null);
                    }
                }
                else if (tipo.Equals("set") && op1.GetType() == typeof(Set))
                {
                    Set original = (Set)ts.getValor(id);
                    Set temp     = (Set)op1;
                    if (original.id.Equals(temp.id) || original.id.Equals("none"))
                    {
                        object resp = temp.buscarRepetidos(mensajes, l, c);
                        if (resp == null)
                        {
                            return(null);
                        }
                        temp.order();
                        ts.setValor(id, temp);
                    }
                    else
                    {
                        mensajes.AddLast(mensa.error("No coincide los tipos: " + original.id + " con: " + temp.id, l, c, "Semantico"));
                        return(null);
                    }
                }
                else if (op1.GetType() == typeof(InstanciaUserType))
                {
                    InstanciaUserType temp = (InstanciaUserType)op1;
                    if (tipo.Equals(temp.tipo.ToLower()) || temp.tipo.Equals("none"))
                    {
                        ts.setValor(id, temp);
                        return("");
                    }
                    else
                    {
                        mensajes.AddLast(mensa.error("No se le puede asignar a la variable: " + id + " el valor: " + op1, l, c, "Semantico"));
                        return(null);
                    }
                }
                else
                {
                    mensajes.AddLast(mensa.error("No se le puede asignar a la variable: " + id + " el valor: " + op1, l, c, "Semantico"));
                    return(null);
                }
                return("");
            }
            else
            {
                if (tipo.Equals("string") || tipo.Equals("date") || tipo.Equals("time"))
                {
                    ts.setValor(id, null);
                }
                else if (tipo.Equals("int") || tipo.Equals("double") || tipo.Equals("boolean") || tipo.Equals("map") || tipo.Equals("list") || tipo.Equals("set"))
                {
                    mensajes.AddLast(mensa.error("No se le puede asignar a la variable: " + id + " el valor: null", l, c, "Semantico"));
                    return(null);
                }
                else
                {
                    ts.setValor(id, new InstanciaUserType(tipo, null));
                }
                return("");
            }
        }
        /*
         * 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);
        }
Beispiel #9
0
 public object Ejecutar(TablaDeSimbolos ts)
 {
     if (ts.existID(new_var.Id))
     {
         bool is_ok = true;
         foreach (string item in new_var.Lst_variables)
         {
             if (!ts.existID(item.ToString()))
             {
                 is_ok = false;
                 salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", item + " no esta declarada en este ambito."));
             }
         }
         if (is_ok)
         {
             if (new_var.Real_type == Tipo.VARIABLE)
             {
                 string name = new_var.Valor.GetType().Name;
                 if (name.Equals("Map"))
                 {
                     Map new_map = (Map)new_var.Valor;
                     Map maux    = (Map)ts.getValor(new_var.Id);
                     new_map.Clave = maux.Clave;
                     if (new_map.comprobarTipo())
                     {
                         ts.setValor(new_var.Id, new_map.Mapita);
                     }
                     else
                     {
                         salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No todos los atributos coinciden."));
                     }
                 }
                 if (name.Equals("Lista"))
                 {
                     Lista new_lista = (Lista)new_var.Valor;
                     ts.setValor(new_var.Id, new_lista.Lista_valores);
                 }
                 else if (name.Equals("Variable"))
                 {
                     Variable aux_var = (Variable)new_var.Valor;
                     if (ts.existID(aux_var.Id))
                     {
                         object valor = ts.getValorByAttr(aux_var.Id, aux_var.Atributos);
                         if (valor == null)
                         {
                             salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "NO EXISTE ATRIBUTO"));
                         }
                         else
                         {
                             ts.setValor(new_var.Id, valor);
                         }
                     }
                     else
                     {
                         salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "Variable " + aux_var.Valor + " no se ha declarado."));
                     }
                 }
                 else if (name.Equals("Operacion"))
                 {
                     Tipo      type  = ts.getType(new_var.Id);
                     Operacion val   = (Operacion)new_var.Valor;
                     object    valor = val.Ejecutar(ts);
                     salida.AddRange(val.getSalida());
                     if (valor != null)
                     {
                         if (Program.casteos.comprobarCasteo(type, valor))
                         {
                             ts.setValor(new_var.Id, valor);
                         }
                         else
                         {
                             salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "No se puede convertir a" + ts.tipoAsignado(new_var.Id)));
                         }
                     }
                 }
             }
             else if (new_var.Real_type == Tipo.VARIABLE_ATRIBUTOS)
             {
                 if (new_var.Instanciada)
                 {
                     try
                     {
                         Operacion val   = (Operacion)new_var.Valor;
                         object    valor = val.Ejecutar(ts);
                         if (!ts.setValorByAttr(new_var.Id, valor, new_var.Atributos))
                         {
                             salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "NO EXISTE ATRIBUTO"));
                         }
                     }
                     catch
                     {
                         if (!ts.setValorByAttr(new_var.Id, new_var.Valor, new_var.Atributos))
                         {
                             salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", "NO EXISTE ATRIBUTO"));
                         }
                     }
                 }
             }
         }
     }
     else
     {
         salida.Add(Program.buildError(getLine(), getColumn(), "Semantico", new_var.Id + " no esta declarada en este ambito."));
     }
     return(null);
 }