DragonFly BSD
DragonFly kernel List (threaded) for 2004-09
[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]

Re: finite state machine/automaton framework?


From: Chris Pressey <cpressey@xxxxxxxxxxxxxxx>
Date: Fri, 3 Sep 2004 11:19:20 -0700

On Fri, 3 Sep 2004 20:05:08 +0200
"Simon 'corecode' Schubert" <corecode@xxxxxxxxxxxx> wrote:

> for example:
> 
> state_idle:
>    if:
>      written_byte & WHATEVER_BITMASK
>    newstate:
>      state_program_oneshot
>    output:
>      this_var = that_var;
>      run_foo();

static void (*state)(void);

static void
state_idle(void)
{
	if (written_byte & WHATEVER_BITMASK) {
		this_var = that_var;
		run_foo();
		state = state_program_oneshot;
		return;
	} else if ...
}

. ..

void
run_fsm(void)
{
	state = start_state;
	while (state != NULL) {
		state();
	}
}

This design pattern is heavily employed in the installer.

I don't think the specialized notation has many advantages over the C
version, especially in this instance.  Yacc and lex are a different area
of application - they transform a regular expression or a grammar into a
DFA or a LALR table - i.e. something of significantly different
structure.  On the other hand, these state descriptions look very very
similar to their C equivalents.

-Chris



[Date Prev][Date Next]  [Thread Prev][Thread Next]  [Date Index][Thread Index]