コード例 #1
0
 public object Ejecutar(Ambito ambito)
 {
     try
     {
         foreach (Object ob in this.instrucciones)
         {
             if (ob is Instruccion)
             {
                 Instruccion aux = (Instruccion)ob;
                 Object      res = aux.Ejecutar(ambito);
                 if (res is NodoReturn)
                 {
                     return(res);
                 }
             }
             else if (ob is Expresion)
             {
                 Expresion exp = (Expresion)ob;
                 Object    res = exp.getValor(ambito);
                 if (res is NodoReturn)
                 {
                     return(res);
                 }
             }
         }
     }
     catch (Exception e)
     {
         TError error = new TError("Ejecucion", "Error al Ejecutar la funcion: " + idFuncion + " | Error: " + e.Message, this.linea, this.columna, false);
         Estatico.errores.Add(error);
         Estatico.ColocaError(error);
     }
     return(new NodoReturn(new Vacio(), "vacio"));
 }
コード例 #2
0
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                Ambito ambitoFor = new Ambito(ambito, this.clase, ambito.archivo);
                ambitoFor.tomaValoresDelAmbito(ambito, true);

                varControl.Ejecutar(ambitoFor);
                Object condicion = condicional.getValor(ambitoFor);
                if (condicion is Boolean)
                {
                    Boolean val = (Boolean)condicion;
                    ///

                    while (val)
                    {
                        foreach (Object o in this.instrucciones)
                        {
                            if (o is Instruccion)
                            {
                                Instruccion aux = (Instruccion)o;
                                Object      res = aux.Ejecutar(ambitoFor);
                                if (res is NodoReturn)
                                {
                                    return(res);
                                }
                                else if (res is Romper)
                                {
                                    goto HacerBreak;
                                }
                                else if (res is Continuar)
                                {
                                    goto HacerContinue;
                                }
                            }
                            else if (o is Expresion)
                            {
                                Expresion exp = (Expresion)o;
                                Object    res = exp.getValor(ambitoFor);
                                if (res is NodoReturn)
                                {
                                    return(res);
                                }
                                else if (res is Romper)
                                {
                                    goto HacerBreak;
                                }
                                else if (res is Continuar)
                                {
                                    goto HacerContinue;
                                }
                            }
                        }
HacerContinue:
                        operacion.Ejecutar(ambitoFor);               //EJECTUO EL IMCREMENTO
                        condicion = condicional.getValor(ambitoFor); // EVALUO LA CONDICION, OJO QUE LA TOMO DEL PADRE
                        val       = (Boolean)condicion;              /// LA PASO A BOOLEANO
                    }

HacerBreak:
                    return(new Nulo());
                }
                else
                {
                    TError error = new TError("Semantico", "En la condicional del ciclo Para se espera un valor booleano | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.errores.Add(error);
                    Estatico.ColocaError(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Error al ejecutar el ciclo For | Clase: " + clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
            return(new Nulo());
        }
コード例 #3
0
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                Object comprobacion = condicion.getValor(ambito);
                if (comprobacion is Boolean)
                {
                    Boolean val = (Boolean)comprobacion;
                    /// NUEVO AMBITO
                    Ambito ambitoWhile = new Ambito(ambito, this.clase, ambito.archivo);
                    ambitoWhile.tomaValoresDelAmbito(ambito, true);
                    ///
                    while (val)
                    {
                        foreach (Object o in this.instrucciones)
                        {
                            if (o is Instruccion)
                            {
                                Instruccion aux = (Instruccion)o;
                                Object      res = aux.Ejecutar(ambitoWhile);
                                if (res is NodoReturn)
                                {
                                    return(res);
                                }
                                else if (res is Romper)
                                {
                                    goto HaceBreak;
                                }
                                else if (res is Continuar)
                                {
                                    goto HacerContinue;
                                }
                            }
                            else if (o is Expresion)
                            {
                                Expresion exp = (Expresion)o;
                                Object    res = exp.getValor(ambitoWhile);
                                if (res is NodoReturn)
                                {
                                    return(res);
                                }
                                else if (res is Romper)
                                {
                                    goto HaceBreak;
                                }
                                else if (res is Continuar)
                                {
                                    goto HacerContinue;
                                }
                            }
                        }

HacerContinue:
                        comprobacion = condicion.getValor(ambito);//OJO POSIBLE ERROR
                        val          = (Boolean)comprobacion;
                    }
HaceBreak:
                    return(new Nulo());
                }
                else
                {
                    TError error = new TError("Semantico", "Para una Sentencias Mientras se necesita un valor Booelano en la condicion | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.errores.Add(error);
                    Estatico.ColocaError(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Ocurrio un error al Ejecutar la sentencia Mientras | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna, false);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
            return(new Nulo());
        }
コード例 #4
0
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                Object cond = this.condicion.getValor(ambito);
                String tipo = this.condicion.getTipo(ambito);
                if (cond is Boolean)
                {
                    Boolean val = (Boolean)cond;
                    /// NUEVO AMBITO
                    Ambito ambitoDoWhile = new Ambito(ambito, this.clase.ToLower(), ambito.archivo);
                    ambitoDoWhile.tomaValoresDelAmbito(ambito, true);
                    ///
                    do
                    {
                        foreach (Object o in this.instrucciones)
                        {
                            if (o is Instruccion)
                            {
                                Instruccion aux = (Instruccion)o;
                                Object      res = aux.Ejecutar(ambitoDoWhile);
                                if (res is NodoReturn)
                                {
                                    return(res);
                                }
                                else if (res is Romper)
                                {
                                    goto HacerBreak;
                                }
                                else if (res is Continuar)
                                {
                                    goto HacerContinue;
                                }
                            }
                            else if (o is Expresion)
                            {
                                Expresion exp = (Expresion)o;
                                Object    res = exp.getValor(ambitoDoWhile);
                                if (res is NodoReturn)
                                {
                                    return(res);
                                }
                                else if (res is Romper)
                                {
                                    goto HacerBreak;
                                }
                                else if (res is Continuar)
                                {
                                    goto HacerContinue;
                                }
                            }
                        }
HacerContinue:
                        cond = this.condicion.getValor(ambito);///OJO POSIBLE BUG
                        val  = (Boolean)cond;
                    } while (val);

HacerBreak:
                    return(new Nulo());
                }
                else
                {
                    TError error = new TError("Ejecucion", "La sentencias Hacer-Mientras recibe una condicion con resultado booleano, Se encontro tipo: \"" + tipo + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.errores.Add(error);
                    Estatico.ColocaError(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Error al ejecutar el ciclo Hacer-Mientras | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna, false);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
            return(new Nulo());
        }
コード例 #5
0
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                if (hayDefecto == 1)///HAY POR DEFECTO
                {
                    foreach (NodoCaso caso in casos)
                    {
                        Expresion op2 = caso.getExpresion();
                        /// HAGO LA COMPARACION
                        Operacion operacion = new Operacion(this.AEvaluar, op2, Estatico.Operandos.IGUAL, linea, columna, clase);
                        Object    re        = operacion.getValor(ambito);
                        if (re is Boolean)           /// EL RESULTADO ES BOOLEANO?
                        {
                            Boolean v = (Boolean)re; /// CASTEO A BOOLENAO
                            if (v)                   /// SI ES VERDADERO.... EJECUTO LAS INSTRUCCIONES
                            {
                                List <Object> instrucciones = caso.getSentencias();
                                Ambito        local         = new Ambito(ambito, this.clase, ambito.archivo);
                                local.tomaValoresDelAmbito(ambito, true);

                                foreach (Object o in instrucciones)
                                {
                                    if (o is Instruccion)
                                    {
                                        Instruccion aux = (Instruccion)o;
                                        Object      res = aux.Ejecutar(local);
                                        if (res is NodoReturn)
                                        {
                                            return(res);
                                        }
                                        else if (res is Romper)
                                        {
                                            goto HacerBreak;
                                        }
                                    }
                                    else if (o is Expresion)
                                    {
                                        Expresion exp = (Expresion)o;
                                        Object    res = exp.getValor(local);
                                        if (res is NodoReturn)
                                        {
                                            return(res);
                                        }
                                        else if (res is Romper)
                                        {
                                            goto HacerBreak;
                                        }
                                    }
                                }
                            }
                        }
                    }
                    goto HacerDefecto;
                }
                else
                {
                    foreach (NodoCaso caso in casos)
                    {
                        Expresion op2 = caso.getExpresion();
                        /// HAGO LA COMPARACION
                        Operacion operacion = new Operacion(this.AEvaluar, op2, Estatico.Operandos.IGUAL, linea, columna, clase);
                        Object    re        = operacion.getValor(ambito);
                        if (re is Boolean)           /// EL RESULTADO ES BOOLEANO?
                        {
                            Boolean v = (Boolean)re; /// CASTEO A BOOLENAO
                            if (v)                   /// SI ES VERDADERO.... EJECUTO LAS INSTRUCCIONES
                            {
                                List <Object> instrucciones = caso.getSentencias();
                                Ambito        local         = new Ambito(ambito, this.clase, ambito.archivo);
                                local.tomaValoresDelAmbito(ambito, true);

                                foreach (Object o in instrucciones)
                                {
                                    if (o is Instruccion)
                                    {
                                        Instruccion aux = (Instruccion)o;
                                        Object      res = aux.Ejecutar(local);
                                        if (res is NodoReturn)
                                        {
                                            return(res);
                                        }
                                        else if (res is Romper)
                                        {
                                            goto HacerBreak;
                                        }
                                    }
                                    else if (o is Expresion)
                                    {
                                        Expresion exp = (Expresion)o;
                                        Object    res = exp.getValor(local);
                                        if (res is NodoReturn)
                                        {
                                            return(res);
                                        }
                                        else if (res is Romper)
                                        {
                                            goto HacerBreak;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    goto HacerBreak;
                }

                /// EJECUTAR EL DEFECTO
HacerDefecto:
                List <object> instrucci = defecto.getSentencias();
                Ambito loca             = new Ambito(ambito, this.clase, ambito.archivo);
                loca.tomaValoresDelAmbito(ambito, true);
                foreach (object o in instrucci)
                {
                    if (o is Instruccion)
                    {
                        Instruccion aux = (Instruccion)o;
                        Object      res = aux.Ejecutar(loca);
                        if (res is NodoReturn)
                        {
                            return(res);
                        }
                        else if (res is Romper)
                        {
                            goto HacerBreak;
                        }
                    }
                    else if (o is Expresion)
                    {
                        Expresion exp = (Expresion)o;
                        Object    res = exp.getValor(loca);
                        if (res is NodoReturn)
                        {
                            return(res);
                        }
                        else if (res is Romper)
                        {
                            goto HacerBreak;
                        }
                    }
                }
HacerBreak:
                return(new Nulo());
            }
            catch
            {
                TError error = new TError("Ejecucion", "Error al Ejecutar sentencias Casos | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                Estatico.ColocaError(error);
                Estatico.errores.Add(error);
            }
            return(new Nulo());
        }
コード例 #6
0
ファイル: AST.cs プロジェクト: Oshhcar/Colette
        public void ejecutar(TextBox salida)
        {
            Entorno global = new Entorno();

            for (int i = 0; i < Instrucciones.Count(); i++)
            {
                Instruccion instruccion = Instrucciones.ElementAt(i);

                if (instruccion is Etiqueta)
                {
                    Etiqueta label = (Etiqueta)instruccion;
                    label.I = i;
                    label.Ejecutar(global);
                }
                else if (instruccion is Metodo)
                {
                    Metodo metodo = (Metodo)instruccion;
                    LinkedList <Instruccion> bloques = metodo.Ejecutar(global) as LinkedList <Instruccion>;
                    /*comprobar null*/
                    for (int j = 0; j < bloques.Count(); j++)
                    {
                        Instruccion bloque = bloques.ElementAt(j);
                        if (bloque is Etiqueta)
                        {
                            Etiqueta labelJ = (Etiqueta)bloque;
                            labelJ.I = j;
                            labelJ.Ejecutar(global);
                        }
                    }
                }
            }



            for (int i = 0; i < Instrucciones.Count(); i++)
            {
                Instruccion instruccion = Instrucciones.ElementAt(i);

                if (!(instruccion is Etiqueta) && !(instruccion is Metodo))
                {
                    if (!(instruccion is Salto) && !(instruccion is SaltoCond))
                    {
                        if (instruccion is Print)
                        {
                            ((Print)instruccion).Output = salida;
                        }
                        else if (instruccion is Call)
                        {
                            ((Call)instruccion).Output = salida;
                        }
                        instruccion.Ejecutar(global);
                    }
                    else
                    {
                        Object o = instruccion.Ejecutar(global);
                        if (o != null)
                        {
                            i = Convert.ToInt32(o.ToString());
                        }
                    }
                }
            }
            Console.WriteLine("\n");
            //global.Recorrer();
            //Console.WriteLine("\n");
        }
コード例 #7
0
 public object Ejecutar(Ambito ambito)
 {
     try
     {
         //SIMPLE IF SIN SENTENCIAS
         /// TOMO LA CONDICIONAL
         Object condicional = this.condicional.getValor(ambito);
         String tipoaux     = this.condicional.getTipo(ambito);
         if (condicional is Boolean)
         {
             Boolean res = (Boolean)condicional;
             ///TOMO EL AMBITO PARA PODER VALIDAR EL USO DE VARIABLES QUE HAN SIDO DECLARADAS MAS ARRIBA
             Ambito ambitoIF = new Ambito(ambito, this.clase, ambito.archivo);
             ambitoIF.tomaValoresDelAmbito(ambito, true);
             ///
             if (tipo == 1)
             {
                 //UN SI SIMPLE
                 if (res)
                 {
                     foreach (Object o in this.sentenciasVerdaderas)
                     {
                         if (o is Instruccion)
                         {
                             Instruccion aux = (Instruccion)o;
                             Object      s   = aux.Ejecutar(ambitoIF);
                             if (s is NodoReturn)
                             {
                                 return(s);
                             }
                             else if (s is Romper)
                             {
                                 return(new Romper());
                             }
                             else if (s is Continuar)
                             {
                                 return(new Continuar());
                             }
                         }
                         else if (o is Expresion)
                         {
                             Expresion exp = (Expresion)o;
                             Object    s   = exp.getValor(ambitoIF);
                             if (s is NodoReturn)
                             {
                                 return(s);
                             }
                             else if (s is Romper)
                             {
                                 return(new Romper());
                             }
                             else if (s is Continuar)
                             {
                                 return(new Continuar());
                             }
                         }
                     }
                     return(new Nulo());
                 }
             }
             else
             {
                 if (res)
                 {
                     foreach (Object o in this.sentenciasVerdaderas)
                     {
                         if (o is Instruccion)
                         {
                             Instruccion aux = (Instruccion)o;
                             Object      s   = aux.Ejecutar(ambitoIF);
                             if (s is NodoReturn)
                             {
                                 return(s);
                             }
                             else if (s is Romper)
                             {
                                 return(new Romper());
                             }
                             else if (s is Continuar)
                             {
                                 return(new Continuar());
                             }
                         }
                         else if (o is Expresion)
                         {
                             Expresion exp = (Expresion)o;
                             Object    s   = exp.getValor(ambitoIF);
                             if (s is NodoReturn)
                             {
                                 return(s);
                             }
                             else if (s is Romper)
                             {
                                 return(new Romper());
                             }
                             else if (s is Continuar)
                             {
                                 return(new Continuar());
                             }
                         }
                     }
                     return(new Nulo());
                 }
                 else
                 {
                     foreach (Object o in this.sentenciasFalso)
                     {
                         if (o is Instruccion)
                         {
                             Instruccion aux = (Instruccion)o;
                             Object      s   = aux.Ejecutar(ambitoIF);
                             if (s is NodoReturn)
                             {
                                 return(s);
                             }
                             else if (s is Romper)
                             {
                                 return(new Romper());
                             }
                             else if (s is Continuar)
                             {
                                 return(new Continuar());
                             }
                         }
                         else if (o is Expresion)
                         {
                             Expresion exp = (Expresion)o;
                             Object    s   = exp.getValor(ambitoIF);
                             if (s is NodoReturn)
                             {
                                 return(s);
                             }
                             else if (s is Romper)
                             {
                                 return(new Romper());
                             }
                             else if (s is Continuar)
                             {
                                 return(new Continuar());
                             }
                         }
                     }
                     return(new Nulo());
                 }
             }
         }
         else
         {
             TError error = new TError("Semantico", "La condicional se espera un valor Booleano y se encontro: \"" + tipoaux + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
             Estatico.errores.Add(error);
             Estatico.ColocaError(error);
         }
     }
     catch (Exception e)
     {
         TError error = new TError("Ejecucion", "Error al Ejecutar condicional Si | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna, false);
         Estatico.errores.Add(error);
         Estatico.ColocaError(error);
     }
     return(null);
 }
コード例 #8
0
        public object Ejecutar(Ambito ambito)
        {
            try
            {
                Object condi = condicion.getValor(ambito);
                String tipo  = condicion.getTipo(ambito);
                if (condi is Boolean)
                {
                    Boolean val = (Boolean)condi;
                    /// NUEVO AMBITO
                    Ambito ambitoRepetir = new Ambito(ambito, this.clase, ambito.archivo);
                    ambitoRepetir.tomaValoresDelAmbito(ambito, true);
                    ///
                    do
                    {
                        foreach (Object o in this.instrucciones)
                        {
                            if (o is Instruccion)
                            {
                                Instruccion aux = (Instruccion)o;
                                Object      res = aux.Ejecutar(ambitoRepetir);
                                if (res is NodoReturn)
                                {
                                    return(res);
                                }
                                else if (res is Romper)
                                {
                                    goto HacerBreak;
                                }
                                else if (res is Continuar)
                                {
                                    goto HacerContinue;
                                }
                            }
                            else if (o is Expresion)
                            {
                                Expresion exp = (Expresion)o;
                                Object    res = exp.getValor(ambitoRepetir);
                                if (res is NodoReturn)
                                {
                                    return(res);
                                }
                                else if (res is Romper)
                                {
                                    goto HacerBreak;
                                }
                                else if (res is Continuar)
                                {
                                    goto HacerContinue;
                                }
                            }
                        }
HacerContinue:
                        condi = this.condicion.getValor(ambito);//OJO CON POSIBLE ERROR
                        val   = (Boolean)condi;
                    } while (!val);

HacerBreak:
                    return(new Nulo());
                }
                else
                {
                    TError error = new TError("Semantico", "Para la condicion del ciclo Repetir se espera un valor Booleano y se encontro: \"" + tipo + "\" | Clase: " + this.clase + " | Archivo: " + ambito.archivo, linea, columna, false);
                    Estatico.ColocaError(error);
                    Estatico.errores.Add(error);
                }
            }
            catch (Exception e)
            {
                TError error = new TError("Ejecucion", "Error al ejecutar el ciclo Repetir-Hasta | Clase: " + this.clase + " | Archivo: " + ambito.archivo + " | Mensaje: " + e.Message, linea, columna, false);
                Estatico.errores.Add(error);
                Estatico.ColocaError(error);
            }
            return(new Nulo());
        }