Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

To answer your title, if not your article, no, state machines aren't used just to parse stuff.

About ten years ago I rewrote the communications layer for a pharmacy management system that was used in about 900 stores in Ontario. Because the system could be used with either a dial modem or a 3201 (poll select) device, I needed to have a state machine that was configurable at run-time, based on the current configuration. Thus, if the 3201 service went down (it did occasionally), a store owner could be talked through changing the configuration, restarting the communications layer and getting back on-line to filing on-line health claims. There were also stores in Northern Ontario that didn't have 3201 service and were permanently on dial modem connections.

The differences were that the modem had more states: it had to dial a number, check that it got CONNECT back, send the transaction, get a response, try again if the timeout was exceeded (and possibly do this for multiple transactions), then break the connection. The 3201 device was always connected, so it just had to send the transaction and get a response.

I used a state machine to take care of all this -- an array of function pointers (this was a C program). Depending on what mode it was in, and what the exit state of the previouis step was, the machine could determine where to go next (and what to do). It worked just fine.

And the same executable also ran as either a TSR or as a separate task under PC-MOS -- that was a fun piece of code to write.

Alex / talexb / Toronto

"Groklaw is the open-source mentality applied to legal research" ~ Linus Torvalds

In reply to Re: Are state machines just for parsing? by talexb
in thread Are state machines just for parsing? by samtregar

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others chanting in the Monastery: (8)
    As of 2018-03-20 12:29 GMT
    Find Nodes?
      Voting Booth?
      When I think of a mole I think of:

      Results (251 votes). Check out past polls.