/* * 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); } }
/* * 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); } }
/* * 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); }
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); }
/* * 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); }
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); }
/* * 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); }
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 que se implementa de la clase padre * @ts tabla de simbolos * @user usuario que ejecuta la accion * @baseD base de datos en la que se esta trabajando * @mensajes respuesta de errores o mensajes de salida */ public object ejecutar(TablaDeSimbolos ts, Ambito ambito, TablaDeSimbolos tsT) { Mensaje mensa = new Mensaje(); TablaDeSimbolos tablaT; LinkedList <string> mensajes = ambito.mensajes; if (tPadre != null) { tablaT = tPadre; } else { tablaT = ts; } object op1 = (a == null) ? null : a.ejecutar(tablaT, ambito, tsT); object atri = (atributo == null) ? null : atributo.ejecutar(tablaT, ambito, tsT); //--------------------------------------------- REALIZA UNA ASIGNACION NORMAL--------------------------------------------------------------- if (operacion.Equals("ASIGNACION")) { string tipo = ts.getTipo(id); tipo = tipo.ToLower().TrimEnd().TrimStart(); if (!tipo.Equals("none")) { return(checkValues(op1, tipo, a, mensajes, ts)); } else { mensajes.AddLast(mensa.error("La variable: " + id + " no existe en este ambito", l, c, "Semantico")); } } //----------------------------------------------- REALIZA LA ASIGNACION DE UN ATRIBUTO ------------------------------------------------------ else if (operacion.Equals("ASIGNACIONA")) { if (atri != null) { if (atri.GetType() == typeof(InstanciaUserType)) { InstanciaUserType tempa = (InstanciaUserType)atri; if (tempa.lista != null) { foreach (Atributo at in tempa.lista) { if (at.nombre.Equals(id)) { string tipo = at.tipo.ToLower(); if (a == null) { if (tipo.Equals("string") || tipo.Equals("date") || tipo.Equals("time")) { at.valor = null; } else if (!tipo.Equals("int") && !tipo.Equals("boolean") && !tipo.Equals("double") && !tipo.Contains("map") && !tipo.Contains("list") && !tipo.Contains("set")) { InstanciaUserType temp = new InstanciaUserType(tipo, null); at.valor = temp; } else { mensajes.AddLast(mensa.error("No se le puede asignar al atributo: " + at.nombre + " el valor: null", l, c, "Semantico")); return(null); } return(""); } else { if (op1 != null) { if (op1.GetType() == typeof(string) && tipo.Equals("string")) { at.valor = (string)op1; } else if (op1.GetType() == typeof(int) && tipo.Equals("int")) { at.valor = (int)op1; } else if (op1.GetType() == typeof(int) && tipo.Equals("double")) { at.valor = Convert.ToInt32((Double)op1); } else if (op1.GetType() == typeof(Double) && tipo.Equals("double")) { at.valor = (Double)op1; } else if (op1.GetType() == typeof(Double) && tipo.Equals("int")) { at.valor = Convert.ToDouble((int)op1); } else if (op1.GetType() == typeof(Boolean) && tipo.Equals("boolean")) { at.valor = (Boolean)op1; } else if (op1.GetType() == typeof(DateTime) && tipo.Equals("date")) { at.valor = (DateTime)op1; } else if (op1.GetType() == typeof(TimeSpan) && tipo.Equals("time")) { at.valor = (TimeSpan)op1; } else if (op1.GetType() == typeof(Map) && tipo.Equals("map")) { Map temp = (Map)op1; Map valor = (Map)at.valor; if (valor.id.Equals(temp.id)) { at.valor = 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)at.valor; if (valor.id.Equals(temp.id)) { at.valor = 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)at.valor; Set temp = (Set)op1; if (original.id.Equals(temp.id)) { 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())) { at.valor = temp; } else { mensajes.AddLast(mensa.error("No se le puede asignar al atributo " + at.nombre + " el valor: " + op1, l, c, "Semantico")); return(null); } } else { mensajes.AddLast(mensa.error("No se le puede asignar al atributo: " + at.nombre + " el valor: " + op1, l, c, "Semantico")); return(null); } return(""); } else { if (tipo.Equals("string") || tipo.Equals("date") || tipo.Equals("time")) { at.valor = 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 al atributo: " + at.nombre + " el valor: null", l, c, "Semantico")); return(null); } else { at.valor = null; } return(""); } } return(null); } } ambito.listadoExcepciones.AddLast(new Excepcion("exception", "No existe el atributo:" + id)); mensajes.AddLast(mensa.error("No existe el atributo:" + id, l, c, "Semantico")); } } else { mensajes.AddLast(mensa.error("Para acceder a un atributo se necesita que sea de tipo USERTYPE no se reconoce: " + atri.ToString(), l, c, "Semantico")); } } ambito.listadoExcepciones.AddLast(new Excepcion("nullpointerexception", "No se puede asignar un valor a un null")); } return(null); }
/* * 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); }
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); }