Regexp to finite state machines

Reply

Join Date: May 2009
Posts: 1
Reputation: blackout83 is an unknown quantity at this point 
Solved Threads: 0
blackout83 blackout83 is offline Offline
Newbie Poster

Regexp to finite state machines

 
0
  #1
May 16th, 2009
Ok so I'm having difficulty understanding how to Take a regular expression and turn it into a finite state machine..

so heres a problem similar to the one I need to solve..

Say I have a machine that takes £1 coins, dispenses beer(£1) and water(£2)

so the values for a regular expression are;

p = inserting a coin
c = dispense beer
b = dispense water
(Also buttons to dispense cans)
B = beer button
W = water button

and lets say ppWb represents buying water..


REG = (pBc+p(e+p)Wb)* (e is an empty string..)

so how do I derive this into a finite state machine? I can vaguely turn this into a syntax tree, then where do I go from there?

If anyone could give a rough sketch I'd be really grateful..
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 24
Reputation: Traevel is an unknown quantity at this point 
Solved Threads: 9
Traevel's Avatar
Traevel Traevel is offline Offline
Newbie Poster

Re: Regexp to finite state machines

 
0
  #2
May 16th, 2009
Hi there,

Basically, all you have to do is draw all the possible transitions between the different states. So, for example, begin at start, then to a state with one coin inserted, one with B-button pushed, the corresponding output, and from there back to start.

(start) -> (p) -> (B:dispense beer) -> (start)
Then from the single coin state draw another transition to a state for two coins and from there to water & output and back to start.

(p) -> (p2) -> (W:dispense water) -> (start)
Perhaps to clarify some of the drawing: a stamp dispenser.

Once you have a drawing it will be much easier to translate those transitions into some workable code (for example, something like Prolog).

Hope this helps, good luck!
6.5 When the answer cannot be put into words, neither can the question be put into words. The riddle does not exist. If a question can be framed at all, it is also possible to answer it. ~ Ludwig Wittgenstein
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Legacy and Other Languages Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC