Class: Aurum::Grammar::LexicalRules::HopcroftMinimizer

Inherits:
Object
  • Object
show all
Defined in:
lib/aurum/grammar/automata.rb

Instance Method Summary collapse

Constructor Details

#initialize(deterministic, accepts) ⇒ HopcroftMinimizer

Returns a new instance of HopcroftMinimizer.



126
127
128
# File 'lib/aurum/grammar/automata.rb', line 126

def initialize deterministic, accepts
  @deterministic, @accepts = deterministic, accepts
end

Instance Method Details

#minimizeObject



130
131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/aurum/grammar/automata.rb', line 130

def minimize
  make_initial_partitions
  refine_partitions
  automata, accepts =  Aurum::Grammar::LexicalRules::Automata.new(@partitions.size), {}
  choose_representatives do |representative, index|
    @deterministic.table[representative].each do |transition|
      automata.connect(index, transition.character_set, partition_contains(transition.destination))
    end
    accepts[index] = @accepts[representative] if @accepts.has_key? representative
  end
  automata.remove_dead_states(accepts.keys)
  return automata, accepts
end