示例#1
0
        public String analizar(String entrada)
        {
            Gramatica.Gramatica gramatica = new Gramatica.Gramatica();
            LanguageData        lenguaje  = new LanguageData(gramatica);
            Parser        parser          = new Parser(lenguaje);
            ParseTree     arbol           = parser.Parse(entrada);
            ParseTreeNode raiz            = arbol.Root;
            string        respuesta       = "";

            if (raiz != null)
            {
                Graficador.Graficador grafo = new Graficador.Graficador();
                grafo.graficar(raiz);
                AST_LUP          ast   = new AST_LUP();
                LinkedList <LUP> lista = ast.Construr(raiz);

                foreach (LUP lup in lista)
                {
                    if (lup.tipo.Equals("query"))
                    {
                        AnalizadorCQL cql = new AnalizadorCQL();
                        cql.Analizar(lup.data);
                        foreach (String men in Estatico.mensajes)
                        {
                            respuesta += men;
                        }
                    }
                    else if (lup.tipo.Equals("login"))
                    {
                        respuesta = "[+LOGIN]SUCCESS[-LOGIN]";
                    }
                    else if (lup.tipo.Equals("logout"))
                    {
                        respuesta = "[+LOGOUT]SUCCESS[-LOGOUT]";
                    }
                    else if (lup.tipo.Equals("bases"))
                    {
                        respuesta = "[+message]SE PIDIO BASES[-message]";
                    }
                }
            }
            else
            {
                respuesta = "[+message]SE PIDIO BASES[-message]";
            }
            return(respuesta);
        }
        public void Analizar(String entrada)
        {
            GramaticaCQL  gramatica = new GramaticaCQL();
            LanguageData  lenguaje  = new LanguageData(gramatica);
            Parser        parser    = new Parser(lenguaje);
            ParseTree     arbol     = parser.Parse(entrada);
            ParseTreeNode raiz      = arbol.Root;

            Estatico.errores  = new List <ErrorCQL>();
            Estatico.mensajes = new List <String>();
            Estatico.servidor = new Servidor();
            obteErroes(arbol);


            if (raiz != null)
            {
                Graficador.Graficador grafo = new Graficador.Graficador();
                grafo.graficar(raiz);
                ConstruirAST constructor = new ConstruirAST(raiz);
                AST          arbolAst    = constructor.generarAst();
                Entorno      ent         = new Entorno(null);

                //-------- Prueba;
                BaseDatos prueba = new BaseDatos("prueba");
                Estatico.servidor.nuevaBase("prueba", prueba);
                Usuario admin = new Usuario("admin", "admin");
                Estatico.actualUsuario = admin;

                foreach (NodoAST sentencia in arbolAst.arbol)
                {
                    if (sentencia is Instruccion)
                    {
                        if (sentencia is Funcion)
                        {
                            Funcion fun = (Funcion)sentencia;

                            ent.agregar(fun.identificador, fun);
                        }
                    }
                    else if (sentencia is Expresion)
                    {
                    }
                }

                foreach (NodoAST sentencia in arbolAst.arbol)
                {
                    if (sentencia is Instruccion)
                    {
                        if (!(sentencia is Funcion))
                        {
                            Instruccion ins   = (Instruccion)sentencia;
                            object      valor = ins.ejecutar(ent);
                        }
                    }
                    else if (sentencia is Expresion)
                    {
                        Expresion exp   = (Expresion)sentencia;
                        object    valor = exp.getValor(ent);
                    }
                }

                //por el momento modificar al final


                ReporteErrores reporte = new ReporteErrores(Estatico.errores);
                reporte.writeReport();
            }
            else
            {
                Estatico.agregarMensaje("[+MESSAGE]raiz nula[-MESSAGE]");
                //MessageBox.Show("raiznula");
            }
        }