12 #ifndef CPROVER_UTIL_NFA_H
13 #define CPROVER_UTIL_NFA_H
20 #include <unordered_map>
21 #include <unordered_set>
86 const auto it = transition.when.find(input);
87 if(it != transition.when.end())
89 for(
const auto result_state : it->second)
91 new_state.possible_states.insert(result_state);
94 for(
const auto result_state : transition.arbitrary)
96 new_state.possible_states.insert(result_state);
107 out <<
"digraph {\n";
112 out <<
'S' << from <<
" -> S" << to <<
"[label=\"*\"]\n";
116 out <<
'S' << from <<
" -> S" << to <<
u8"[label=\"ε\"]\n";
120 const auto &in = pair.first;
121 const auto &tos = pair.second;
122 for(
const auto to : tos)
124 out <<
'S' << from <<
" -> S" << to <<
"[label=\"(" << in <<
")\"]\n";
134 const auto min_size = std::max(from, to) + 1;
143 std::vector<state_labelt> new_states{};
153 new_states.push_back(to);
161 }
while(!new_states.empty());
168 std::unordered_map<T, std::unordered_set<state_labelt>>
when;
A state is a set of possibly active transitions.
std::unordered_set< state_labelt > possible_states
bool contains(state_labelt state_label) const
std::unordered_map< T, std::unordered_set< state_labelt > > when
std::unordered_set< state_labelt > arbitrary
std::unordered_set< state_labelt > epsilon
Very simple NFA implementation Not super performant, but should be good enough for our purposes.
statet initial_state(state_labelt initial) const
statet next_state(const statet ¤t, const T &input) const
void resize_if_necessary(state_labelt from, state_labelt to)
void add_arbitrary_transition(state_labelt from, state_labelt to)
Add a transition from "from" to "to" when any input is consumed This is handled a special case so not...
std::vector< transitiont > transitions
void dump_automaton_dot_to(std::ostream &out) const
Write the automaton structure to out in graphviz dot format.
void follow_epsilon_transitions(statet &state) const
void add_transition(state_labelt from, T when, state_labelt to)
Add a transition from "from" to "to" exactly when "when" is consumed.
void add_epsilon_transition(state_labelt from, state_labelt to)
Add a transition from "from" to "to" that doesn’t consume input.