Questions tagged [fsm]

Acronym for Finite State Machine.

Finite state machine, finite state automata, or state machine, is used in computer science or logic theory to represent a finite number of states and the transitions between states.

Finite state machines are commonly used in parsing and matching strings, so it accepts certain types of strings (such as those representing an integer), and a language (set of strings) is regular if and only if it can be represented as a finite state machine.

An example of a finite state machine implementation in pseudocode, accepting all decimal integers:

state = 0;
digits = "152341264"; // Some sequence of decimal digits
for (k = 0; k < len(digits); k++) {
    switch (state) {
    case 0: // Initial state
        if (digits[k] is a decimal digit)
            state = 1;
        else
            state = 2;
        break;
    case 1: // Digit found, also an accepting state
        if (digits[k] is a decimal digit)
            state = 1;
        else
            state = 2;
        break;
    case 2: // Dead state
        break;
    }
}
FSM accepts the string digits if it finishes at state 1.

Finite state machines represent all the regular languages, or Type 3 languages, which are the lowest in the Chomsky hierarchy, below the context-free (Type 2) languages, which is below the context-sensitive (Type 1) languages, which is below the recursively enumerable (Type 0) languages.

Wikipedia page

The tag is also known like on stackoverflow.

533 questions
14
votes
2 answers

Designing high-performance State Machine in Java

I am in the process of starting to write a Java library to implement high-performance Finite State Machines. I know there are a lot of libraries out there, but I want to write my own from scratch, as almost all the libraries out there construct…
Nico Huysamen
  • 10,217
  • 9
  • 62
  • 88
14
votes
7 answers

What is the Pythonic way to implement a simple FSM?

Yesterday I had to parse a very simple binary data file - the rule is, look for two bytes in a row that are both 0xAA, then the next byte will be a length byte, then skip 9 bytes and output the given amount of data from there. Repeat to the end of…
Vicky
  • 12,934
  • 4
  • 46
  • 54
14
votes
6 answers

Finite State Machine and inter-FSM signaling

Recommendations for languages with native (so no FSM generation tools) support for state machine development and execution and passing of messages/signals. This is for telecoms, e.g implementation of FSMs of this level of complexity. I have…
user172783
12
votes
5 answers

Convert finite state machine to regular expression

Is there a tool (or an algorithm) to convert a finite state machine into a regular expression? (not the other way around, that would be easy).
enrico.bacis
  • 30,497
  • 10
  • 86
  • 115
11
votes
1 answer

How to parse template languages in Ragel?

I've been working on a parser for simple template language. I'm using Ragel. The requirements are modest. I'm trying to find [[tags]] that can be embedded anywhere in the input string. I'm trying to parse a simple template language, something that…
Tobias Lütke
  • 1,028
  • 1
  • 9
  • 9
11
votes
1 answer

General Finite State Machine (Transducer) in Scala

What is the general way to implement a finite state machine (or finite state transducer) in Scala? I often find myself in need for state machine implementation. My typical implementation looks like object TypicalFSM { // actually — finite state…
Arseniy Zhizhelev
  • 2,381
  • 17
  • 21
10
votes
1 answer

How to access state during transitions in Akka FSM

I am using Akka FSM for handling state in my Actor. I want some actions to be performed every time a transition to a certain state occurs, no matter which state the transition was made from. After reading the docs, I felt certain that this could be…
eirirlar
  • 814
  • 6
  • 24
10
votes
3 answers

Akka Java FSM by Example

Please note: I am a Java developer with no working knowledge of Scala (sadly). I would ask that any code examples provided in the answer would be using Akka's Java API. I am trying to use the Akka FSM API to model the following super-simple state…
smeeb
  • 27,777
  • 57
  • 250
  • 447
9
votes
3 answers

State Pattern C# with previous states

I am new to the state pattern implementation in C#, could you provide some info on how you implement it. I am refactoring a state machine in C# using the state pattern. Currently my state machine contains 5 states and it is only possible to go…
Manolete
  • 3,431
  • 7
  • 54
  • 92
9
votes
6 answers

FST (Finite-state transducers) Libraries, C++ or java

I have a problem to solve using FSTs. Basically, I'll make a morphological parser, and in this moment i have to work with large transducers. The performance is The Big issue here. Recently, i worked in c++ in other projects where the performance…
Cdiniz
  • 91
  • 1
  • 5
9
votes
4 answers

What is the best practice for a hierarchical state machine using the state pattern?

I'm about to implement a hierarchical state machine in C# using the state pattern. As a guide I'm using this example. The example doesn't provide an answer regarding hierarchical states though. Unfortunately, I can't seem to find good examples…
user341877
  • 237
  • 2
  • 12
8
votes
1 answer

Validating a finite state machine (using AASM) on Rails

I'm using AASM by Rubyist to build a 4-step wizard for an AR object. According to the state of the object, there are different validations that need to be done. What is the smartest way to validate an object according to it's state on a certain…
Javier
  • 2,491
  • 4
  • 36
  • 57
8
votes
1 answer

What are the principles involved for an Hierarchical State Machine, and how to implement a basic model?

So I'm attempting to make a game using C++, and I've read a ton of articles on Finite State Machines (FSM), and Hierarchical State Machines (HSM). However I will admit most of the stuff I've read is a bit dense and hard to understand, so I was…
Rivasa
  • 6,510
  • 3
  • 35
  • 64
8
votes
2 answers

What does 1-, 2-, or 3-process mean for an FSM in VHDL?

It seems like there is quite some debate about how to code finite state machines (FSMs) in VHDL. People talk about 1-process, 2-process, or 3-process FSMs as if everyone knew exactly what it means and what each process does. However, I've been…
VHDL Addict
  • 171
  • 1
  • 10
8
votes
3 answers

How to avoid singletons when making an OOP state machine design?

I'm in the midst of trying to teach myself programming. I started the same way that I'm sure most people start; making small, messy apps and games that do simple things in not-so-simple ways. Recently, I've been trying to take the next step by…
MrKatSwordfish
  • 1,504
  • 5
  • 18
  • 30
1
2
3
35 36