automata state machine

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • conics
    New Member
    • Feb 2008
    • 30

    automata state machine

    i need to create an automata state machine simulator using c..

    i know how it runs, problem is, i do not know the exact algorithm to put it in "C"

    another thing is, most samples i find now are java based. hope anyone can help me

    thanks..
    Nico
  • sicarie
    Recognized Expert Specialist
    • Nov 2006
    • 4677

    #2
    There is no set algorithm that will allow you to code something in C. If you have found one in Java, you can translate that very easily to C, but you have to understand the code and what it is doing first.

    Comment

    • weaknessforcats
      Recognized Expert Expert
      • Mar 2007
      • 9214

      #3
      First, you use a loop that continues as long as the state is not the exit state.

      Then inside that loop you use a switch and you switch on the state.

      Each state (case) does what it is supposed to and then sets the next case. Then break. That is, all that's required is a) you know the initial state when you enter the loop and b) each individual state knows the next state.

      You stay in the loop until one of the cases sets the exit state.

      The individual states are integer values. This is a great place for an enum
      Code:
      enum State {INITIAL, EXIT, START_ENGINE, STOP_ENGINE, NO_GAS}

      Comment

      Working...