I've been trying to convert the regular expression
to a non-deterministic finite automata (NFA) first using Thompson's construction, giving:
, which looks correct.
I am then using subset construction to create the DFA from the NFA, shown here.
But this does not look correct to me, as for example 0 followed by 0 is not valid according to the DFA I have constructed. I was wondering how should I be modelling the epsilon in the original regular expression, as I have simply treated it as a normal epsilon.
A single matches already - thus state B in your diagram for an dfa has to be already an accepting state (just mark it as accepting would not fix it!). I can't reconstruct your ideas, but you should end in something like
A --0--> (B)
A --1--> C
B --0--> (B)
B --1--> C
C --0--> (B)
C --1--> C
If you'll start to think from the other side, the regex (0|)(0|1)*0
could be simplified by removing the first part (0|)
. This could be done because (0|1)
matches everything that (0|)
will match (and more). You can see it in your diagram for the nfa, too.
S0->S1->S2->S5 === S7->S7->S8->S11
S0->S3->S4->S5 === epsilon
Maybe this could help to get your thoughts in the right direction..
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.