def nfa_to_dot (nfa, label_table = None, state_prefix = None):
    """Given a NFA tuple, output a string with Graphviz DOT code."""
    if state_prefix is None:
        state_prefix = "s"
    ret_val = []
    state_index = 0
    for state in nfa[2]:
        state_name = "%s%d" % (state_prefix, state_index)
        state_attrs = {}
        if state_index == nfa[3]:
            state_attrs["peripheries"] = 2
        if state_index == nfa[4]:
            state_attrs["peripheries"] = 2
            state_attrs["style"] = "filled"
        state_attrs_str = ""
        if state_attrs:
            state_attrs_str = (" [%s]" %
                               (", ".join(["%s = %s" % (str(k), str(v))
                                           for (k, v) in state_attrs.items()])
                                ))
        ret_val.append("%s%s;" % (state_name, state_attrs_str))
        for (label, tostate) in state:
            arc_attrs = {}
            if label_table:
                arc_attrs["label"] = label_table[label][1]
            else:
                arc_attrs["label"] = str(label)
            arc_attrs_str = ""
            if arc_attrs:
                arc_attrs_str = " [%s]" % (
                    ", ".join(["%s = %s" % (str(k), str(v))
                               for (k, v) in arc_attrs.items()]))
            ret_val.append("%s -> %s%d%s;" % (state_name, state_prefix,
                                              tostate, arc_attrs_str))
        state_index += 1
    return "\n".join(ret_val)