def enumx(tree, idx=0):
    """ a generator for enumerating all translations in a parse forest """
    try:
        item = tree.right[idx]
    except IndexError:
        yield '', tree.cost
        return
    for rest, cost in tree.enumx(idx + 1):
        if type(item) == str:
            if rest:
                yield item + ' ' + rest, cost
            else:
                yield item, cost
        else:
            for alt in item:
                for first, fcost in alt.enumx():
                    if first and rest:
                        yield first + ' ' + rest, cost + fcost
                    else:
                        yield first or rest, cost + fcost
