示例#1
0
        public itemValor getValor(elementoEntorno elementoEntor, token tipo)
        {
            itemValor retorno = new itemValor();

            retorno.setTypeNulo();


            if (hayErrores())
            {
                return(retorno);
            }

            if (lstAtributos.listaAtributos.Count == 4)
            {
                String item1 = lstAtributos.listaAtributos[0].nombretoken;
                String item2 = lstAtributos.listaAtributos[1].nombretoken;
                if (item1.Equals("nuevo") && item2.Equals("valId"))

                /*
                 |----------------------------
                 |   tNuevo + valId + sAbreParent + LST_VAL + sCierraParent
                 */
                {
                    /*
                     |--------------------------------------------------------------------------
                     | nuevo Objeto()
                     | nuevo valId()
                     |--------------------------------------------------------------------------
                     | tNuevo + valId + sAbreParent + LST_VAL + sCierraParent
                     | tengo que crear una nueva clase y cargar los valores globales con sus metdos, funciones, y validar constructores
                     | hay que buscar la clase primero
                     |
                     */

                    //token tokId = lstAtributos.getToken(1);
                    token         tokInstancia = lstAtributos.getToken(1);
                    elementoClase temp         = tablaSimbolos.getClase(tokInstancia);
                    if (temp != null)
                    {
                        objetoClase ObjClase    = new objetoClase(temp, tablaSimbolos);
                        lstValores  lstValores2 = new lstValores();
                        //ahora tengo que llamar al constructor, pero digamos que no tiene, jejejeje


                        if (hijos.Count > 0)
                        {
                            nodoModelo hijo   = hijos[0];
                            _LST_VAL   lstval = (_LST_VAL)hijo;
                            lstValores2 = lstval.getLstValores(elementoEntor);
                            //me tiene que devolver una lista de valores,
                        }

                        ObjClase.ejecutarGlobales(); //cargando sus valores globales
                                                     // jlk
                        ObjClase.ejecutarConstructor(lstAtributos.getToken(1), 0, lstValores2, ObjClase.tablaEntorno.raiz);
                        //println("ejecutando constructor de la claes, new objeto()");

                        retorno.setValue(ObjClase, lstAtributos.getToken(1).valLower);
                        retorno.setTypeObjeto(tokInstancia.valLower);
                        //println("Es un objeto");

                        return(retorno);
                    }
                    else
                    {
                        tablaSimbolos.tablaErrores.insertErrorSemantic("No se puede  instanaciar la clase:" + tokInstancia.valLower + ", para crear el objeto, debido a que no se existe la clase ", tokInstancia);
                    }


                    return(retorno);
                }
            }

            if (hijos.Count > 0)
            {
                nodoModelo hijo = hijos[0];

                switch (hijo.nombre)
                {
                case "PREGUNTA_NATIVA":

                    _PREGUNTA_NATIVA preg = (_PREGUNTA_NATIVA)hijo;

                    return(preg.getValor(elementoEntor));


                case "TIPO":
                    if (hayErrores())
                    {
                        return(retorno);
                    }

                    /*
                     |--------------------------------------------------------------------------
                     | ARREGLO
                     |--------------------------------------------------------------------------
                     | Hay que mapear las variables para inicializar el array valores de item
                     | Estoy definiendo las dimensiones del arreglo
                     | tNuevo + TIPO + LST_CORCHETES_VAL
                     |
                     |
                     | String[][] hola = new String[3][2];
                     |
                     | String[] jejej = new String[12];
                     | int[][] jeje = { new int[12], { 2, 2 } };
                     |
                     | int[][][] numeros = {{3,3,3},{2,2,2},{1,1,1}, {4,4,4},{5,5,5},{6,6,6}};
                     | hola = jejej;*/
                    nodoModelo tempTipo = getNodo("TIPO");
                    _TIPO      nodoTipo = (_TIPO)tempTipo;
                    retorno.setType(nodoTipo.getTipo().valLower);

                    token      item1 = lstAtributos.listaAtributos[0].tok;
                    nodoModelo temp1 = getNodo("LST_CORCHETES_VAL");
                    if (temp1 != null)
                    {
                        _LST_CORCHETES_VAL lstVal     = (_LST_CORCHETES_VAL)temp1;
                        List <int>         tempLstInt = lstVal.getLstInt(elementoEntor, item1);

                        int dimensionMaxima = 1;
                        foreach (int elemento in tempLstInt)
                        {
                            // println("dimen: " + elemento);
                            if (elemento != 0)
                            {
                                dimensionMaxima = dimensionMaxima * elemento;
                            }
                            else
                            {
                                tablaSimbolos.tablaErrores.insertErrorSemantic("No se puede inicializar una matriz con tamaño 0", item1);
                            }
                        }


                        //llenando la lista de nulos


                        Dictionary <int, itemValor> diccionario = new Dictionary <int, itemValor>();

                        for (int i = 0; i < dimensionMaxima; i++)
                        {
                            diccionario.Add(i, new itemValor());
                        }



                        retorno.setArrayTipo(tempLstInt, diccionario, tipo.valLower);



                        //println("La dimensión mapeada -> indice máximo es " + retorno.arrayValores.Count);
                        //tengo que mapear
                        //  sf
                    }



                    //println(itEntorno.nombre.valLower + "-> tNuevo + TIPO + LST_CORCHETES_VAL");
                    return(retorno);

                case "LST_LLAVES_VAL":

                    /*
                     |--------------------------------------------------------------------------
                     | ARREGLO
                     |--------------------------------------------------------------------------
                     | Le estoy enviando directamente los valores al arreglo
                     | LST_LLAVES_VAL esto retorna=Dictionary<int, itemValor>
                     |
                     */
                    nodoModelo      tempLstLlaves = getNodo("LST_LLAVES_VAL");
                    _LST_LLAVES_VAL nodoLstLlaves = (_LST_LLAVES_VAL)tempLstLlaves;


                    nodoLstLlaves.getArray(tipo, elementoEntor);
                    int arrayLengthMapeado = getDimensionMapeada(nodoLstLlaves.lstDimensiones, tipo);
                    if (arrayLengthMapeado == nodoLstLlaves.diccionario.Count)
                    //se puede agregar correctamente
                    {
                        itemValor retorno2 = new itemValor();
                        retorno2.setType(tipo.valLower);
                        retorno2.arrayValores = nodoLstLlaves.diccionario;
                        retorno2.dimensiones  = nodoLstLlaves.lstDimensiones;
                        return(retorno2);
                    }
                    else
                    {
                        println("Hay problema en las dimensiones del arreglo" + tipo.linea);
                    }



                    return(retorno);

                case "E":

                    /*
                     |--------------------------------------------------------------------------
                     | E
                     |--------------------------------------------------------------------------
                     */
                    _E ope = (_E)hijo;
                    return(ope.getValor(elementoEntor));

                default:
                    println(hijo.nombre + "->No se reconoció la producción :(");
                    return(retorno);
                }
            }
            else

            /*
             |----------------------------
             |   tNulo
             |   tEste
             */
            {
                String item1 = lstAtributos.listaAtributos[0].nombretoken;

                if (item1.Equals("tEste"))
                {
                    itemValor it = new itemValor();
                    it.setTypeObjeto(elementoEntor.este.cuerpoClase.nombreClase.valLower);
                    it.setValue(elementoEntor.este, elementoEntor.este.cuerpoClase.nombreClase.valLower);

                    return(it);
                }
                else
                {
                    /*
                     |--------------------------------------------------------------------------
                     | return nulo
                     |--------------------------------------------------------------------------
                     | tNulo
                     */

                    return(retorno);
                }
            }
        }
示例#2
0
        public nodoModelo getNodo(String nombreNoTerminal, tablaSimbolos tabla)
        {
            nodoModelo retorno = null;

            switch (nombreNoTerminal)
            {
            case "S":
                retorno = new _S(nombreNoTerminal, tabla);

                break;

            case "LST_IMPORT":
                retorno = new _LST_IMPORT(nombreNoTerminal, tabla);

                break;

            case "IMPORT":
                retorno = new _IMPORT(nombreNoTerminal, tabla);

                break;

            case "LST_CLASE":
                retorno = new _LST_CLASE(nombreNoTerminal, tabla);

                break;

            case "CLASE":
                retorno = new _CLASE(nombreNoTerminal, tabla);

                break;

            case "TIPO":
                retorno = new _TIPO(nombreNoTerminal, tabla);

                break;

            case "EXTENDER":
                retorno = new _EXTENDER(nombreNoTerminal, tabla);

                break;

            case "VISIBILIDAD":
                retorno = new _VISIBILIDAD(nombreNoTerminal, tabla);

                break;

            case "LST_PARAMETROS":
                retorno = new _LST_PARAMETROS(nombreNoTerminal, tabla);

                break;

            case "PARAMETRO":
                retorno = new _PARAMETRO(nombreNoTerminal, tabla);

                break;

            case "LST_VAL":
                retorno = new _LST_VAL(nombreNoTerminal, tabla);

                break;

            case "CP_CLASE":
                retorno = new _CP_CLASE(nombreNoTerminal, tabla);

                break;

            case "CUERPO_CLASE":
                retorno = new _CUERPO_CLASE(nombreNoTerminal, tabla);

                break;

            case "METODO":
                retorno = new _METODO(nombreNoTerminal, tabla);

                break;

            case "SOBRESCRITURA":
                retorno = new _SOBRESCRITURA(nombreNoTerminal, tabla);

                break;

            case "MAIN":
                retorno = new _MAIN(nombreNoTerminal, tabla);

                break;

            case "CONSTRUCTOR":
                retorno = new _CONSTRUCTOR(nombreNoTerminal, tabla);

                break;

            case "DECLARAR_VARIABLE_GLOBAL":
                retorno = new _DECLARAR_VARIABLE_GLOBAL(nombreNoTerminal, tabla);

                break;

            case "DECLARAR_VARIABLE_SINVISIBI":
                retorno = new _DECLARAR_VARIABLE_SINVISIBI(nombreNoTerminal, tabla);

                break;

            case "VAL":
                retorno = new _VAL(nombreNoTerminal, tabla);

                break;

            case "LST_LLAVES_VAL":
                retorno = new _LST_LLAVES_VAL(nombreNoTerminal, tabla);

                break;

            case "LLAVES_VAL_P":
                retorno = new _LLAVES_VAL_P(nombreNoTerminal, tabla);

                break;

            case "VAR_ARREGLO":
                retorno = new _VAR_ARREGLO(nombreNoTerminal, tabla);

                break;

            case "LST_CORCHETES":
                retorno = new _LST_CORCHETES(nombreNoTerminal, tabla);

                break;

            case "LST_CORCHETES_VAL":
                retorno = new _LST_CORCHETES_VAL(nombreNoTerminal, tabla);

                break;

            case "USAR_METO_VAR":
                retorno = new _USAR_METO_VAR(nombreNoTerminal, tabla);

                break;

            case "USAR_VARIABLEP":
                retorno = new _USAR_VARIABLEP(nombreNoTerminal, tabla);

                break;

            case "USAR_VARIABLE":
                retorno = new _USAR_VARIABLE(nombreNoTerminal, tabla);

                break;

            case "USAR_METODO":
                retorno = new _USAR_METODO(nombreNoTerminal, tabla);

                break;

            case "LLAMADA_FORMULARIO":
                retorno = new _LLAMADA_FORMULARIO(nombreNoTerminal, tabla);

                break;

            case "LST_CUERPO":
                retorno = new _LST_CUERPO(nombreNoTerminal, tabla);

                break;

            case "CUERPO":
                retorno = new _CUERPO(nombreNoTerminal, tabla);

                break;

            case "VALOR":
                retorno = new _VALOR(nombreNoTerminal, tabla);

                break;

            case "PAR_CORCHETES_VACIOS":
                retorno = new _PAR_CORCHETES_VACIOS(nombreNoTerminal, tabla);
                break;

            case "E":
                retorno = new _E(nombreNoTerminal, tabla);
                break;

            case "FUNCIONES_NATIVAS":
                retorno = new _FUNCIONES_NATIVAS(nombreNoTerminal, tabla);
                break;

            case "IMPRIMIR":
                retorno = new _IMPRIMIR(nombreNoTerminal, tabla);
                break;


            case "ID_VAR_FUNC":
                retorno = new _ID_VAR_FUNC(nombreNoTerminal, tabla);
                break;

            case "LST_PUNTOSP":
                retorno = new _LST_PUNTOSP(nombreNoTerminal, tabla);
                break;

            case "ASIG_VALOR":
                retorno = new _ASIG_VALOR(nombreNoTerminal, tabla);
                break;

            case "PAR_CORCHETES_VAL":
                retorno = new _PAR_CORCHETES_VAL(nombreNoTerminal, tabla);
                break;

            case "RETORNO":
                retorno = new _RETORNO(nombreNoTerminal, tabla);
                break;

            case "SI":
                retorno = new _SI(nombreNoTerminal, tabla);
                break;


            case "SINO_SI":
                retorno = new _SINO_SI(nombreNoTerminal, tabla);
                break;


            case "SINO":
                retorno = new _SINO(nombreNoTerminal, tabla);
                break;

            case "SENTENCIAS":
                retorno = new _SENTENCIAS(nombreNoTerminal, tabla);
                break;

            case "SI_SIMPLIFICADO":
                retorno = new _SI_SIMPLIFICADO(nombreNoTerminal, tabla);
                break;

            case "CASO":
                retorno = new _CASO(nombreNoTerminal, tabla);
                break;

            case "CUERPO_CASE":
                retorno = new _CUERPO_CASE(nombreNoTerminal, tabla);
                break;

            case "ROMPER":
                retorno = new _ROMPER(nombreNoTerminal, tabla);
                break;

            case "WHILE":
                retorno = new _WHILE(nombreNoTerminal, tabla);
                break;


            case "CONTINUAR":
                retorno = new _CONTINUAR(nombreNoTerminal, tabla);
                break;

            case "FOR":
                retorno = new _FOR(nombreNoTerminal, tabla);
                break;

            case "DOWHILE":
                retorno = new _DOWHILE(nombreNoTerminal, tabla);
                break;

            case "REPETIR":
                retorno = new _REPETIR(nombreNoTerminal, tabla);
                break;

            case "MENSAJE":
                retorno = new _MENSAJE(nombreNoTerminal, tabla);
                break;

            case "TO_CADENA":
                retorno = new _TO_CADENA(nombreNoTerminal, tabla);
                break;

            case "SUB_CAD":
                retorno = new _SUB_CAD(nombreNoTerminal, tabla);
                break;

            case "POS_CAD":
                retorno = new _POS_CAD(nombreNoTerminal, tabla);
                break;

            case "TO_BOOLEAN":
                retorno = new _TO_BOOLEAN(nombreNoTerminal, tabla);
                break;

            case "TO_ENTERO":
                retorno = new _TO_ENTERO(nombreNoTerminal, tabla);
                break;

            case "HOY":
                retorno = new _HOY(nombreNoTerminal, tabla);
                break;

            case "AHORA":
                retorno = new _AHORA(nombreNoTerminal, tabla);
                break;

            case "TO_FECHA":
                retorno = new _TO_FECHA(nombreNoTerminal, tabla);
                break;

            case "TO_HORA":
                retorno = new _TO_HORA(nombreNoTerminal, tabla);
                break;

            case "TO_FECHAHORA":
                retorno = new _TO_FECHAHORA(nombreNoTerminal, tabla);
                break;

            case "TAM":
                retorno = new _TAM(nombreNoTerminal, tabla);
                break;

            case "RANDOM":
                retorno = new _RANDOM(nombreNoTerminal, tabla);
                break;

            case "MIN":
                retorno = new _MIN(nombreNoTerminal, tabla);
                break;

            case "MAX":
                retorno = new _MAX(nombreNoTerminal, tabla);
                break;

            case "OPE_TIPO":
                retorno = new _OPE_TIPO(nombreNoTerminal, tabla);
                break;

            case "OPE_ARITME":
                retorno = new _OPE_ARITME(nombreNoTerminal, tabla);
                break;


            case "POTENCIA":
                retorno = new _POTENCIA(nombreNoTerminal, tabla);
                break;

            case "LOGARITMO":
                retorno = new _LOGARITMO(nombreNoTerminal, tabla);
                break;

            case "LOGARITMO10":
                retorno = new _LOGARITMO10(nombreNoTerminal, tabla);
                break;

            case "ABSOLUTO":
                retorno = new _ABSOLUTO(nombreNoTerminal, tabla);
                break;

            case "SENO":
                retorno = new _SENO(nombreNoTerminal, tabla);
                break;

            case "COSENO":
                retorno = new _COSENO(nombreNoTerminal, tabla);
                break;

            case "TANGENTE":
                retorno = new _TANGENTE(nombreNoTerminal, tabla);
                break;

            case "RAIZ":
                retorno = new _RAIZ(nombreNoTerminal, tabla);
                break;

            case "PI":
                retorno = new _PI(nombreNoTerminal, tabla);
                break;


            case "SUPER":
                retorno = new _SUPER(nombreNoTerminal, tabla);
                return(retorno);

            case "FORMULARIO":
                retorno = new _FORMULARIO(nombreNoTerminal, tabla);
                return(retorno);


            case "PREGUNTA":
                retorno = new _PREGUNTA(nombreNoTerminal, tabla);
                return(retorno);


            case "GRUPO":
                retorno = new _GRUPO(nombreNoTerminal, tabla);
                return(retorno);


            case "LST_CUERPO_PREGUNTA":
                retorno = new _LST_CUERPO_PREGUNTA(nombreNoTerminal, tabla);
                return(retorno);


            case "CUERPO_PREGUNTA":
                retorno = new _CUERPO_PREGUNTA(nombreNoTerminal, tabla);
                return(retorno);

            case "PREGUNTA_NATIVA":
                retorno = new _PREGUNTA_NATIVA(nombreNoTerminal, tabla);
                return(retorno);

            case "ESCRIBIR_ARCHIVO":
                retorno = new _ESCRIBIR_ARCHIVO(nombreNoTerminal, tabla);
                return(retorno);

            case "FUNC_MULTIMEDIA":
                retorno = new _FUNC_MULTIMEDIA(nombreNoTerminal, tabla);
                return(retorno);

            case "AUDIO":
                retorno = new _AUDIO(nombreNoTerminal, tabla);
                return(retorno);

            case "VIDEO":
                retorno = new _VIDEO(nombreNoTerminal, tabla);
                return(retorno);

            case "IMAGEN":
                retorno = new _IMAGEN(nombreNoTerminal, tabla);
                return(retorno);

            case "LEN":
                retorno = new _LEN(nombreNoTerminal, tabla);
                return(retorno);

            default:
                retorno = new nodoModelo("Desc_" + nombreNoTerminal, tabla);
                Console.WriteLine("[generarArbol]No se encontró el nodo:" + nombreNoTerminal);
                break;
            }

            return(retorno);
        }