1
My intention is to define a function that allows to simulate the execution of a deterministic finite automaton (DFA) datum.
According to the formal definition a DFA is the 5-upla M = (Q, Σ, δ, q0, F) in which:
- Q is the set of machine states.
- Σ is a set of symbols called alphabet, making up the entry.
- δ is a transition function defined by δ : Q x Σ Q.
- q0 Q is the initial state.
- F Q is the set of final states.
Here’s the function I imagined:
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 does not give any security on the parameters of the function. I wanted to make sure that the table had the correct values, i.e, the characters and states of the transition table were only characters present in the alphabet and 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 list of states (first argument); and the initial state belongs to the list of states.
Is there any way to define a function in such a way that I can be sure that the past arguments are all correct without me having to do any checks by hand?