public object getValor(Ambito ambito) { try { Simbolo s = (Simbolo)ambito.getSimbolo(this.id.ToLower()); if (s != null) { if (s is Arreglo) { Arreglo aux = (Arreglo)s; List <int> coordenada = getDimensiones(ambito); if (coordenada != null) { if (aux.esCoordenadaValida(coordenada)) { int realIndex = aux.calcularPosicion(coordenada); Object valor = aux.getElementFromArray(realIndex); this.ValorAux = valor; return(valor); } else { TError error = new TError("Semantico", "Para el arreglo: \"" + this.id + "\" La Dimension no se encuentra dentro de los limites! | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } else { TError error = new TError("Semantico", "Para el arreglo: \"" + this.id + "\" No se ha proporcionado un Entero como Dimension del Mismo | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } else { TError error = new TError("Semantico", "El simbolo: \"" + this.id + "\" No es un arreglo por lo que no se puede acceder al valor indicado | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } else { TError error = new TError("Semantico", "No existe el Arreglo: \"" + this.id + "\" en este Ambito | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } catch (Exception e) { TError error = new TError("Ejecucion", "Error al acceder al valor de arreglo: \"" + id + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } this.ValorAux = new Nulo(); return(ValorAux); }
public object Ejecutar(Ambito ambito) { try { Simbolo s = (Simbolo)ambito.getSimbolo(this.idArr.ToLower()); if (s != null) { if (s is Arreglo) { Arreglo arr = (Arreglo)s; /// DIMENSIONES DEL ARREGLO List <int> dimensiones = getDimensiones(ambito); if (dimensiones != null) { Object valorAsignado = val.getValor(ambito); String tipoVal = val.getTipo(ambito); if (tipoVal.ToLower().Equals(arr.Tipo.ToLower())) { //ASIGNO EL VALOR if (arr.esCoordenadaValida(dimensiones)) { int realIndex = arr.calcularPosicion(dimensiones); arr.setValueAtPosition(realIndex, valorAsignado); } else { TError error = new TError("Semantico", "Asignacion a Arreglo: \"" + this.idArr + "\" no se puede realizar ya que la posicion no es valida! | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } else { TError error = new TError("Semantico", "El valor asignar al arreglo: \"" + this.idArr + "\" no coincide con el tipo esperado. Se esperaba: \"" + arr.Tipo + "\" y se encontro:\"" + tipoVal + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } else { TError error = new TError("Semantico", "Las dimensiones no contienen valores valodos, solo enteros son admitidos: \"" + this.idArr + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } else { TError error = new TError("Semantico", "El simbolo: \"" + this.idArr + "\" No es un arreglo para poder realizara la asignacion | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } else { TError error = new TError("Semantico", "El arreglo: \"" + idArr + "\" no existe en este ambito! | Clase: " + this.clase + " | Archivo: " + ambito.archivo, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } } catch (Exception e) { TError error = new TError("Ejecucion", "Error de Ejecucion al intentar asignar posicion de un Arreglo | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, this.linea, this.columna, false); Estatico.errores.Add(error); Estatico.ColocaError(error); } return(null); }