Class: Ibex::LALR::IELR::Annotator
- Inherits:
-
Object
- Object
- Ibex::LALR::IELR::Annotator
- Defined in:
- lib/ibex/lalr/ielr/annotator.rb
Overview
Finds grammar-relative inadequacies and traces their possible manifestations through predecessor states.
Instance Attribute Summary collapse
-
#annotation_lists ⇒ Object
readonly
: Array[Array[Annotation]].
-
#inadequacies ⇒ Object
readonly
: Array[Array[Inadequacy]].
-
#item_lookaheads ⇒ Object
readonly
: ItemLookaheads.
-
#split_stable_discarded ⇒ Object
readonly
: Integer.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(grammar, states, transitions, items, goto_follows, resolver: nil) ⇒ Annotator
constructor
A new instance of Annotator.
Constructor Details
#initialize(grammar, states, transitions, items, goto_follows, resolver: nil) ⇒ Annotator
Returns a new instance of Annotator.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/ibex/lalr/ielr/annotator.rb', line 28 def initialize(grammar, states, transitions, items, goto_follows, resolver: nil) @grammar = grammar @states = states @transitions = transitions @items = items @goto_follows = goto_follows @resolver = resolver || ConflictResolver.new(grammar) @kernel_cores = states.map { |state| kernel_items(state) } @item_lookaheads = ItemLookaheads.new( grammar, goto_follows, @kernel_cores, goto_follows.predecessors, start_states: (0...grammar.starts.length).to_a ) @annotation_lists = Array.new(states.length) { [] } @keys = Array.new(states.length) { Set.new } @inadequacies = Array.new(states.length) { [] } @next_id = 0 @split_stable_discarded = 0 end |
Instance Attribute Details
#annotation_lists ⇒ Object (readonly)
: Array[Array[Annotation]]
21 22 23 |
# File 'lib/ibex/lalr/ielr/annotator.rb', line 21 def annotation_lists @annotation_lists end |
#inadequacies ⇒ Object (readonly)
: Array[Array[Inadequacy]]
22 23 24 |
# File 'lib/ibex/lalr/ielr/annotator.rb', line 22 def inadequacies @inadequacies end |
#item_lookaheads ⇒ Object (readonly)
: ItemLookaheads
23 24 25 |
# File 'lib/ibex/lalr/ielr/annotator.rb', line 23 def item_lookaheads @item_lookaheads end |
#split_stable_discarded ⇒ Object (readonly)
: Integer
24 25 26 |
# File 'lib/ibex/lalr/ielr/annotator.rb', line 24 def split_stable_discarded @split_stable_discarded end |
Instance Method Details
#build ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ibex/lalr/ielr/annotator.rb', line 48 def build @states.each_index do |state_id| @inadequacies[state_id] = build_inadequacies(state_id) @inadequacies.fetch(state_id).each do |inadequacy| register?(state_id, annotate_manifestation(state_id, inadequacy)) end end worklist = @annotation_lists.each_with_index.flat_map do |annotations, state_id| annotations.map { |annotation| [state_id, annotation] } end cursor = 0 while cursor < worklist.length state_id, annotation = worklist.fetch(cursor) cursor += 1 @goto_follows.predecessors.fetch(state_id).each do |previous| derived = annotate_predecessor(previous, state_id, annotation) worklist << [previous, derived] if register?(previous, derived) end end @annotation_lists end |