thinghaser.blogg.se

Finite state machine examples
Finite state machine examples














The handler skip ignores the current character. The handler push pushes the given character onto the stack. The default behavior of on_any is to do nothing. The handler on_any is called automatically when an event occurs which is not covered by any row in the transition table. There are three built-in event handlers, on_any, push and skip. A special event handler on_eof takes no arguments and is called automatically after the last character in a sequence is processed. The implementation of an event handler typically examines the given character and pushes zero or more characters of filtered data onto the stack. The character classes alnum, is_alpha, is_cntrl, is_digit, is_graph, is_lower, is_print, is_punct, is_space, is_upper, is_xdigit implement locale-sensitive character classification.Įvent handlers are member functions of a finite state machine which take a single character as argument and return void. For any character c, the character class is only matches c. The character class is_any matches any character. There are several built in character classes. Static bool test( char, const std::locale&) The machine's state is then updated to the row's next state, and the event handler is called with e as an argument.Ī character class is a class type with a static member function test taking a character and a std::locale as arguments. When an event e occurs, the transition table is searched for the first row whose current state is equal to the current state of the machine, and whose character class matches e. During the operation of a finite state machine, its transition table is consulted to determine how the machine's state should be updated and which event handler to call. Each row is a 4-tuple consisting of a current state, a character class, a next state and an event handler. A transition table is an MPL Forward Sequence of rows. See, e.g., įor us, an event is simply a character. These finite state machines were inspired by the finite state machine examples that accompany the Boost Metaprogamming library. For purposes of this section, a finite state machine consists of a collection of states, represented as ints, a distinguished initial state, a transition table, a collection of event handlers and a stack of characters.

#Finite state machine examples how to

In this section I show how to construct Dual-Use Filters from finite state machines. Finite State Filters Finite State Machines














Finite state machine examples