My intention is to define a function that allows simulating the execution of a given deterministic finite automaton (DFA) .
According to the formal definition a DFA is the 5-upla M = (Q, Σ, δ, q 0 , F) where:
- Q is the set of machine states.
- Σ is a set of symbols called alphabet , which make up the entry.
- δ is a transition function defined by δ: Q x Σ → Q.
- q 0 ∈ Q is the initial state.
- F ⊆ Q is the set of final states.
Here is the function I envisioned:
typedef std::set<unsigned> StateSet;
typedef std::set<char> Alphabet;
typedef std::list<std::function<unsigned(const unsigned&, const char&)>> TransitionTable;
void RunAutomaton (const StateSet &states, const Alphabet &alphabet, const TransitionTable &table, const unsigned &initState, const SateSet &finalStates) {
// Executa o autômato...
}
However, this code gives no assurance about the parameters of the function. I wanted to be sure that the table had the correct values, i.e. the characters and states of the transition table were just characters present in the alphabet and in the list of states, respectively. There is also no way to be sure that the list of final states is a subset of the original state list (first argument); and the initial state belongs to the list of states.
Is there a way to define a function in such a way that I make sure that the arguments passed are all correct without having to perform hand checks?