def get_nonterminals(rules):
    """
    Returns all non terminals that appear in the rules
    """
    d = {}
    for r in rules:
        d[r[0]] = 1
        # binary rule
        if len(r[1])==2:
            d[r[1][0]] = 1
            d[r[1][1]] = 1
    return d.keys()