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
8
votes
2 answers

is there any compiler that can convert regexp to fsm? or could convert to human words?

Something that can convert r"a+|(?:ab+c)" to { (1, 'a') : [2, 3], (2, 'a') : [2], (3, 'b') : [4, 3], (4, 'c') : [5] } or something similar and accepting in 2 or 5
somethin
  • 115
  • 6
7
votes
1 answer

Is a fake stack faster than a real stack

I'm doing some recursive parsing. Currently I have a fake stack, where I store states for my finite state machine, so as I drill down recursively I push the state I was in, and pop it later after I've finished processing the recursive bit of…
matiu
  • 7,469
  • 4
  • 44
  • 48
7
votes
1 answer

Extensible state machines in Haskell

I can define a toy state machine (with trivial input) as follows: -------------------------------------------- -- module State where data State = A | B Int -------------------------------------------- -- module A where -- import State transitionA…
Sam Derbyshire
  • 719
  • 1
  • 4
  • 12
7
votes
4 answers

GUI for Creating Visual State Machine

I want to create an application GUI that allows a user to create a visual state machine. The interface would work similarly to Microsoft's Visio product, where the user adds blocks or circles (states) and then connects the states with arrow lines…
SyllogismRXS
  • 326
  • 1
  • 2
  • 4
7
votes
3 answers

Finite State Machine parser

I would like to parse a self-designed file format with a FSM-like parser in C++ (this is a teach-myself-c++-the-hard-way-by-doing-something-big-and-difficult kind of project :)). I have a tokenized string with newlines signifying the end of a euh...…
rubenvb
  • 74,642
  • 33
  • 187
  • 332
7
votes
1 answer

Coroutine based state machines

I have a tricky and interesting question to You. While working on I/O tasks such as protocol implementation via some transport layer in Twisted, Tornado, I found a similar scenario or pattern. The pattern is rather generic than abstract. For…
Rustem K
  • 1,212
  • 11
  • 27
7
votes
2 answers

Difference between Mealy and Moore

Does the difference between Mealy and Moore state machines have any real significance when it comes to a C implementation? What would that difference normally be? A long time ago, it was much easier for me to understand Mealy/Moore…
user1461251
  • 71
  • 1
  • 2
6
votes
2 answers

Finite State Machine parsing

This picture depicts finite state machine parsing "nice" string. The question is how would it look like in JS code? EDIT Picture from link above:
DrStrangeLove
  • 11,227
  • 16
  • 59
  • 72
6
votes
7 answers

FSM data structure design

I want to write an FSM which starts with an idle state and moves from one state to another based on some event. I am not familiar with coding of FSM and google didn't help. Appreciate if someone could post the C data structure that could be used for…
user68685
6
votes
1 answer

What could cause C to skip over a return statement?

I am programming in C for a microcontroller so I am not sure if this question belongs here or on the electronics stackexchange. Just let me know if it doesn't fit here and I will move the question over there. So I have Finite State Machine in C.…
Vincent Kenbeek
  • 583
  • 1
  • 5
  • 11
6
votes
6 answers

Implementing a FSM in VHDL

Just wondering if I'm implementing a finite state machine in VHDL whether or not I need to state what all of the outputs are in every possible state? Even if I know that some outputs won't change from one state to the other and I know that the order…
JimR
  • 2,145
  • 8
  • 28
  • 37
6
votes
1 answer

How to correctly pass data in the Finite State machine in AKKA

I am following this example here from the doc Here is part of the finite state machine I'm working with startWith(ACCEPTED, new myData()); when(ACCEPTED, matchEvent(someMesage.class, MyData.class, (someMessage, myData) ->…
user_mda
  • 18,148
  • 27
  • 82
  • 145
6
votes
6 answers

RE -> FSM generator?

Given a regular expression, I'm looking for a package which will dynamically generate the code for a finite state machine that implements the RE. C/C++ and Python preferred, but other languages are of interest as well.
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
6
votes
3 answers

Why not a two-process state machine in VHDL?

When I learnt how to express finite state machines in VHDL, it was with a two-process architecture. One process handles the clock/reset signals, and another handles the combinatorial logic of updating the state and output. An example is below. I've…
detly
  • 29,332
  • 18
  • 93
  • 152
6
votes
1 answer

Finite State Machine & persistence in Laravel

I'm wondering if Laravel has some built-in state machine mechanism? And if not, what's the best way to use this excellent library called Finite (https://github.com/yohang/Finite). Here's what I have (use case : a job board) : User creates an…
Ahmed Chergaoui
  • 103
  • 2
  • 6
1 2
3
35 36