private double evaluate(String expresion) {

        if (error && !allErrors) {
            return 0;
        }

        expresion = eliminarParentesis(expresion);
        if (expresion.isEmpty()) {
            strError.append("Error: Expresion Vacia!\n");
            error = true;
            return 0;
        }
        if (expresion.charAt(0) == '-') {
            expresion = "0" + expresion;
        }

        // ----------------------------------------------

        Double ret = getValorVariable(expresion);
        if (ret != null) {
            return ret;
        }
        if( error ) return 0;

        // ----------------------------------------------

        if (isNumber(expresion)) {
            return Double.parseDouble(expresion);
        }

        // ----------------------------------------------

        String fun = dataFunction(expresion);

        if (fun != null) {
            Funcion f = null;
            String toks[] = fun.split(";");
            String name = toks[0];
            String expresion2 = toks[1];

            name = Character.toUpperCase(name.charAt(0))
                    + name.substring(1).toLowerCase();

            double rr = 0;
            switch (name) {
                case "Sum":
                    return evaluateSum(expresion2);
                case "Mult":
                    return evaluateMult(expresion2);
                default:
                    try {
                        f = (Funcion) Class.forName("Entidad.Funciones." + name).newInstance();

                    } catch (Exception e) {
                        error = true;
                        strError.append("Error: Funcion no definida \"").append(name).append("\"\n");
                        rr = evaluate(expresion2);
                        return 0;
                    }

                    rr = evaluate(expresion2);

                    if (f.isValue(rr)) {
                        return f.evaluate(rr);
                    } else {
                        strError.append("Error:  Parametro no aceptado \"").append(name).append("(").append(rr).append(")\"\n");
                        error = true;
                        return 0;
                    }
            }
        }

        // -----------------------------------------------

        int prioridad = 0;

        int posoper = -1;
        char oper = '?';
        int priop = Integer.MAX_VALUE;
        boolean ispar = false;

        for (int i = 0; i < expresion.length(); i++) {
            if (expresion.charAt(i) == '(') {
                prioridad++;
                ispar = true;
            }
            if (expresion.charAt(i) == ')') {
                prioridad--;
                ispar = true;
            }

            int po = OPERS.indexOf(Character.toString(expresion.charAt(i)));
            if (po >= 0 && po + 10 * prioridad <= priop) {
                oper = expresion.charAt(i);
                posoper = i;
                priop = po + 10 * prioridad;
            }
        }

        String s1 = "";
        String s2 = "";

        if (oper == '?') {
            error = true;

            if (ispar) {
                strError.append("Error:  Expresion no definida \"").append(expresion).append("\"\n");
            } else {
                strError.append("Error:  Variable no definida \"").append(expresion).append("\"\n");
            }

            return 0;

        } else {
            s1 = expresion.substring(0, posoper);
            s2 = expresion.substring(posoper + 1);
        }

        return Operate(s1, expresion.charAt(posoper), s2);
    }