Hi,
I am Varun Gupta, a student at San jose State university and am working on finite automata.
I am totally new to the concept of finite automata.
Can anybody please provide me with a code in C or C++ or may b JAVA, that converts regular expression into finite automata?
That would be of a great help to me or if anyone can please give me a link for the same?
Thanks,
Varun
It shouldn't be too hard, there is an algorithm to do it in "Introduction to Computation" by Michael Sipser in chapter 1. It gives you a step-by-step process which seemed simple enough for me since you have the closure properties all the operators proven by construction.
For instance, the op's problem ((0*1*0)U(11*0))* can be tackled by taking into account the order of operations. We start by building NFA for empty string (sometimes called lambda or epsilon), then we build NFA for accepting single characters '0' and '1'.
Next, we use the proof of closure-property of * operator to build 0* and 1*.
Afterwards, we build two new NFA's
One, were we concatenate 0* with 1* with '0'. Using the epsilon-transitions are helpful in this matter.
The other NFA is done in a similar fashion, where we connect the NFA which accepts a single '1' with 1* using the epsilon-transition, then with the NFA which accepts a single '0' as well.
Then, using the closure-property of union, we unite 0*1*0 with 11*0. Again, epsilon-transitions make this much easier for us.
Finally, we add a new start state (as apart of the algorithm for making NFA's which mimicks * operator listed in the closure property of * operator) that only sends you to the last NFA but doesn't receive any incoming transitions from any other state.
Have the last states in both 0*1*0 and 11*0 connect with epsilon-transitions to the old start state of the prior NFA (where we united the two subproblems).
to OP: I would post the answer for you, but I don't have a means to do it nor the time. I think it's best for you to list an aim-account or ask for it to be sent over e-mail so I could send you a copy of that answer. However, probably - by now - you're already way past this so any help concerning this is unnecessary as you're likely working on Turin Machines now. --Good Luck
To Varun: For someone like myself, I'd have an easier time reading something written in English how to make automata from regular expressions than by using code. I think most people are the same way, but for some programming is better.