simple-dfa
is an appilcation that feeds input to a DFA and produces the corresponding output.
Download the simple-dfa
folder, open it in terminal and run make
.
From the simple-dfa
folder, run
./main dfa/[filename].dfa [inputs]
The format of [filename].dfa
should be as follows.
number of states
states (one per line)
the start state
number of final states
final states (one per line)
number of transitions
transitions (one per line, each line in the form "current-state transition-symbol goal-state output-symbol")
For transitions on an empty symbol, an empty word/symbol may simply be denoted by empty
in the .dfa
file.
The src
folder contains the DFA implementation.
main dfa/replace.dfa argv
replaces each occurrence of1 0 0
by0 1 1
in the binary vectorargv
.
Complexity:O(|argv|)
.
main dfa/add1.dfa n
for a reversed binary vectorn
computesn+1
in reversed binary.
Complexity:O(log n)
.
main dfa/sub1.dfa n
for a reversed binary vectorn
computesn-1
in reversed binary.
Complexity:O(log n)
.
main dfa/multi.dfa n
for a reversed binary vectorn
computesi*n
in reversed binary.
Complexity:O(log n)
.
main dfa/collatz.dfa n
for a reversed binary vectorn
computesn%2 ? 3*n+1 : n/2
in reversed binary.
Complexity:O(log n)
.
main dfa/aba-count.dfa argv
printsa^n
wheren
is the number of occurrences ofa b a
inargv
.
Complexity:O(|argv|)
.
main dfa/add.dfa ab cd ef ...
computes the sum of the reversed binary numbersace...
andbdf...
in reversed binary.
Complexity:O(|argv|)
.