Class: Ibex::LALR::IELRPartition
- Inherits:
-
Object
- Object
- Ibex::LALR::IELRPartition
- Defined in:
- lib/ibex/lalr/ielr_partition.rb
Overview
Deterministically merges compatible canonical LR(1) states and splits partitions until their outgoing transitions are congruent.
Constant Summary collapse
- AUGMENTED_PRODUCTION =
@rbs! type contribution_action = [:shift] | [:reduce, Integer] | [:accept]
-1 #: Integer
Instance Attribute Summary collapse
-
#final_partition_count ⇒ Object
readonly
: Integer?.
- #initial_partition_count ⇒ Object readonly
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(grammar, states, transitions, profile: false) ⇒ IELRPartition
constructor
A new instance of IELRPartition.
Constructor Details
#initialize(grammar, states, transitions, profile: false) ⇒ IELRPartition
Returns a new instance of IELRPartition.
27 28 29 30 31 32 33 34 35 |
# File 'lib/ibex/lalr/ielr_partition.rb', line 27 def initialize(grammar, states, transitions, profile: false) @grammar = grammar @states = states @transitions = transitions @contributions = Array.new(states.length) { |state_id| action_contributions(state_id) } @initial_partition_count = nil @final_partition_count = nil @profile = profile end |
Instance Attribute Details
#final_partition_count ⇒ Object (readonly)
: Integer?
24 25 26 |
# File 'lib/ibex/lalr/ielr_partition.rb', line 24 def final_partition_count @final_partition_count end |
#initial_partition_count ⇒ Object (readonly)
23 24 25 |
# File 'lib/ibex/lalr/ielr_partition.rb', line 23 def initial_partition_count @initial_partition_count end |
Instance Method Details
#build ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ibex/lalr/ielr_partition.rb', line 38 def build partitions = initial_partitions @initial_partition_count = partitions.length if @profile partitions = refine_transitions(partitions) @final_partition_count = partitions.length if @profile indexes = partition_indexes(partitions) items = partitions.map { |members| merge_items(members) } transitions = partitions.map do |members| @transitions.fetch(members.first).to_h do |symbol_id, target| [symbol_id, indexes.fetch(target)] end end [items, transitions] end |