简体   繁体   中英

Regular expression [ 1 ( 0 1* 0)* 1 ]* DFA

这个正则表达式接受链的条件是什么?

The * at the end can be taken to mean the initial state is accepting and that the automaton returns to this state whenever it accepts anything. Call the initial state q1.

To accept 1(01*0)1 we must first consume a 1 and go to a new state, say q2. From there, we can self-loop on the subexpression 01*0 by going to a new state, q3, on 0, then looping on 1 in q3, then returning to q2 on 0.

From q2, we can return to q0 on 1. Our DFA looks like:

     /--1--\  /--0--\
     |      \ |     |
     V      | V     |
--->(q1)-1->(q2)-0->(q3)-\
     |               ^    \
     0               |    /
     |               \-1-/
     V
    (q4)-\
     ^    \
     |    /
     \0,1/

Something like that ought to do it.

When you don't know how to start off, you should write down several first elements generated by regular expression. In this case:

SET = {eps, 11, 1001, 10101, ...}

and then try to make up something. You got the answer though, so I'm not going to repeat this.

May you get some idea

\[[0-9\s]+.*\]\*

Demo: https://rubular.com/r/n3bVXJd3SFffr0

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