def _parseStage2(bPattern):
    """
    This function takes as input a bPattern, pattern generated by _parseStage1.
    This function checks and converts bPattern into cPattern which is later
    used for matching tree structures.
    This function:
        1. Checks if each subtree sequence has three parts (preceding
            children, root, following children)
        2. Converts each subtree into [root, [left children, right children]]

    The output of this function is a cPattern
    """
    if bPattern == []:
        return []
    if isinstance(bPattern, str):
        return bPattern
    elements = [[]]
    for entry in bPattern:
        if entry == '|':
            elements.append([])
        elif isinstance(entry, list):
            subCPattern = _parseStage2(entry)
            elements[-1].append(subCPattern)
        else:
            elements[-1].append(entry)

    if len(elements) != 3:
        raise ValueError("numOfElements Incorrect")

    if (not isinstance(elements[1], list)) or len(elements[1]) != 1:
        raise ValueError("Invalid root specification")
    if not isinstance(elements[1][0], str):
        raise ValueError("Invalid root specification")

    cPattern = elements[1] + [elements[0], elements[2]]
    return cPattern