简体   繁体   中英

DFA to regular expression

I have already read a couple soultions and tutorials, expecially on Stackoverflow, but can't help myself with a specific issue. To begin with, I have this DFA: 在此处输入图片说明

And could reduce it to this:

在此处输入图片说明

So that I have the regular expression at (aa|ba|cc)c but missing the returning d. Checking it that far with http://hackingoff.com/compilers/regular-expression-to-nfa-dfa it looks exactly like my starting DFA but without the d. I tried a lot but am very unsure how to write the d into the RE.

Your proposed sequence isn't quite correct, as pointed out by revo . The correct sequence is (aa|ba|c)c .

The regex version (in programming languages) of the whole DFA would be

/^(?:aa|ba|c)c(?:d(?:aa|ba|c)c)*$/

The formal regex would be

(aa|ba|c)c(d(aa|ba|c)c)*

(?:aa|ba|cc)c is the first sequence that you already figured out (everything from q0 to q6 , without the d path from q6 back to q0 ).

Once a d appears, you basically need the above sequence again . That second instance of the sequence including the d can be repeated any number of times, so you use the * quantifier.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM