Subj : Re: implementation of finite state machine To : comp.programming From : moi Date : Thu Oct 06 2005 08:58 pm Thad Smith wrote: > pete wrote: > >>Roman Mashak wrote: >> >>>Hello, Dave! >>>You wrote on Thu, 06 Oct 2005 10:11:59 +0100: >>> >>> ??>> Could you please point me to some resource, describing sample >>> ??>> implementation of FSM in C language, just to better catch >>> ??>> idea. TIA. With best regards, Roman Mashak. E-mail: mrv@tusur.ru >>> >>>Due to my understandanding of FSM, >>>I used 'if-elseif-else' chain. Might me >>>there are other ways and more efficient methods? >> >>Use an array of function pointers. >>The index into the array, is the state. >>The state is updated either as the return value of the function call >>or the address of the state object can be passed as an argument. > > > Another common technique is a switch statement, with a case for each > state. The case logic evaluates input criteria to determine when to > change state. > > Another technique is table driven, based on small number of input > variables. Index into the array based on input values to choose the > next state. > > In both techniques you can use either a particular transition or > particular state to choose an action routine (or block of code) to > perform based on either the transition or the current state. > > Thad An axample of the "next state := big_table [ current state, token ] " -method can be found in [f]lex, which generates the big tables for you. HTH, AvK .