public override object ejecutar(Entorno ent) { foreach (Condicion_If condicion in listaCondiciones) { Object retornar = condicion.ejecutar(ent); if (condicion.ejecutado) { if (retornar != null) { if (typeof(Break).IsInstanceOfType(retornar)) { //si viene un break se detiene el flujo del ciclo return(retornar); } else if (typeof(Continue).IsInstanceOfType(retornar)) { //aqui solo se debe continuar el ciclo //continue; } else if (typeof(Primitivo).IsInstanceOfType(retornar)) { //Aqui devolvemos el valor del retorno return(retornar); } } } } //si llego aqui es porque no retorno en ninguna true if (Else != null) { Entorno ent1 = new Entorno(ent, ent.global); Object retornar = Else.ejecutar(ent1); //aqui puede que sea new Entorno(ent.anterior, ent.global); para no tomar el del if if (retornar != null) { if (typeof(Break).IsInstanceOfType(retornar)) { //si viene un break se detiene el flujo del ciclo return(retornar); } else if (typeof(Continue).IsInstanceOfType(retornar)) { //aqui solo se debe continuar el ciclo //continue; } else if (typeof(Primitivo).IsInstanceOfType(retornar)) { //Aqui devolvemos el valor del retorno return(retornar); } } } return(null); }
public override object ejecutar(Entorno ent) { MasterClass.Display.AddLast(MasterClass.TipoCiclo.Ciclo); //obtenemos la expresion de condicion siempre y cuando sea booleana y sea true Expresion valor = condicion.getValor(ent); if (valor.tipo.tipo == Tipo.enumTipo.booleano) { //Si es booleana! Boolean condition = bool.Parse(valor.valor.ToString()); //hacemos el ciclo while puramente while (condition) { //Creamos su nuevo entorno (sirve para while anidados) Entorno nuevo = new Entorno(ent); Object retornar = sentencias.ejecutar(nuevo); //se ejecutan todas las instrucciones de su bloque if (retornar != null) { if (typeof(Break).IsInstanceOfType(retornar)) { //si viene un break se detiene el flujo del ciclo break; } else if (typeof(Continue).IsInstanceOfType(retornar)) { //aqui solo se debe continuar el ciclo //continue; } else if (typeof(Primitivo).IsInstanceOfType(retornar)) { //Aqui devolvemos el valor del retorno return(retornar); } } Expresion valor1 = condicion.getValor(nuevo); condition = bool.Parse(valor1.valor.ToString()); } } else { MasterClass.Instance.addError(new C_Error("Semantico", "No se puede comparar tipo de dato: " + valor.tipo.tipo, linea, columna)); } MasterClass.Display.RemoveLast(); return(null); }
public override object ejecutar(Entorno ent) { ejecutado = false; Expresion valor = Condicion.getValor(ent); if (valor.tipo.tipo == Tipo.enumTipo.booleano) { bool condition = bool.Parse(valor.valor.ToString()); if (condition) { Entorno nuevo = new Entorno(ent, ent.global); // Object retornar = instrucciones.ejecutar(nuevo); ejecutado = true; if (retornar != null) { if (typeof(Break).IsInstanceOfType(retornar)) { //si viene un break se detiene el flujo del ciclo return(retornar); } else if (typeof(Continue).IsInstanceOfType(retornar)) { //aqui solo se debe continuar el ciclo //continue; } else if (typeof(Primitivo).IsInstanceOfType(retornar)) { //Aqui devolvemos el valor del retorno return(retornar); } } } } else { MasterClass.Instance.addError(new C_Error("Semantico", "No se puede operar tipo de dato: " + valor.tipo.tipo + " como condicion ", linea, columna)); } return(null); }