- Category :Theory of Computation / C++
- Stack :C++17, Graphviz
- Automata :DFA, NFA, ε-NFA
- Output :State paths + Accepted / Rejected
- Status :Working
Three finite-automaton simulators written in C++ that show how the same idea grows in power and in complexity: a deterministic machine, a nondeterministic one, and a nondeterministic one with ε-moves. Each program prints the state path for the words it processes, and each comes with a transition diagram drawn from its Graphviz source.
All three work over the alphabet {0, 1} and print their transition table at the end of the run.
A four-state machine over the binary alphabet. It starts and accepts in state A, so it recognises words with an even number of 0s and an even number of 1s. The program walks the first 500 binary words and prints the state path of every accepted word.
1001: A→C→D→C→A.
| 0 | 1 | |
|---|---|---|
| →*A | B | C |
| B | A | D |
| C | D | A |
| D | C | B |
dfa/dfa.cpp
Nine states with several possible moves per symbol. A recursive backtracking search explores every branch and prints each path with its verdict; the word is accepted if at least one path ends in state 9. In the diagram, blue edges are symbol 0 and orange edges are symbol 1.
| makes every branch run, so the full search tree is printed.9.
| 0 | 1 | |
|---|---|---|
| →1 | 2,4 | 5 |
| 2 | 4,6 | 1,5,3 |
| 3 | 2,6 | 5 |
| 4 | 2,8 | 1,5,7 |
| 5 | 2,4,6,8 | 1,3,7,9 |
| 6 | 2,8 | 3,5,9 |
| 7 | 4,8 | 5 |
| 8 | 4,6 | 7,5,9 |
| *9 | 8,6 | 5 |
nfa/nfa.cpp
Six states plus empty (ε) transitions that change state without consuming input. In the recursion this is a call that does not advance the input index. State E branches into B and C for free, and B can jump to the accepting state D at the end of the word.
1, 0, 000, 111, 011 accepted; 11, 01, 010 rejected.
| 0 | 1 | ε | |
|---|---|---|---|
| →A | E | B | |
| B | C | D | |
| C | D | ||
| *D | D | ||
| E | F | B,C | |
| F | D |
enfa/enfa.cpp



Send a direct message about this project and it will be delivered to my email.