//TODO: validar tipos public Simbolo execute_for(Entorno entorno) { Simbolo simbolo = retornar_asignacion(entorno); No_constante(simbolo); Objeto valor = retornar_valor_nuevo(entorno); Validar_tipos(simbolo.getValor(), valor); simbolo.setValor(valor); return(simbolo); }
public override Objeto execute(Entorno entorno) { //TODO: implementar asignacion, validar que sea integer Simbolo inicio = this.condicion.execute_for(entorno); validar_integer(inicio.getValor()); Objeto final = obtener_expresion(entorno); validar_integer(final); int b = Int16.Parse(final.getValor().ToString()); // Asignacion se debe agregar aca int a = Int16.Parse(inicio.getValor().getValor().ToString()); if (comportamiento) { for (int i = a; i >= b; i--) { Primitivo pr = new Primitivo(Objeto.TipoObjeto.INTEGER, i); inicio.setValor(pr); foreach (Nodo instruccion in this.instrucciones) { if (instruccion != null) { try { Objeto retorno = instruccion.execute(entorno); if (retorno != null) { if (retorno.getTipo() == Objeto.TipoObjeto.CONTINUE) { break; } else if (retorno.getTipo() == Objeto.TipoObjeto.BREAK) { return(null); } else if (retorno.getTipo() == Objeto.TipoObjeto.NULO) { return(retorno); } } } catch (Exception e) { Console.WriteLine(e); } } } } } else { for (int i = a; i <= b; i++) { Primitivo pr = new Primitivo(Objeto.TipoObjeto.INTEGER, i); inicio.setValor(pr); foreach (Nodo instruccion in this.instrucciones) { if (instruccion != null) { try { //validar los retornos Objeto retorno = instruccion.execute(entorno); if (retorno != null) { if (retorno.getTipo() == Objeto.TipoObjeto.CONTINUE) { break; } else if (retorno.getTipo() == Objeto.TipoObjeto.BREAK) { return(null); } else if (retorno.getTipo() == Objeto.TipoObjeto.NULO) { return(retorno); } } } catch (Exception e) { Console.WriteLine(e); } } } } } return(null); }