Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
14 votes

Very simple finite state machine

using namespace std Don't use using namespace std. It's considered bad practice. Consistency Use a consistent coding style. ...
Zeta's user avatar
  • 19.3k
10 votes
Accepted

Deterministic finite automaton in Java

Java 8 constructs The following function.putIfAbsent(startState, new HashMap<>()); function.get(startState).put(character, goalState); can be simplified ...
Tunaki's user avatar
  • 9,243
10 votes
Accepted

Event-driven finite state machine DSL in Kotlin

I'd design the StateMachine differently. The StateMachine does not need to know about all the possible Transitions between the States. All the StateMachine should care about is the current State it ...
D3xter's user avatar
  • 281
10 votes
Accepted

The parking machine implementation

Not a finite state machine The state machine in the posted code has infinite states. This is caused by the recursive calls of get_coin and ...
janos's user avatar
  • 111k
9 votes
Accepted

Simple tokenizer v2 - reading all matching chars at once

MatchDelegate Much as I love .NET's nominal delegates, I almost always regret using a delegate rather than an ...
VisualMelon's user avatar
  • 7,431
7 votes

The parking machine implementation

Given a state machine p which has initial state s and final state f, then it can only accept 0, 5, 10, 20 as inputs. This can be represented graphically as such: Therefore, the machine must continue ...
alexyorke's user avatar
  • 1,181
6 votes

Implementation of tokenizer object and finite state machine in C

Don't Repeat Yourself (DRY) ...
mdfst13's user avatar
  • 21.6k
6 votes
Accepted

C++ CLI Console Menu Statemachine

Use a constructor to initialize class variables Your function buildMenu() looks like it is just initializing all the members of a class ...
G. Sliepen's user avatar
  • 56.7k
6 votes

Simple tokenizer v1 - reading char by char

This isn't exhaustive, because I don't have much time now, so I might add some more later. As I said in a comment, I don't buy the idea of looping over one char at a time: it's not documented that ...
VisualMelon's user avatar
  • 7,431
5 votes
Accepted

Simulate Turing machine

I believe you're looking for std::prev: std::prev(tape.end()); The linked page even states the exact comparison of the two: ...
Jamal's user avatar
  • 34.9k
5 votes

Finite state automata

Just reviewing DFA. There are no docstrings. What does an object belonging to this class represent? What arguments do I pass to the constructor? What does the <...
Gareth Rees's user avatar
  • 49.6k
5 votes

Turing machine schoolwork

Some grist for the mill: When variables will not be reassigned, it's helpful to declare them as final to reduce cognitive load on the reader. When using the ...
Eric Stein's user avatar
  • 6,514
5 votes
Accepted

Simple tokenizer v1 - reading char by char

State Machine Review This is an interesting, yet unorthodox implementation of a state machine. Your states are actually transitions. You don't really have a state, since the state machine (...
dfhwze's user avatar
  • 13.9k
5 votes

Simple tokenizer v2 - reading all matching chars at once

General thoughts You have managed to create a somewhat elegant API that balances between a state machine pattern and a regex engine. This is reusable for small and context-free use cases, but will ...
dfhwze's user avatar
  • 13.9k
5 votes

Scalable design of a system with multiple state machines, where valid state transitions depend on the state of other machines

This doesn't have to be complicated. Definitely avoid Approach 1 - having a dedicated class for state combinations is not a good idea. Follow vaguely Approach 2, but Do not have a ...
Reinderien's user avatar
  • 62.1k
5 votes

Sequence state machine

First, you should follow the Java naming conventions. Second, don't shorten names just because you can. Example, what does "Proc" stand for? Procedure? Processor? Even if names become ...
Bobby's user avatar
  • 7,722
4 votes
Accepted

Time-dependent state machine

1. (Possible) bugs There are several problematic aspects of the code in the post. However, it is impossible for me to tell whether these really indicate bugs, because the code has no documentation, ...
Gareth Rees's user avatar
  • 49.6k
4 votes

Efficient data-driven finite state machine

This was quite fun to read and to figure out how it works. It took me a while to understand the control flow, which is my main point of critisism. I rearranged it a bit so that, at least in my ...
mkrieger1's user avatar
  • 1,694
4 votes
Accepted

Efficient data-driven finite state machine

Nice work. On findWeekdayDate() return, I'd expect a value that is enumerated like ...
chux - Reinstate Monica's user avatar
4 votes
Accepted

Arduino controller to control the backlighting of a gear selector

I see some things that may help you improve your code. The Arduino language isn't C The language used for the Arduino isn't quite C and isn't quite C++, so if your goal is "to learn C," you might ...
Edward's user avatar
  • 66.4k
4 votes

Very simple finite state machine

Zeta's answer is excellent. I'd like to point out a few additional things. First, remember that you can use = default to implement a boilerplate constructor, such ...
Adrian McCarthy's user avatar
4 votes
Accepted

Mars Rover problem in J

I applaud any use sequential machine. A primitive that simulates a state machine... fruit only the tree of J could produce... why resist? So while in that way ;: ...
Jonah's user avatar
  • 4,340
4 votes

DFA creation from string

Constructors should be class methods Your method suggests, that an instance of the respective class is being created using the given text. Thus you should make it a ...
Richard Neumann's user avatar
4 votes

Simple tokenizer v2 - reading all matching chars at once

Unnecessary switch-statements switch statements are nice as a way of avoiding long chains of ...
JAD's user avatar
  • 2,909
4 votes
Accepted

Hardware Clock Divider

Yes, there are some issues. With process (clk, divfactor) you're making it difficult for the synthesis software to generate a nice clocked process. So you should ...
JHBonarius's user avatar
4 votes

The parking machine implementation

For the first question: Your implementation is really good. For the second question: Yes, I believe this is suitable for real world applications, though it won't work without knowing mechanical ...
Sriv's user avatar
  • 2,740
4 votes
Accepted

Toy Robot Simulator

Aside from the given critiques (which are all correct) I have following notes: Prefixing variable names with its type (Hungarian notation) is generally considered bad style. (BTW, what does the ...
RoToRa's user avatar
  • 11k
3 votes
Accepted

UTF8 Codepoint decode and length v.2

Overall, this seems like a pretty straightforward implementation of the FSM you show. It's understandable, which is great! Document What It Is The only thing is, what if someone reading this has never ...
user1118321's user avatar
  • 11.7k

Only top scored, non community-wiki answers of a minimum length are eligible