BioJulia / Automa.jl

A julia code generator for regular expressions
Other
188 stars 15 forks source link

Improve DFA edge reduction #57

Closed jakobnissen closed 3 years ago

jakobnissen commented 3 years ago

This is best illustrated with an example: First, create this DFA:

import Automa
const re = Automa.RegExp
dfa = Automa.nfa2dfa(Automa.re2nfa(re.rep(re.rep(re.any()) * re.opt(re.parse("A")))))

Then visualise it: image

Note that these three nodes are indistinguishable. Indeed, once we optimize the DFA:

dfa = reduce_nodes(dfa)

We get one with only one node: image But look at the edges! Clearly, the edges are now indistinguishable! Why are they not collapsed to a single edge? Briefly, what it did before was:

Now, it checks if an equivalent edge already exists before adding a second one. If an equivalent edge does exist, it simply unions the edge labels