Esempio n. 1
0
        public override object Ejecutar(Entorno e, bool funcion, bool ciclo, bool sw, bool tc, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            Entorno local = new Entorno(e);
            object  obj   = BloqueTry.Ejecutar(local, funcion, ciclo, sw, true, log, errores);

            if (obj != null)
            {
                if (obj is Throw th)
                {
                    bool sacar = false;

                    if (Parametro != null)
                    {
                        if (Parametro.Count() > 1)
                        {
                            errores.AddLast(new Error("Semántico", "El Catch solo recibe un Parámetro.", Linea, Columna));
                        }

                        string id = Parametro.ElementAt(0).Id;

                        Simbolo sim = e.GetLocal(id);

                        if (sim == null)
                        {
                            LinkedList <Simbolo> sims = new LinkedList <Simbolo>();
                            sims.AddLast(new Simbolo(new Tipo(Type.STRING), Rol.ATRIBUTO, "message", th.Mensaje));

                            sim = new Simbolo(new Tipo("exception"), Rol.VARIABLE, id.ToLower(), new Objeto("exception", new Entorno(null, sims)));
                            e.Add(sim);
                            sacar = true;
                        }
                        else
                        {
                            return(new Throw("ObjectAlreadyExists", Linea, Columna));
                            //errores.AddLast(new Error("Semántico", "Ya se ha declarado una variable con el id: " + id + ".", Linea, Columna));
                            //return null;
                        }
                    }

                    obj = BloqueCatch.Ejecutar(e, funcion, ciclo, sw, tc, log, errores);

                    if (Parametro != null && sacar)
                    {
                        string id = Parametro.ElementAt(0).Id;

                        Simbolo sim = e.GetLocal(id);

                        if (sim != null)
                        {
                            e.Simbolos.Remove(sim);
                        }
                    }
                }

                return(obj);
            }

            return(null);
        }
Esempio n. 2
0
        public override object Ejecutar(Entorno e, bool funcion, bool ciclo, bool sw, bool tc, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            Simbolo sim = e.Get(Id);

            if (sim != null)
            {
                if (sim.Tipo.IsCursor())
                {
                    Cursor cursor = (Cursor)sim.Valor;

                    if (cursor.Data != null)
                    {
                        if (cursor.Data.Count() > 0)
                        {
                            if (Parametro != null)
                            {
                                if (Parametro.Count() == cursor.Data.ElementAt(0).Simbolos.Count())
                                {
                                    foreach (Entorno ent in cursor.Data)
                                    {
                                        Entorno local = new Entorno(e);

                                        for (int i = 0; i < Parametro.Count(); i++)
                                        {
                                            Identificador par = Parametro.ElementAt(i);
                                            Simbolo       col = ent.Simbolos.ElementAt(i);

                                            Simbolo var;

                                            if (par.Tipo.Equals(col.Tipo))
                                            {
                                                var = new Simbolo(par.Tipo, Rol.VARIABLE, par.Id.ToLower(), col.Valor);
                                            }
                                            else
                                            {
                                                /*Agregar Collection*/

                                                Casteo cast = new Casteo(par.Tipo, new Literal(col.Tipo, col.Valor, 0, 0), 0, 0)
                                                {
                                                    Mostrar = false
                                                };
                                                object valCol = cast.GetValor(e, log, errores);

                                                if (valCol != null)
                                                {
                                                    if (valCol is Throw)
                                                    {
                                                        return(valCol);
                                                    }

                                                    var = new Simbolo(par.Tipo, Rol.VARIABLE, par.Id.ToLower(), valCol);
                                                }
                                                else
                                                {
                                                    errores.AddLast(new Error("Semántico", "Los Tipos en los parametros no coinciden con los del Cursor.", Linea, Columna));
                                                    return(null);
                                                }
                                            }
                                            local.Add(var);
                                        }

                                        object obj = Bloque.Ejecutar(local, funcion, true, sw, tc, log, errores);

                                        if (obj is Break)
                                        {
                                            break;
                                        }
                                        else if (obj is Return)
                                        {
                                            return(obj);
                                        }
                                        else if (obj is Throw)
                                        {
                                            return(obj);
                                        }
                                    }
                                    return(null);
                                }
                                else
                                {
                                    errores.AddLast(new Error("Semántico", "Los parametros no coinciden con los del Cursor.", Linea, Columna));
                                }
                            }
                            else
                            {
                                errores.AddLast(new Error("Semántico", "Los parametros no coinciden con los del Cursor.", Linea, Columna));
                            }
                        }
                    }
                    else
                    {
                        errores.AddLast(new Error("Semántico", "El Cursor esta cerrado, ejecute la sentecia Open primero.", Linea, Columna));
                    }
                }
                else
                {
                    errores.AddLast(new Error("Semántico", "La variable: " + Id + " no es un cursor.", Linea, Columna));
                }
            }
            return(null);
        }