Esempio n. 1
0
        public static nodo_expresion ejecutar_sentencia_control(funcion funcion)
        {
            variables variables = new variables();

            variables_actuales.Push(variables);
            funcion_actual.Push(funcion);
            foreach (sentencia s in funcion.sentencias)
            {
                nodo_expresion respuesta = ejecutar_sentencia(s);
                if (respuesta.rol.Equals("retorno"))
                {
                    variables_actuales.Pop();
                    funcion_actual.Pop();
                    return(respuesta);
                }
                else if (respuesta.rol.Equals("detener"))
                {
                    variables_actuales.Pop();
                    funcion_actual.Pop();
                    return(respuesta);
                }
                else if (respuesta.rol.Equals("continuar"))
                {
                    variables_actuales.Pop();
                    funcion_actual.Pop();
                    return(respuesta);
                }
            }
            variables_actuales.Pop();
            funcion_actual.Pop();
            return(@const.VOID);
        }
Esempio n. 2
0
        public static nodo_expresion ejecutar_flujo(funcion funcion, List <arbol_expresion> parametros)
        {
            variables variables = new variables();

            variables_actuales.Push(variables);
            funcion_actual.Push(funcion);

            //DECLARAR PARAMETROS AUN NO HECHA
            int indice = 0;

            foreach (String parametro in funcion.parametros)
            {
                String tipo = parametro.Split(',')[0].ToLower();
                String id   = parametro.Split(',')[1];

                //nodo_expresion valor = parametros.ElementAt(indice).ejecutar_arbol();
                nodo_expresion valor = parametros.ElementAt(indice).ejecutar_arbol();
                if (valor.tipo.Equals("error"))
                {
                    return(new nodo_expresion("Error Semantico", "Parametro incorrecto", "error", -1, -1));
                }
                else
                {
                    variables_actuales.Peek().add_variable(tipo, id, valor.valor);
                }
                indice++;
            }

            foreach (sentencia s in funcion.sentencias)
            {
                nodo_expresion respuesta = ejecutar_sentencia(s);
                if (respuesta.rol.Equals("retorno"))
                {
                    if (respuesta.tipo.Equals(funcion.tipo.ToLower()))
                    {
                        variables_actuales.Pop();
                        funcion_actual.Pop();
                        return(respuesta);
                    }
                    else
                    {
                        errores.errores.add_error("Error Semantico", "Error en retorno de tipo " + respuesta.tipo + " en funcion \"" + funcion.nombre.Split('#')[0] + "\" de tipo " + funcion.tipo, s.fila, s.columna);
                        variables_actuales.Pop();
                        funcion_actual.Pop();
                        return(new nodo_expresion("error", "error", "error", s.fila, s.columna));
                    }
                }
                else if (respuesta.rol.Equals("continuar") || respuesta.rol.Equals("detener"))
                {
                    errores.errores.add_error("Error Semantico", "Sentencia " + respuesta.rol + " fuera de ciclo, en funcion \"" + funcion.nombre.Split('#')[0] + "\" de tipo " + funcion.tipo, s.fila, s.columna);
                    variables_actuales.Pop();
                    funcion_actual.Pop();
                    return(new nodo_expresion("error", "error", "error", s.fila, s.columna));
                }
            }

            //reporte de variables
            //foreach (variable variable in variables_actuales.Peek().lista) {
            //    Console.WriteLine(variable.tipo + " " + variable.nombre + " " + variable.valor);
            //}
            if ([email protected])
            {
                variables_actuales.Pop();
            }
            else
            {
                funcion.variables = variables_actuales.Pop();
            }
            funcion_actual.Pop();


            if ("void".Equals(funcion.tipo.ToLower()))
            {
                return(@const.VOID);
            }
            else
            {
                errores.errores.add_error("Error Semantico", "Error en retorno de tipo " + "void" + " en funcion \"" + funcion.nombre.Split('#')[0] + "\" de tipo " + funcion.tipo, funcion.sentencias.Last().fila, funcion.sentencias.Last().columna);
                return(new nodo_expresion("error", "error", "error", funcion.sentencias.Last().fila, funcion.sentencias.Last().columna));
            }
        }