From: Francis Cianfrocca Date: 2006-09-09T05:53:21+09:00 Subject: Re: state machine in ruby On 9/8/06, ara.t.howard@noaa.gov wrote: > > > harp:~ > cat a.rb > > require 'fsm' > > FSM.system do > > fsm{ > states %w( empty full ) > transition 'filling', 'empty' => 'full' > transition 'emptying', 'full' => 'empty' > } > > observer{ > on_entry 'empty' do > puts 'became empty.' > > transition 'empty', 'filling' do > puts 'filling...' > sleep 1 > end > end > > on_entry 'full' do > puts 'became full.' > > transition 'full', 'emptying' do > puts 'emptying...' > sleep 1 > end > end > } > > start > end > > STDIN.gets > Reading this, I kept trying to figure out how this is different from plain old yacc, then I realized you have no lookahead capability. What kind of situations have you used this in? I don't understand Chris' example enough yet to decide if it constitutes a regular language or something more. Mechanically dealing with comms protocols is a pretty interesting subject, although in general the more recent ones aren't terribly complicated. (The practical subset of HTTP isn't bad; SIP isn't bad; SMTP is a bear; XML is ambiguous in at two places I know of.) I often end up just writing recursive-descent parsers that expose their internal state and use a pushback buffer so they can be restarted.