Method: Journey::NFA::TransitionTable#generalized_table
- Defined in:
- lib/journey/nfa/transition_table.rb
#generalized_table ⇒ Object
Returns a generalized transition graph with reduced states. The states are reduced like a DFA, but the table must be simulated like an NFA.
Edges of the GTG are regular expressions
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/journey/nfa/transition_table.rb', line 52 def generalized_table gt = GTG::TransitionTable.new marked = {} state_id = Hash.new { |h,k| h[k] = h.length } alphabet = self.alphabet stack = [eclosure(0)] until stack.empty? state = stack.pop next if marked[state] || state.empty? marked[state] = true alphabet.each do |alpha| next_state = eclosure(following_states(state, alpha)) next if next_state.empty? gt[state_id[state], state_id[next_state]] = alpha stack << next_state end end final_groups = state_id.keys.find_all { |s| s.sort.last == accepting } final_groups.each do |states| id = state_id[states] gt.add_accepting id save = states.find { |s| @memos.key?(s) && eclosure(s).sort.last == accepting } gt.add_memo id, memo(save) end gt end |