def isValid(form):
    """
    Checks the structural and symbol validity of the forumla.

    Parameters
    ----------
    form : string
        The formula to be validated.

    Returns
    -------
    valid : bool
        Whether the formula is valid or not.

    Examples
    --------
    >>> isValid("RUR'U'")
    True
    >>> isValid("RUR'UG") 
    False
    >>> isValid("(RU)((F2)2)") 
    True
    >>> isValid("((DU")        
    False
    """
    level = 0
    valid = True
    validAlpha = ['U', 'D', 'R', 'L', 'F', 'B', 'E', 'M', 'S', 'x', 'y', 'z', 'u', 'd', 'r', 'l', 'f', 'b', 'w']
    boolAlpha = False
    boolPrime = False
    boolDec = False
    for ch in form:
        if(ch == '('):
            level += 1
            boolAlpha = False
            boolPrime = False
            boolDec = False
        elif(ch == ')'):
            if(level > 0):
                level -= 1
            else:
                valid = False
            boolAlpha = True
            boolPrime = False
            boolDec = False
        else:
            if(ch in validAlpha):
                boolAlpha = True
                boolPrime = False
                boolDec = False
            elif((ch == '\'' or ch == 'P') and boolAlpha and not boolPrime and not boolDec):
                if(boolDec):
                    boolAlpha = False
                    boolDec = False
                else:
                    boolPrime = True
            elif(ch.isdigit() and boolAlpha):
                boolDec = True
            else:
                valid = False
    if(level != 0):
        valid = False
    return valid