//========================================================================================================== // Calculate the epsiolon closure for a state in the NFA. This is needed for constructing the DFA. //========================================================================================================== set<int> DFA::calc_epsilon_closure(int state, NFA& nfa) { set<int> res; vector<int> cur_states; res.insert(state); cur_states.push_back(state); //------------------------------------------------------------------------------------------------------ // As long as there are states in the list, add their epsilon neighbors, but only if they weren't added // yet //------------------------------------------------------------------------------------------------------ for(int i = 0; i < cur_states.size(); ++i) { for(int s: nfa.get_epsilon_transitions(cur_states[i])) { if(res.count(s) == 0) { res.insert(s); cur_states.push_back(s); } } } return res; }