Class: Ibex::LALR::IELR::StateSplitter
- Inherits:
-
Object
- Object
- Ibex::LALR::IELR::StateSplitter
- Defined in:
- lib/ibex/lalr/ielr/state_splitter.rb
Overview
Splits LR(0) isocores only where an inadequacy would change the resolved action. New states copy their transition arrays; no mutable transition table is shared between isocores.
Instance Attribute Summary collapse
-
#annotations ⇒ Object
readonly
: Array[Array[Annotation]].
-
#inadequacies ⇒ Object
readonly
: Array[Array[Inadequacy]].
-
#lalr_isocores ⇒ Object
readonly
: Array.
-
#split_stable_discarded ⇒ Object
readonly
: Integer.
-
#split_states ⇒ Object
readonly
: Integer.
-
#states ⇒ Object
readonly
: Array.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(grammar, states, transitions, items, goto_follows, resolver: nil) ⇒ StateSplitter
constructor
rubocop:disable Metrics/AbcSize -- initialization wires the phase tables once.
Constructor Details
#initialize(grammar, states, transitions, items, goto_follows, resolver: nil) ⇒ StateSplitter
rubocop:disable Metrics/AbcSize -- initialization wires the phase tables once.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/ibex/lalr/ielr/state_splitter.rb', line 29 def initialize(grammar, states, transitions, items, goto_follows, resolver: nil) @grammar = grammar @base_states = states @base_transitions = transitions @base_items = items @goto_follows = goto_follows @resolver = resolver || ConflictResolver.new(grammar) @kernel_cores = states.map { |state| kernel_items(state) } annotator = Annotator.new(grammar, states, transitions, items, goto_follows, resolver: @resolver) @annotations = annotator.build @inadequacies = annotator.inadequacies @split_stable_discarded = annotator.split_stable_discarded @item_lookaheads = annotator.item_lookaheads @states = states.each_with_index.map do |_state, state_id| SplitState.new(core: @kernel_cores.fetch(state_id), transitions: transitions.fetch(state_id).sort_by(&:first).map(&:dup), lalr_isocore: state_id) end @lalr_isocores = states.each_index.to_a @isocore_nexts = states.each_index.to_a @lookaheads_recomputed = Array.new(states.length, false) @lookahead_sets = states.each_with_index.map do |_state, state_id| @kernel_cores.fetch(state_id).each_index.map do |index| @item_lookaheads.fetch(state_id, index) end end @filters = {} @split_states = 0 end |
Instance Attribute Details
#annotations ⇒ Object (readonly)
: Array[Array[Annotation]]
19 20 21 |
# File 'lib/ibex/lalr/ielr/state_splitter.rb', line 19 def annotations @annotations end |
#inadequacies ⇒ Object (readonly)
: Array[Array[Inadequacy]]
23 24 25 |
# File 'lib/ibex/lalr/ielr/state_splitter.rb', line 23 def inadequacies @inadequacies end |
#lalr_isocores ⇒ Object (readonly)
: Array
21 22 23 |
# File 'lib/ibex/lalr/ielr/state_splitter.rb', line 21 def lalr_isocores @lalr_isocores end |
#split_stable_discarded ⇒ Object (readonly)
: Integer
24 25 26 |
# File 'lib/ibex/lalr/ielr/state_splitter.rb', line 24 def split_stable_discarded @split_stable_discarded end |
#split_states ⇒ Object (readonly)
: Integer
22 23 24 |
# File 'lib/ibex/lalr/ielr/state_splitter.rb', line 22 def split_states @split_states end |
#states ⇒ Object (readonly)
: Array
20 21 22 |
# File 'lib/ibex/lalr/ielr/state_splitter.rb', line 20 def states @states end |
Instance Method Details
#build ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ibex/lalr/ielr/state_splitter.rb', line 61 def build state_id = 0 while state_id < @states.length @states.fetch(state_id).transitions.each_index do |index| target = @states.fetch(state_id).transitions.fetch(index).fetch(1) compute_state(state_id, target, index) end state_id += 1 end [pack_items, packed_transitions] end |