예제 #1
0
        public override Objeto executar_funcion_usuario(Entorno entorno)
        {
            Simbolo simbolo_retorno = new Simbolo(base.getNombre(), this.retorno, base.getLinea(), base.getColumna());

            entorno.addSimbolo(simbolo_retorno, base.getNombre());

            foreach (Nodo instruccion in this.instrucciones)
            {
                if (instruccion != null)
                {
                    try
                    {
                        Objeto retorno = instruccion.execute(entorno);
                        if (retorno != null)
                        {
                            if (retorno.getTipo() == Objeto.TipoObjeto.CONTINUE)
                            {
                                Sentencia_transferencia tem = (Sentencia_transferencia)retorno;
                                Error error = new Error(tem.linea, tem.columna, Error.Errores.Semantico,
                                                        "Sentencia continue debe estar dentro de un ciclo");
                                Captura_error(error);
                            }
                            else if (retorno.getTipo() == Objeto.TipoObjeto.BREAK)
                            {
                                Sentencia_transferencia tem = (Sentencia_transferencia)retorno;
                                Error error = new Error(tem.linea, tem.columna, Error.Errores.Semantico,
                                                        "Sentencia break debe estar dentro de un ciclo o case");
                                Captura_error(error);
                            }
                            else if (retorno.getTipo() == Objeto.TipoObjeto.NULO)
                            {
                                Sentencia_transferencia tem = (Sentencia_transferencia)retorno;
                                if (tem.valor != null)
                                {
                                    Validar_retorno(tem.valor, instruccion);
                                    return(tem.valor);
                                }
                                else
                                {
                                    Error error = new Error(tem.linea, tem.columna, Error.Errores.Semantico,
                                                            "La sentencia de exit en funcion debe de retornar un valor");
                                    Captura_error(error);
                                }
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                        //throw new Exception(e.ToString());
                    }
                }
            }

            Simbolo aux = entorno.GetSimbolo(base.getNombre());

            return(aux.getValor());
        }
예제 #2
0
        public override Objeto executar_funcion_usuario(Entorno entorno)
        {
            foreach (Nodo instruccion in this.instruciones)
            {
                if (instruccion != null)
                {
                    try
                    {
                        Objeto retorno = instruccion.execute(entorno);
                        if (retorno != null)
                        {
                            if (retorno.getTipo() == Objeto.TipoObjeto.CONTINUE)
                            {
                                Sentencia_transferencia tem = (Sentencia_transferencia)retorno;
                                Error error = new Error(tem.linea, tem.columna, Error.Errores.Semantico,
                                                        "Sentencia continue debe estar dentro de un ciclo");
                                Captura_error(error);
                            }
                            else if (retorno.getTipo() == Objeto.TipoObjeto.BREAK)
                            {
                                Sentencia_transferencia tem = (Sentencia_transferencia)retorno;
                                Error error = new Error(tem.linea, tem.columna, Error.Errores.Semantico,
                                                        "Sentencia break debe estar dentro de un ciclo o case");
                                Captura_error(error);
                            }
                            else if (retorno.getTipo() == Objeto.TipoObjeto.NULO)
                            {
                                Sentencia_transferencia tem = (Sentencia_transferencia)retorno;
                                if (tem.valor != null)
                                {
                                    Error error = new Error(tem.linea, tem.columna, Error.Errores.Semantico,
                                                            "La sentencia de exit no debe retornar valor dentro del procedimiento");
                                    Captura_error(error);
                                }
                                // contrario termina la ejecucion
                                return(null);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                        //throw new Exception(e.ToString());
                    }
                }
            }

            return(null);
        }
예제 #3
0
        public void ejecutar()
        {
            Entorno entorno = new Entorno("global");

            foreach (Nodo nodo in instrucciones)
            {
                if (nodo != null)
                {
                    try
                    {
                        Objeto retorno = nodo.execute(entorno);

                        if (retorno != null)
                        {
                            if (retorno.getTipo() == Objeto.TipoObjeto.CONTINUE)
                            {
                                Sentencia_transferencia tem = (Sentencia_transferencia)retorno;
                                Error error = new Error(tem.linea, tem.columna, Error.Errores.Semantico,
                                                        "Sentencia continue debe estar dentro de un ciclo");
                                this.addError(error);
                            }
                            else if (retorno.getTipo() == Objeto.TipoObjeto.BREAK)
                            {
                                Sentencia_transferencia tem = (Sentencia_transferencia)retorno;
                                Error error = new Error(tem.linea, tem.columna, Error.Errores.Semantico,
                                                        "Sentencia break debe estar dentro de un ciclo o case");
                                this.addError(error);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.ToString());
                    }
                }
            }
            entorno.Tabla_general();
        }