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

General proof of equivalence of two FSMs in finite time?

Does a general proof exist for the equivalence of two (deterministic) finite state machines that always takes finite time? That is, given two FSMs, can you prove that given the same inputs they will always produce the same outputs without actually…
sgibbons
  • 3,620
  • 11
  • 36
  • 31
6
votes
3 answers

How can I get a boost::function (or other generic function wrapper) that returns itself?

I've recently become enamored with the simplicity of Erlang's actor-based concurrency model, and am playing around with ideas for implementing some parts of it in C++. Along these lines, I also like the idea of implementing a finite state machine…
Managu
  • 8,849
  • 2
  • 30
  • 36
5
votes
1 answer

XState: Wait for response of invoked function

I am planning to use XState for managing states in the backend of my application. When an api is called, a function will be called on successful state change. The result of the function call has to be returned as response of the api. // Returns a…
suku
  • 10,507
  • 16
  • 75
  • 120
5
votes
2 answers

Finite State Machines in C

I'm trying to create a FSM in C that follows this diagram: and has output that looks like this: I started by defining an enum that held all the possible states: typedef enum { Start = 0, Build_Id = 1, Identifier = 2, Build_Num = 3, Number =…
Ismael
  • 197
  • 1
  • 2
  • 12
5
votes
3 answers

Best way to generate java with python?

Whats the best way to generate java from python? I want to write a decorator that generates java code to call a json version of a function (I can use existing decorators to export the json api). Whats the best way to generate the java, should I…
Stuart Axon
  • 1,844
  • 1
  • 26
  • 44
5
votes
2 answers

FSM export using Yosys

I am using Yosys to synthesize my Verilog designs. I want to export the FSM in my Verilog design using the Yosys command fsm_export, but it does not generate anything. I wonder how is this command supposed to be called. The series of commands I…
adrianX
  • 619
  • 7
  • 21
5
votes
2 answers

Akka FSM Goto within future

I'm trying to change FSM state in future but i doesn't work.. I think i'm looking for pipeTo like method. When(State.Waiting) { case Event(anyMsg, anyData) => asyncCode.map(res => if (res == 1) { goto(State.Working)…
Alexander Kondaurov
  • 3,677
  • 5
  • 42
  • 64
5
votes
2 answers

Implementing a finite state machine with a single coroutine

I'm looking at ways to implement an FSM, which led to my first encounter with coroutines. I saw several examples (here, here and here) which hint that a state machine can be implemented by a single coroutine. However, what I noticed all these…
mcmlxxxvi
  • 1,358
  • 1
  • 11
  • 21
5
votes
1 answer

Is it possible to compose FSMs in Akka?

For regular actors, they can be composed. But, I can't seem to find anything about doing it with FSMs. And there isn't a receive block to use += to add things to. Does anyone have any experience trying to generalize an FSM? I can't provide a code…
Dante Romero
  • 1,234
  • 1
  • 8
  • 9
5
votes
1 answer

State machine pushing events to its own event queue

I am currently researching Hierarchical State Machines (UML State Machines, Statecharts, etc.), and the following is unclear to me: Is pushing events to machine's own event queue during transitions and from states valid, and if it is, is it safely…
bgr
  • 147
  • 2
  • 8
5
votes
1 answer

Converting regular expression to finite state machine

Would you have a hint at algorithm to convert any regular expression to a Finite State Machine (FSM). For instance, an algorithm parsing a regexp and adding states to the FSM appropriately? Any reference or deeper idea? I am writting this with…
kiriloff
  • 25,609
  • 37
  • 148
  • 229
4
votes
3 answers

State Machine - Structure To Hold States, Events and pFuncs

If I make a state machine and want to use an interface like this: AddState ( state1, state2, Key_UP ); AddEvent ( Key_UP ); AddEventFunction ( Key_UP, &UP_Function); AddStateFunction ( state1, &State1_In_Function,…
uMinded
  • 595
  • 1
  • 9
  • 21
4
votes
1 answer

Document C code containing state machines

I've written C code containing a state machine 1. Now I'm looking for a way to generate a html file documenting that state machine like [2]. I've looked at doxygen [3]. It can extract texts, callgraphs and the like, but it cannot generate state…
Cedric
  • 89
  • 4
4
votes
1 answer

Is there a benefit to using an enum in a FSM over just using a string?

I want to create a finite state machine and most of the example code I can find uses enums and I was just wondering if it gives an advantage over just using a string or int to store the state. With Enum: class TrafficLight { enum State { …
user9549420
4
votes
2 answers

Finite State Machine to Search for "ABBA"

I'm trying to write a while switch case kinda code for modeling a finite state machine that searches a string of As and Bs to see if the string "ABBA" is present. When I input just "ABBA", it outputs Word found! like it's supposed to. However, if I…
Anna
  • 379
  • 5
  • 16