예제 #1
0
        public String Generar3DInit()
        {
            String temp = TitusTools.GetTemp();
            String init = "void init_" + this.Nombre + "(){\n";

            init += "\t\t" + temp + " = H;\n";
            int sizeherencia = Ambito.Tamaño;

            String init3 = "";

            foreach (Simbolo sim in Ambito.TablaSimbolo)
            {
                if (sim.Rol.Equals(Constante.DECLARACION))
                {
                    FDeclaracion decla = (FDeclaracion)sim.Valor;
                    init3 += decla.Generar3DInit(temp, 0);
                }
            }

            //buscamos los init de los hereda

            if (!Herencia.Equals(""))
            {
                String herencia = Herencia;
                while (herencia != "")
                {
                    Simbolo clase = Padre.BuscarClase(herencia, ArchivoPadre);
                    if (clase != null)
                    {
                        FClase nuevaclase = (FClase)clase.Valor;
                        foreach (Simbolo sim in nuevaclase.Ambito.TablaSimbolo)
                        {
                            if (sim.Rol.Equals(Constante.DECLARACION))
                            {
                                FDeclaracion decla = (FDeclaracion)sim.Valor;
                                init3 += decla.Generar3DInit(temp, sizeherencia);
                            }
                        }
                        sizeherencia += nuevaclase.Ambito.Tamaño;
                        herencia      = nuevaclase.Herencia;
                    }
                    else
                    {
                        TitusTools.InsertarError(Constante.TErrorSemantico, "No se encontro la clase para heredar " + herencia, TitusTools.GetRuta(), Padre.Fila, Padre.Columna);
                        break;
                    }
                }
            }

            String init2 = "\t\t" + "H = H + " + sizeherencia.ToString() + ";\n";

            init += init2 + init3;

            init += "}\n\n";
            return(init);
        }
예제 #2
0
        public Nodo3D Generar3DSuperAsignacion(String temporal)
        {
            Nodo3D nodo = new Nodo3D();

            Simbolo sim = Padre.BuscarVariable(this.Nombre);


            if (sim != null)
            {
                FDeclaracion decla = (FDeclaracion)sim.Valor;

                if (decla.Dimensiones.Count == this.Dimensiones.Count)
                {
                    nodo.Tipo = sim.Tipo;


                    String heap = TitusTools.GetTemp();
                    nodo.Valor   = TitusTools.GetTemp();
                    nodo.Codigo += "\t\t" + heap + " = " + temporal + " + " + sim.Posicion.ToString() + ";//posicion de la variable " + sim.Nombre + "\n";
                    nodo.Codigo += "\t\t" + nodo.Valor + " = Heap[" + heap + "];\n";


                    String tempAcceso    = TitusTools.GetTemp();
                    String cadenaArreglo = "";
                    String etqError      = TitusTools.GetEtq();
                    String etqSalida     = TitusTools.GetEtq();
                    cadenaArreglo += "\t\t" + tempAcceso + " = Heap[" + nodo.Valor + "];//acceso a las dimensiones\n";
                    cadenaArreglo += "\t\t" + "ifFalse " + tempAcceso + " == " + this.Dimensiones.Count.ToString() + " goto " + etqError + ";\n";
                    cadenaArreglo += "\t\t" + nodo.Valor + " = " + nodo.Valor + " + 1;\n";

                    String mapeo = TitusTools.GetTemp();

                    String dsize = TitusTools.GetTemp();

                    String indice = TitusTools.GetTemp();

                    cadenaArreglo += "\t\t" + mapeo + " = 0;\n";
                    int i = 0;
                    foreach (FNodoExpresion d in Dimensiones)
                    {
                        Nodo3D dtemp = d.Generar3D();
                        if (dtemp.Tipo.Equals(Constante.TEntero) && !TitusTools.HayErrores())
                        {
                            cadenaArreglo += dtemp.Codigo;
                            cadenaArreglo += "\t\t" + dsize + " = Heap[" + nodo.Valor + "];\n";
                            cadenaArreglo += "\t\t" + indice + " = " + dsize + " - 1;\n";
                            cadenaArreglo += "\t\t" + nodo.Valor + " = " + nodo.Valor + " + 1;\n";
                            cadenaArreglo += "\t\t" + "ifFalse " + dtemp.Valor + " >= 0 goto " + etqError + ";\n";
                            cadenaArreglo += "\t\t" + "ifFalse " + dtemp.Valor + " <= " + indice + " goto " + etqError + ";\n";
                            if (i > 0)
                            {
                                cadenaArreglo += "\t\t" + mapeo + " = " + mapeo + " * " + dsize + ";\n";
                            }

                            cadenaArreglo += "\t\t" + mapeo + " = " + mapeo + " + " + dtemp.Valor + ";\n";
                        }
                        else
                        {
                            TitusTools.InsertarError(Constante.TErrorSemantico, "Solo se puede acceder al arreglo " + this.Nombre + " con un tipo entero no un tipo " + dtemp.Tipo, TitusTools.GetRuta(), this.Fila, this.Columna);
                        }

                        i++;
                    }

                    cadenaArreglo += "\t\t" + "goto " + etqSalida + ";\n";
                    cadenaArreglo += "\t" + etqError + ":\n";
                    cadenaArreglo += "\t\t" + "Error(1);\n";
                    cadenaArreglo += "\t" + etqSalida + ":\n";
                    cadenaArreglo += "\t\t" + nodo.Valor + " = " + nodo.Valor + " + " + mapeo + ";//posicion lexicografica\n";

                    nodo.Valor = "Heap[" + nodo.Valor + "]";

                    nodo.Codigo += cadenaArreglo;
                }
                else
                {
                    TitusTools.InsertarError(Constante.TErrorSemantico, "El arreglo " + this.Nombre + ", tiene " + decla.Dimensiones.Count.ToString() + " dimensiones no " + this.Dimensiones.Count.ToString(), TitusTools.GetRuta(), this.Fila, this.Columna);
                }
            }
            else
            {
                TitusTools.InsertarError(Constante.TErrorSemantico, "No se encontro la variable " + this.Nombre, TitusTools.GetRuta(), this.Fila, this.Columna);
            }

            return(nodo);
        }