let nfa_to_dot (nfa : nfa) : string =
let outb = Buffer.create (Hashtbl.length nfa.delta * 5) in
let appf x = Printf.bprintf outb x in
let delta_step q1 rhs =
let handle_rhs q2 charset =
let thecar = Charset.choose charset in
appf "q%d -> q%d [label=\"%d\"];\n" q1 q2 thecar
in
Hashtbl.iter handle_rhs rhs in
let epsilon_step q1 rhs =
let handle_rhs q2 = appf "q%d -> q%d [ label = \"%s\" ];\n" q1 q2 "eps"
in iter handle_rhs rhs
in
appf "digraph nfa {\nrankdir=LR;\n";
appf "node [shape = doublecircle]; q%d;" nfa.f;
appf "node [shape = circle];\n";
Hashtbl.iter delta_step nfa.delta;
Hashtbl.iter epsilon_step nfa.epsilon;
appf "}\n"; Buffer.contents outb