Beispiel #1
0
        public override string ToString()
        {
            String cad     = "{ ";
            bool   primero = true;

            foreach (DictionaryEntry item in this.atributos.tabla)
            {
                Simbolo sim = (Simbolo)(item.Value);
                if (primero)
                {
                    cad    += sim.identificador + " : " + sim.valor;
                    primero = false;
                }
                else
                {
                    cad += ", " + sim.identificador + " : " + sim.valor;
                }
            }
            cad += "} AS " + this.tipo.tipo;
            return(cad);
        }
Beispiel #2
0
        public bool existeEnActual(String id)
        {
            Simbolo encontrado = (Simbolo)(this.tabla[id]);

            return(encontrado != null);
        }
Beispiel #3
0
 public void agregar(String id, Simbolo simbolo)
 {
     this.tabla.Add(id, simbolo);
 }
        public object ejecutar(Entorno ent)
        {
            foreach (Simbolo variable in variables)
            {
                string nombreVariable = variable.identificador.ToLower();
                if (tieneValorInicial())
                {
                    Tipo tipoVal = valorInicial.getTipo(ent);
                    Tipo tipoVar = variable.tipo;
                    if (ent.existeEnActual(nombreVariable))
                    {
                        Estatico.errores.Add(new ErrorCQL("Semantico", "La variable: " + nombreVariable + " ya existe ", this.fila, this.columna));
                    }
                    else
                    {
                        Simbolo sim_nuevo = new Simbolo(variable.identificador);
                        sim_nuevo.tipo = tipoVal;
                        if (tipoVal.tipo.Equals(tipoVar.tipo))
                        {
                            Object val = valorInicial.getValor(ent);
                            if (val is Objeto)
                            {
                            }
                            sim_nuevo.valor = val;

                            ent.agregar(nombreVariable, sim_nuevo);
                        }
                        else if (tipoVal.tipo.Equals("int") && tipoVar.tipo.Equals("double"))
                        {
                            int    valor  = (int)valorInicial.getValor(ent);
                            double valor2 = Convert.ToDouble(valor);
                            sim_nuevo.valor = valor2;
                            ent.agregar(nombreVariable, sim_nuevo);
                        }
                        else if (tipoVar.tipo.Equals("int") && tipoVal.tipo.Equals("double"))
                        {
                            double valor  = (double)valorInicial.getValor(ent);
                            int    valor2 = Convert.ToInt32(valor);
                            sim_nuevo.valor = valor2;
                            ent.agregar(nombreVariable, sim_nuevo);
                        }
                        else if ((!(tipoVar.tipo.Equals("int") || tipoVar.tipo.Equals("double") || tipoVar.tipo.Equals("bool"))) && tipoVal.tipo.Equals("null"))
                        {
                            sim_nuevo.valor = new Nulo();
                            ent.agregar(nombreVariable, sim_nuevo);
                        }
                        else
                        {
                            Estatico.errores.Add(new ErrorCQL("Semantico", "Error de tipos en la variable: " + nombreVariable + " de tipo " + tipoVar.tipo + " se intento poner tipo: " + tipoVal.tipo, this.fila, this.columna));
                        }
                    }
                }
                else
                {
                    if (ent.existeEnActual(nombreVariable))
                    {
                        Estatico.errores.Add(new ErrorCQL("Semantico", "La variable: " + nombreVariable + " ya existe ", this.fila, this.columna));
                    }
                    else
                    {
                        Tipo    tipov     = variable.tipo;
                        bool    agreegar  = true;
                        Simbolo sim_nuevo = new Simbolo(variable.identificador);
                        sim_nuevo.tipo = tipov;
                        if (tipov.tipo.Equals("int"))
                        {
                            sim_nuevo.valor = (int)0;
                        }
                        else if (tipov.tipo.Equals("double"))
                        {
                            sim_nuevo.valor = (double)0.0;
                        }
                        else if (tipov.tipo.Equals("bool"))
                        {
                            sim_nuevo.valor = false;
                        }
                        else if (tipov.tipo.Equals("string") || tipov.tipo.Equals("date") || tipov.tipo.Equals("time") || tipov.tipo.Equals("map") || tipov.tipo.Equals("set") || tipov.tipo.Equals("list"))
                        {
                            sim_nuevo.valor = new Nulo();
                        }
                        else
                        {
                            if (Estatico.actualBase != null)
                            {
                                if (Estatico.actualBase.existeObjetoDefinido(tipov.tipo))
                                {
                                    sim_nuevo.valor = new Nulo();
                                }
                                else
                                {
                                    Estatico.errores.Add(new ErrorCQL("Ejecucion", "No existe el objeto: " + tipov.tipo + " en la base: " + Estatico.actualBase.nombre, this.fila, this.columna));
                                    agreegar = false;
                                }
                            }
                            else
                            {
                                Estatico.errores.Add(new ErrorCQL("Ejecucion", "No hay base en uso ", this.fila, this.columna));
                                agreegar = false;
                            }
                        }
                        if (agreegar)
                        {
                            ent.agregar(nombreVariable, sim_nuevo);
                        }
                    }
                }
            }

            return(null);
        }
Beispiel #5
0
        public object ejecutar(Entorno ent)
        {
            object val = valor.getValor(ent);

            if (!accesoObjeto)
            {
                Tipo tipoVal = valor.getTipo(ent);
                Tipo tipoVar = ent.get(nombreVar).tipo;
                if (ent.existe(nombreVar))
                {
                    if (tipoVal.tipo.Equals(tipoVar.tipo))
                    {
                        //ent.get(nombreVar).valor = val;

                        ent.reemplazar(nombreVar, new Simbolo(nombreVar, tipoVar, val));
                    }
                    else if (tipoVal.tipo.Equals("int") && tipoVar.tipo.Equals("double"))
                    {
                        int    valor  = (int)val;
                        double valor2 = Convert.ToDouble(valor);
                        //ent.get(nombreVar).valor = valor2;
                        ent.reemplazar(nombreVar, new Simbolo(nombreVar, tipoVar, valor2));
                    }
                    else if (tipoVar.tipo.Equals("int") && tipoVal.tipo.Equals("double"))
                    {
                        double valor  = (double)val;
                        int    valor2 = Convert.ToInt32(valor);
                        //ent.get(nombreVar).valor = valor2;
                        ent.reemplazar(nombreVar, new Simbolo(nombreVar, tipoVar, valor2));
                    }
                    else if ((!(tipoVar.tipo.Equals("int") || tipoVar.tipo.Equals("double") || tipoVar.tipo.Equals("bool"))) && tipoVal.tipo.Equals("null"))
                    {
                        ent.reemplazar(nombreVar, new Simbolo(nombreVar, tipoVar, new Nulo()));
                    }
                    else
                    {
                        Estatico.errores.Add(new ErrorCQL("Semantico", "Error de tipos en la variable: " + nombreVar + " de tipo " + tipoVar + " se intento poner tipo: " + tipoVal, this.fila, this.columna));
                    }
                }
                else
                {
                    Estatico.errores.Add(new ErrorCQL("Semantico", "La variable: " + nombreVar + " no existe ", this.fila, this.columna));
                }
            }
            else
            {
                if (ent.existe(nombreVar))
                {
                    Simbolo sim = ent.get(nombreVar);

                    Object valor = sim.valor;
                    int    x     = 0;
                    for (x = 0; x < this.atributos.Count - 1; x++)
                    {
                        Expresion exp = atributos.ElementAt(x);

                        if (exp is Identificador)
                        {
                            if (valor is Objeto)
                            {
                                Objeto        ob  = (Objeto)valor;
                                Identificador ide = (Identificador)exp;

                                valor = ide.getValor(ob.atributos);
                            }
                        }
                    }
                    if (valor is Objeto)
                    {
                        Objeto    actual = (Objeto)valor;
                        Expresion exp;
                        if (atributos.Count == 1)
                        {
                            exp = atributos.ElementAt(0);
                        }
                        else
                        {
                            exp = atributos.ElementAt(x);
                        }

                        if (exp is Identificador)
                        {
                            Identificador ide = (Identificador)exp;
                            if (actual.atributos.existe(ide.identificador))
                            {
                                Tipo tipoVar = actual.atributos.get(ide.identificador).tipo;
                                Tipo tipoVal = this.valor.getTipo(ent);
                                if (tipoVal.tipo.Equals(tipoVar.tipo))
                                {
                                    //ent.get(nombreVar).valor = val;

                                    actual.atributos.reemplazar(ide.identificador, new Simbolo(ide.identificador, tipoVar, val));
                                }
                                else if (tipoVal.tipo.Equals("int") && tipoVar.tipo.Equals("double"))
                                {
                                    int    valo   = (int)val;
                                    double valor2 = Convert.ToDouble(valo);
                                    //ent.get(nombreVar).valor = valor2;
                                    actual.atributos.reemplazar(ide.identificador, new Simbolo(ide.identificador, tipoVar, valor2));
                                }
                                else if (tipoVar.tipo.Equals("int") && tipoVal.tipo.Equals("double"))
                                {
                                    double valo   = (double)val;
                                    int    valor2 = Convert.ToInt32(valo);
                                    //ent.get(nombreVar).valor = valor2;
                                    actual.atributos.reemplazar(ide.identificador, new Simbolo(ide.identificador, tipoVar, valor2));
                                }
                                else if ((!(tipoVar.tipo.Equals("int") || tipoVar.tipo.Equals("double") || tipoVar.tipo.Equals("bool"))) && tipoVal.tipo.Equals("null"))
                                {
                                    actual.atributos.reemplazar(ide.identificador, new Simbolo(ide.identificador, tipoVar, new Nulo()));
                                }
                                else
                                {
                                    Estatico.errores.Add(new ErrorCQL("Semantico", "Error de tipos en atributo de la variable " + nombreVar, this.fila, this.columna));
                                }
                            }

                            else
                            {
                                Estatico.errores.Add(new ErrorCQL("Semantico", "La variable: " + nombreVar + " no existe ", this.fila, this.columna));
                            }
                        }
                    }
                }
                else
                {
                    Estatico.errores.Add(new ErrorCQL("Semantico", "La variable: " + nombreVar + " no existe ", this.fila, this.columna));
                }
            }

            return(null);
        }