Skip to content

Commit

Permalink
Rewind the version
Browse files Browse the repository at this point in the history
  • Loading branch information
junk0612 committed Sep 25, 2024
1 parent 0e60548 commit 30a5755
Showing 1 changed file with 23 additions and 26 deletions.
49 changes: 23 additions & 26 deletions lib/lrama/state.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def rr_conflicts
end

def propagate_lookaheads(next_state)
next_state.kernels.to_h {|item|
next_state.kernels.map {|item|
lookahead_sets =
if item.position == 1
goto_follow_set(item.lhs)
Expand All @@ -169,7 +169,7 @@ def propagate_lookaheads(next_state)
end

[item, lookahead_sets & next_state.lookahead_set_filters[item]]
}
}.to_h
end

def lookaheads_recomputed
Expand All @@ -186,21 +186,22 @@ def compatible_lookahead?(filtered_lookahead)
end

def lookahead_set_filters
kernels.to_h {|kernel|
kernels.map {|kernel|
[kernel,
@lalr_isocore.annotation_list.filter_map {|token, actions|
filter = token.term? && actions.any? {|action, contributions|
@lalr_isocore.annotation_list.filter {|token, actions|
token.term? && actions.any? {|action, contributions|
!contributions.nil? && contributions.key?(kernel) && contributions[kernel]
}
filter && token
}]
}
}.map {|token, _| token }
]
}.to_h
end

def dominant_contribution(token, actions, lookaheads)
a = actions.filter_map {|action, contributions|
action if contributions.nil? || contributions.any? {|item, contributed| contributed && lookaheads[item].include?(token) }
}
a = actions.filter {|action, contributions|
contributions.nil? || contributions.any? {|item, contributed| contributed && lookaheads[item].include?(token) }
}.map {|action, _| action }
return nil if a.empty?
a.reject {|action|
if action.is_a?(State::Shift)
Expand All @@ -214,14 +215,14 @@ def dominant_contribution(token, actions, lookaheads)
def inadequacy_list
return @inadequacy_list if @inadequacy_list

shift_contributions = shifts.to_h {|shift|
shift_contributions = shifts.map {|shift|
[shift.next_sym, [shift]]
}
}.to_h
reduce_contributions = reduces.map {|reduce|
(reduce.look_ahead || []).to_h {|sym|
(reduce.look_ahead || []).map {|sym|
[sym, [reduce]]
}
}.reduce(Hash.new([])) {|hash, cont|
}.to_h.reduce(Hash.new([])) {|hash, cont|
hash.merge(cont) {|_, a, b| a.union(b) }
}

Expand Down Expand Up @@ -249,18 +250,18 @@ def annotation_list

def annotate_manifestation
inadequacy_list.transform_values {|actions|
actions.to_h {|action|
actions.map {|action|
if action.is_a?(Shift)
[action, nil]
elsif action.is_a?(Reduce)
if action.rule.empty_rule?
[action, lhs_contributions(action.rule.lhs, inadequacy_list.key(actions))]
else
contributions = kernels.to_h {|kernel| [kernel, kernel.rule == action.rule && kernel.end_of_rule?] }
contributions = kernels.map {|kernel| [kernel, kernel.rule == action.rule && kernel.end_of_rule?] }.to_h
[action, contributions]
end
end
}
}.to_h
}
end

Expand All @@ -275,14 +276,14 @@ def annotate_predecessor(predecessor)
if lhs_adequacy
next nil
else
predecessor.kernels.to_h {|pred_k|
predecessor.kernels.map {|pred_k|
[pred_k, kernels.any? {|k|
inadequacy[k] && (
pred_k.predecessor_item_of?(k) && predecessor.item_lookahead_set[pred_k].include?(token) ||
k.position == 1 && predecessor.lhs_contributions(k.lhs, token)[pred_k]
)
}]
}
}.to_h
end
}
}
Expand All @@ -293,7 +294,7 @@ def lhs_contributions(sym, token)
if always_follows(shift, next_state).include?(token)
nil
else
kernels.to_h {|kernel| [kernel, follow_kernel_items(shift, next_state, kernel) && item_lookahead_set[kernel].include?(token)] }
kernels.map {|kernel| [kernel, follow_kernel_items(shift, next_state, kernel) && item_lookahead_set[kernel].include?(token)] }.to_h
end
end

Expand All @@ -310,7 +311,7 @@ def follow_kernel_items(shift, next_state, kernel)
def item_lookahead_set
return @item_lookahead_set if @item_lookahead_set

kernels.to_h {|item|
kernels.map {|item|
value =
if item.lhs.accept_symbol?
[]
Expand All @@ -323,7 +324,7 @@ def item_lookahead_set
prev_state.goto_follows(shift, next_state)
end
[item, value]
}
}.to_h
end

def item_lookahead_set=(k)
Expand All @@ -340,10 +341,6 @@ def predecessors_with_item(item)
result
end

def next_terms
shifts.filter_map {|shift| shift.next_sym.term? && shift.next_sym }
end

def append_predecessor(prev_state)
@predecessors << prev_state
@predecessors.uniq!
Expand Down

0 comments on commit 30a5755

Please sign in to comment.