Beispiel #1
0
        static nodo_expresion asignacion(sentencia sentencia)
        {
            nodo_expresion valor    = sentencia.expresion.ejecutar_arbol();
            String         id       = sentencia.ids.ElementAt(0);
            String         tipo     = valor.tipo;
            variable       variable = null;

            variable = buscar_variable(id);

            if (variable != null)
            {
                String tipo_id  = variable.tipo;
                String tipo_exp = valor.tipo;
                if (tipo.Equals("error"))
                {
                    return(@const.VOID);
                }
                if (tipo_id.Equals("number"))
                {
                    if (tipo_exp.Equals("string"))
                    {
                        errores.errores.add_error("Error Semantico", "casteo indefinido string a number", sentencia.fila, sentencia.columna);
                        return(@const.VOID);
                    }
                }
                else if (tipo_id.Equals("bool"))
                {
                    if (!tipo_exp.Equals("bool"))
                    {
                        errores.errores.add_error("Error Semantico", "casteo indefinido " + tipo_exp + " a bool", sentencia.fila, sentencia.columna);
                        return(@const.VOID);
                    }
                }

                variable.valor = valor.valor;
                return(@const.VOID);
            }
            else
            {
                //REPORTAR ERROR
                errores.errores.add_error("Error Semantico", "Variable \"" + id + "\" no definida", sentencia.fila, sentencia.columna);
                return(@const.VOID);
            }
        }
Beispiel #2
0
        public static variable buscar_variable(String id)
        {
            variable variable = null;

            //primero local

            Stack <variables> vars = new Stack <variables>(variables_actuales.Reverse());
            var aux = vars.Pop();

            while (aux != null && variable == null)
            {
                variable = aux.getVariable(id);
                if (vars.Count > 0)
                {
                    aux = vars.Pop();
                }
                else
                {
                    aux = null;
                }
            }


            //prueba otros tipos
            if (variable == null)
            {
                variable = buscar_variable("bool", id);
                if (variable == null)
                {
                    variable = buscar_variable("number", id);
                    if (variable == null)
                    {
                        variable = buscar_variable("string", id);
                    }
                }
            }
            return(variable);
        }
Beispiel #3
0
        public static variable buscar_variable(String tipo, String nombre)
        {
            variable variable = null;
            //buscar local en todos los ambitos
            Stack <variables> vars = new Stack <variables>(variables_actuales.Reverse());

            vars.Reverse();
            var aux = vars.Pop();

            while (aux != null && variable == null)
            {
                variable = aux.getVariable(tipo, nombre);
                if (vars.Count > 0)
                {
                    aux = vars.Pop();
                }
                else
                {
                    aux = null;
                }
            }

            if (variable == null)
            {
                foreach (archivo a in @const.interprete.archivos)
                {
                    variable = a.global.variables.getVariable(tipo, nombre);
                    if (variable != null)
                    {
                        return(variable);
                    }
                }
                //variable = @const.funcion_global.variables.getVariable(tipo, nombre);
            }

            return(variable);
        }