Example #1
0
        public override object GetValor(Entorno e, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            object valExpr = Expr.GetValor(e, log, errores);

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

                object valTarget = Target.GetValor(e, log, errores);

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

                    if (Target.Tipo.IsMap() || Target.Tipo.IsList() || Target.Tipo.IsSet())
                    {
                        if (!(valTarget is Null))
                        {
                            Collection collection = (Collection)valTarget;

                            if (collection.Tipo.Clave.Equals(Expr.Tipo))
                            {
                                object valor = GetCollection ? collection.GetCollection(valExpr.ToString()) : collection.Get(valExpr.ToString());
                                if (valor != null)
                                {
                                    Tipo = collection.Tipo.Valor;
                                    return(valor);
                                }
                                else
                                {
                                    return(new Throw("IndexOutException", Linea, Columna));
                                }
                                //errores.AddLast(new Error("Semántico", "No existe un valor en la posición: " + valExpr.ToString() + " del " + Target.Tipo.Type.ToString() + ".", Linea, Columna));
                            }
                            else
                            {
                                Casteo cast = new Casteo(collection.Tipo.Clave, new Literal(Expr.Tipo, valExpr, 0, 0), 0, 0)
                                {
                                    Mostrar = false
                                };
                                valExpr = cast.GetValor(e, log, errores);

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

                                    object valor = GetCollection ? collection.GetCollection(valExpr.ToString()) : collection.Get(valExpr.ToString());
                                    if (valor != null)
                                    {
                                        Tipo = collection.Tipo.Valor;
                                        return(valor);
                                    }
                                    else
                                    {
                                        return(new Throw("IndexOutException", Linea, Columna));
                                    }
                                }

                                errores.AddLast(new Error("Semántico", "El tipo de la clave no coincide con la clave de la Collection.", Linea, Columna));
                                return(null);
                            }
                        }
                        else
                        {
                            return(new Throw("NullPointerException", Linea, Columna));
                        }
                        //errores.AddLast(new Error("Semántico", "El " + Target.Tipo.Type.ToString() + " no ha sido inicializado.", Linea, Columna));
                    }
                    else
                    {
                        errores.AddLast(new Error("Semántico", "La variable debe ser de tipo Map, List o Set.", Linea, Columna));
                    }
                }
            }

            return(null);
        }
Example #2
0
        public override object GetValor(Entorno e, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            Expresion clave = (Expresion)Collection.ElementAt(0).Clave;
            Expresion valor = (Expresion)Collection.ElementAt(0).Valor;

            object valClave = clave.GetValor(e, log, errores);
            object valValor = valor.GetValor(e, log, errores);

            if (valClave != null && valValor != null)
            {
                if (valClave is Throw)
                {
                    return(valClave);
                }

                if (valValor is Throw)
                {
                    return(valValor);
                }

                Tipo = new Tipo(clave.Tipo, valor.Tipo);

                Collection map = new Collection(new Tipo(clave.Tipo, valor.Tipo));
                map.Insert(valClave, valValor);

                for (int i = 1; i < Collection.Count(); i++)
                {
                    CollectionValue value = Collection.ElementAt(i);
                    clave    = (Expresion)value.Clave;
                    valor    = (Expresion)value.Valor;
                    valClave = clave.GetValor(e, log, errores);
                    valValor = valor.GetValor(e, log, errores);

                    if (valClave != null && valValor != null)
                    {
                        if (valClave is Throw)
                        {
                            return(valClave);
                        }

                        if (valValor is Throw)
                        {
                            return(valValor);
                        }

                        if (map.Tipo.Clave.Equals(clave.Tipo) && map.Tipo.Valor.Equals(valor.Tipo))
                        {
                            if (map.Get(valClave) == null)
                            {
                                map.Insert(valClave, valValor);
                            }
                            else
                            {
                                errores.AddLast(new Error("Semántico", "Ya existe un valor con la clave: " + valClave.ToString() + " en Map.", Linea, Columna));
                            }
                        }
                        else
                        {
                            Casteo cast1 = new Casteo(map.Tipo.Clave, new Literal(clave.Tipo, valClave, 0, 0), 0, 0)
                            {
                                Mostrar = false
                            };

                            Casteo cast2 = new Casteo(map.Tipo.Valor, new Literal(valor.Tipo, valValor, 0, 0), 0, 0)
                            {
                                Mostrar = false
                            };

                            valClave = cast1.GetValor(e, log, errores);
                            valValor = cast2.GetValor(e, log, errores);

                            if (valClave != null && valValor != null)
                            {
                                if (valClave is Throw)
                                {
                                    return(valClave);
                                }

                                if (valValor is Throw)
                                {
                                    return(valValor);
                                }

                                if (map.Get(valClave) == null)
                                {
                                    map.Insert(valClave, valValor);
                                }
                                else
                                {
                                    errores.AddLast(new Error("Semántico", "Ya existe un valor con la clave: " + valClave.ToString() + " en Map.", Linea, Columna));
                                }

                                continue;
                            }

                            errores.AddLast(new Error("Semántico", "Los tipos no coinciden con la clave:valor del Map.", Linea, Columna));
                        }
                        //continue;
                    }
                    //return null;
                }

                return(map);
            }
            return(null);
        }
Example #3
0
        public override object GetValor(Entorno e, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            Expresion valor    = Collection.ElementAt(0);
            object    valValor = valor.GetValor(e, log, errores);

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

                Tipo = new Tipo(Type.LIST, valor.Tipo);
                Collection list = new Collection(new Tipo(Type.LIST, valor.Tipo));
                list.Insert(list.Posicion++, valValor);

                for (int i = 1; i < Collection.Count(); i++)
                {
                    valor    = Collection.ElementAt(i);
                    valValor = valor.GetValor(e, log, errores);

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

                        if (list.Tipo.Valor.Equals(valor.Tipo))
                        {
                            list.Insert(list.Posicion++, valValor);
                        }
                        else
                        {
                            Casteo cast = new Casteo(list.Tipo.Valor, new Literal(valor.Tipo, valValor, 0, 0), 0, 0)
                            {
                                Mostrar = false
                            };

                            valValor = cast.GetValor(e, log, errores);

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

                                list.Insert(list.Posicion++, valValor);
                                continue;
                            }
                            errores.AddLast(new Error("Semántico", "El tipo no coinciden con el valor del List.", Linea, Columna));
                        }
                        //continue;
                    }
                    //return null;
                }

                return(list);
            }
            return(null);
        }
Example #4
0
        public override object GetValor(Entorno e, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            BD actual = e.Master.Actual;

            if (actual != null)
            {
                Simbolo sim = actual.GetUserType(Id);
                if (sim != null)
                {
                    if (Atributos.Count() == ((Entorno)sim.Valor).Simbolos.Count())
                    {
                        LinkedList <Simbolo> sims = new LinkedList <Simbolo>();
                        for (int i = 0; i < Atributos.Count(); i++)
                        {
                            Simbolo   s       = ((Entorno)sim.Valor).Simbolos.ElementAt(i);
                            Expresion expr    = Atributos.ElementAt(i);
                            object    valExpr = expr.GetValor(e, log, errores);

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

                                if (s.Tipo.Equals(expr.Tipo))
                                {
                                    sims.AddLast(new Simbolo(s.Tipo, Rol.ATRIBUTO, s.Id, valExpr));
                                    continue;
                                }
                                else
                                {
                                    if (s.Tipo.IsCollection() && expr.Tipo.IsCollection())
                                    {
                                        if (s.Tipo.EqualsCollection(expr.Tipo))
                                        {/*verificar mas tipos*/
                                            sims.AddLast(new Simbolo(s.Tipo, Rol.ATRIBUTO, s.Id, valExpr));
                                            continue;
                                        }
                                    }
                                    else
                                    {
                                        Casteo cast = new Casteo(s.Tipo, new Literal(expr.Tipo, valExpr, 0, 0), 0, 0)
                                        {
                                            Mostrar = false
                                        };
                                        valExpr = cast.GetValor(e, log, errores);

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

                                            sims.AddLast(new Simbolo(s.Tipo, Rol.ATRIBUTO, s.Id, valExpr));
                                            continue;
                                        }
                                    }
                                }
                            }

                            errores.AddLast(new Error("Semántico", "Los valores no coinciden con el User Type.", Linea, Columna));
                            return(null);
                        }
                        Tipo = new Tipo(Id.ToLower());
                        return(new Objeto(Id.ToLower(), new Entorno(null, sims)));
                    }
                    else
                    {
                        errores.AddLast(new Error("Semántico", "Los valores no coinciden con el User Type.", Linea, Columna));
                    }
                }
                else
                {
                    errores.AddLast(new Error("Semántico", "No existe un User Type con el id: " + Id + " en la base de datos.", Linea, Columna));
                }
            }
            else
            {
                errores.AddLast(new Error("Semántico", "No se ha seleccionado una base de datos, no se pudo buscar el User Type.", Linea, Columna));
            }

            return(null);
        }
Example #5
0
        public override object GetValor(Entorno e, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            string  firma = Id;
            Entorno local = new Entorno(e.Global);

            LinkedList <Literal> parametros = new LinkedList <Literal>();

            if (Id.ToLower().Equals("today"))
            {
                if (Parametro != null)
                {
                    errores.AddLast(new Error("Semántico", "La función nativa today no necesita parámetros.", Linea, Columna));
                }

                Tipo = new Tipo(Type.DATE);
                DateTime date = DateTime.Now;
                return(new Date(date.Year + "-" + date.Month + "-" + date.Day));
            }
            else if (Id.ToLower().Equals("now"))
            {
                if (Parametro != null)
                {
                    errores.AddLast(new Error("Semántico", "La función nativa now no necesita parámetros.", Linea, Columna));
                }

                Tipo = new Tipo(Type.TIME);
                DateTime date = DateTime.Now;
                return(new Time(date.Hour + ":" + date.Minute + ":" + date.Second));
            }

            if (Parametro != null)
            {
                foreach (Expresion expr in Parametro)
                {
                    object valExpr = expr.GetValor(e, log, errores);
                    if (valExpr != null)
                    {
                        if (valExpr is Throw)
                        {
                            return(valExpr);
                        }

                        firma += "-" + expr.Tipo.Type.ToString();
                        parametros.AddLast(new Literal(expr.Tipo, valExpr, 0, 0));
                        continue;
                    }
                    return(null);
                }
            }

            Simbolo sim = e.GetFuncion(firma);

            if (sim != null)
            {
                Funcion fun = (Funcion)sim.Valor;

                if (Parametro != null)
                {
                    for (int i = 0; i < parametros.Count(); i++)
                    {
                        local.Add(new Simbolo(parametros.ElementAt(i).Tipo, Rol.VARIABLE, fun.Parametro.ElementAt(i).Id, parametros.ElementAt(i).Valor));
                    }
                }
                object obj = fun.Bloque.Ejecutar(local, true, false, false, false, log, errores);

                if (obj != null)
                {
                    if (obj is Return ret)
                    {
                        if (!ret.Error)
                        {
                            if (ret.Valores == null)
                            {
                                if (ret.Valor != null)
                                {
                                    Tipo = ret.Valor.Tipo;

                                    if (Tipo.IsNull())
                                    {
                                        if (sim.Tipo.IsNullable())
                                        {
                                            return(ret.Valor.Valor);
                                        }
                                    }

                                    if (Tipo.Equals(sim.Tipo))
                                    {
                                        return(ret.Valor.Valor);
                                    }
                                    else
                                    {
                                        if (sim.Tipo.IsCollection() && ret.Valor.Tipo.IsCollection())
                                        {
                                            if (sim.Tipo.EqualsCollection(ret.Valor.Tipo))
                                            {
                                                return(ret.Valor.Valor);
                                            }
                                        }
                                        else
                                        {
                                            Casteo cast = new Casteo(sim.Tipo, ret.Valor, 0, 0)
                                            {
                                                Mostrar = false
                                            };

                                            object valCast = cast.GetValor(e, log, errores);

                                            if (valCast != null)
                                            {
                                                if (!(valCast is Throw))
                                                {
                                                    Tipo = cast.Tipo;
                                                    return(valCast);
                                                }
                                            }
                                        }

                                        errores.AddLast(new Error("Semántico", "Se esperaba un valor en return de tipo: " + sim.Tipo.Type.ToString() + ".", ret.Linea, ret.Columna));
                                        return(null);
                                    }
                                }
                                else
                                {
                                    errores.AddLast(new Error("Semántico", "Se esperaba un valor en return.", ret.Linea, ret.Columna));
                                }
                            }
                            else
                            {
                                errores.AddLast(new Error("Semántico", "No se esperaba una lista de expresiones en return.", ret.Linea, ret.Columna));
                            }
                        }
                        return(null);
                    }

                    if (obj is Throw)
                    {
                        return(obj);
                    }
                }

                if (IsExpresion)
                {
                    errores.AddLast(new Error("Semántico", "Se esperaba un return en funcion " + Id + ".", Linea, Columna));
                }
                return(null);
            }

            errores.AddLast(new Error("Semántico", "No se ha definico una funcion con la firma: " + firma.ToLower() + ".", Linea, Columna));
            return(null);
        }
Example #6
0
        public override object GetValor(Entorno e, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            Entorno local = new Entorno(e.Global); /*********/

            Simbolo sim;

            if (Simbolo != null)
            {
                sim = Simbolo;
            }
            else
            {
                object obj = GetSimbolo(e, log, errores);

                if (obj is Throw)
                {
                    return(obj);
                }

                sim = (Simbolo)obj;
            }

            if (sim != null)
            {
                Procedimiento proc = (Procedimiento)sim.Valor;

                if (Parametro != null)
                {
                    for (int i = 0; i < Parametros.Count(); i++)
                    {
                        local.Add(new Simbolo(Parametros.ElementAt(i).Tipo, Rol.VARIABLE, proc.Parametro.ElementAt(i).Id, Parametros.ElementAt(i).Valor));
                    }
                }

                object obj = proc.Bloque.Ejecutar(local, true, false, false, false, log, errores);

                if (obj != null)
                {
                    if (obj is Return ret)
                    {
                        if (!ret.Error)
                        {
                            if (proc.Retorno != null)
                            {
                                if (ret.Valor != null)
                                {
                                    if (proc.Retorno.Count() == 1)
                                    {
                                        if (ret.Valor.Tipo.IsNull())
                                        {
                                            if (proc.Retorno.ElementAt(0).Tipo.IsNullable())
                                            {
                                                LinkedList <Literal> valores = new LinkedList <Literal>();
                                                valores.AddLast(ret.Valor);
                                                return(valores);
                                            }
                                        }

                                        if (ret.Valor.Tipo.Equals(proc.Retorno.ElementAt(0).Tipo))
                                        {
                                            LinkedList <Literal> valores = new LinkedList <Literal>();
                                            valores.AddLast(ret.Valor);
                                            return(valores);
                                        }
                                        else
                                        {
                                            /*Agregar collections*/
                                            if (ret.Valor.Tipo.IsCollection() && proc.Retorno.ElementAt(0).Tipo.IsCollection())
                                            {
                                                if (ret.Valor.Tipo.EqualsCollection(proc.Retorno.ElementAt(0).Tipo))
                                                {
                                                    LinkedList <Literal> valores = new LinkedList <Literal>();
                                                    valores.AddLast(ret.Valor);
                                                    return(valores);
                                                }
                                            }
                                            else
                                            {
                                                Casteo cast = new Casteo(proc.Retorno.ElementAt(0).Tipo, ret.Valor, 0, 0)
                                                {
                                                    Mostrar = false
                                                };

                                                object valExpr = cast.GetValor(e, log, errores);

                                                if (valExpr != null)
                                                {
                                                    if (!(valExpr is Throw))
                                                    {
                                                        LinkedList <Literal> valores = new LinkedList <Literal>();
                                                        valores.AddLast(new Literal(cast.Tipo, valExpr, 0, 0));
                                                        return(valores);
                                                    }
                                                }
                                            }

                                            errores.AddLast(new Error("Semántico", "Los Tipos de los valores del Return no coinciden con los del Procedimiento.", ret.Linea, ret.Columna));
                                            return(null);
                                        }
                                    }
                                    else
                                    {
                                        return(new Throw("NumberReturnsException", Linea, Columna));
                                    }
                                    //errores.AddLast(new Error("Semántico", "Los valores del Return no coinciden con los del Procedimiento.", ret.Linea, ret.Columna));
                                }
                                else if (ret.Valores != null)
                                {
                                    if (proc.Retorno.Count() == ret.Valores.Count())
                                    {
                                        for (int i = 0; i < proc.Retorno.Count(); i++)
                                        {
                                            if (!proc.Retorno.ElementAt(i).Tipo.Equals(ret.Valores.ElementAt(i).Tipo))
                                            {
                                                Casteo cast = new Casteo(proc.Retorno.ElementAt(0).Tipo, ret.Valores.ElementAt(i), 0, 0)
                                                {
                                                    Mostrar = false
                                                };

                                                object valExpr = cast.GetValor(e, log, errores);

                                                if (valExpr != null)
                                                {
                                                    ret.Valores.ElementAt(i).Tipo  = cast.Tipo;
                                                    ret.Valores.ElementAt(i).Valor = valExpr;
                                                }
                                                else
                                                {
                                                    errores.AddLast(new Error("Semántico", "Los Tipos de los valores del Return no coinciden con los del Procedimiento.", ret.Linea, ret.Columna));
                                                    return(null);
                                                }
                                            }
                                        }
                                        return(ret.Valores);
                                    }
                                    else
                                    {
                                        return(new Throw("NumberReturnsException", Linea, Columna));
                                    }
                                    //errores.AddLast(new Error("Semántico", "Los valores del Return no coinciden con los del Procedimiento.", ret.Linea, ret.Columna));
                                }
                                else
                                {
                                    return(new Throw("NumberReturnsException", Linea, Columna));
                                }
                                //errores.AddLast(new Error("Semántico", "Se esperaba valor en Return.", ret.Linea, ret.Columna));
                            }
                            else
                            {
                                if (ret.Valor != null || ret.Valores != null)
                                {
                                    errores.AddLast(new Error("Semántico", "No se esperaba valor en Return.", ret.Linea, ret.Columna));
                                }
                            }
                        }
                        return(null);
                    }

                    if (obj is Throw)
                    {
                        return(obj);
                    }
                }

                if (proc.Retorno != null)
                {
                    if (proc.Retorno.Count() > 0)
                    {
                        errores.AddLast(new Error("Semántico", "Se esperaba Return en Procedimiento.", Linea, Columna));
                    }
                }

                return(null);
            }

            return(null);
        }
Example #7
0
        public override object GetValor(Entorno e, LinkedList <Salida> log, LinkedList <Error> errores)
        {
            Expresion valor    = Collection.ElementAt(0);
            object    valValor = valor.GetValor(e, log, errores);

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

                Tipo = new Tipo(Type.SET, valor.Tipo);

                Collection set = new Collection(new Tipo(Type.SET, valor.Tipo));
                set.Insert(set.Posicion++, valValor);

                for (int i = 1; i < Collection.Count(); i++)
                {
                    valor    = Collection.ElementAt(i);
                    valValor = valor.GetValor(e, log, errores);

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

                        if (set.Tipo.Valor.Equals(valor.Tipo))
                        {
                            if (!set.Contains(valValor))
                            {
                                set.Insert(set.Posicion++, valValor);
                            }
                            else
                            {
                                errores.AddLast(new Error("Semántico", "Ya existe el valor: " + valValor.ToString() + " en el Set.", Linea, Columna));
                            }
                        }
                        else
                        {
                            Casteo cast = new Casteo(set.Tipo.Valor, new Literal(valor.Tipo, valValor, 0, 0), 0, 0)
                            {
                                Mostrar = false
                            };

                            valValor = cast.GetValor(e, log, errores);

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

                                if (!set.Contains(valValor))
                                {
                                    set.Insert(set.Posicion++, valValor);
                                }
                                else
                                {
                                    errores.AddLast(new Error("Semántico", "Ya existe el valor: " + valValor.ToString() + " en el Set.", Linea, Columna));
                                }

                                continue;
                            }

                            errores.AddLast(new Error("Semántico", "El tipo no coinciden con el valor del Set.", Linea, Columna));
                        }
                        //continue;
                    }
                    //return null;
                }

                set.Ordenar();

                return(set);
            }
            return(null);
        }