Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/lrama/reporter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def report(io, states)
@terms.report(io, states)
@conflicts.report(io, states)
@grammar.report(io, states)
@states.report(io, states)
@states.report(io, states, ielr: states.ielr_defined?)
end
end
end
Expand Down
41 changes: 39 additions & 2 deletions lib/lrama/reporter/states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def initialize(itemsets: false, lookaheads: false, solved: false, counterexample
@verbose = verbose
end

# @rbs (IO io, Lrama::States states) -> void
def report(io, states)
# @rbs (IO io, Lrama::States states, ielr: bool) -> void
def report(io, states, ielr: false)
if @counterexamples
cex = Counterexamples.new(states)
end
Expand Down Expand Up @@ -179,6 +179,43 @@ def report(io, states)
end
end

if ielr && !state.annotation_list.empty?
state.annotation_list.each do |annotation|
# binding.irb
io << " inadequacy annotation manifesting state #{annotation.state.id}, token #{annotation.token.id.s_value}\n"

annotation.contribution_matrix.each do |action, contributions|
case action
when State::Shift
io << " state #{state.id} always contributes to shift by #{action.next_sym.id.s_value}\n"
when State::Reduce
reduce_rule = action.item.rule
reduce_rule_text = "#{reduce_rule.lhs.display_name}: #{reduce_rule.rhs.map(&:display_name).join(" ")}"

if contributions
contributions.each do |item, contribution|
if item.empty_rule?
r = "ε •"
else
r = item.rhs.map(&:display_name).insert(item.position, "•").join(" ")
end

if contribution
io << " '#{r}' potentially contributes to reduce by '#{reduce_rule_text}'\n"
else
io << " '#{r}' never contributes to reduce by '#{reduce_rule_text}'\n"
end
end
else
io << " state #{state.id} always contributes to reduce by '#{reduce_rule_text}'\n"
end
end
end
end

io << "\n"
end

if @verbose
# Report direct_read_sets
io << " [Direct Read sets]\n"
Expand Down
2 changes: 1 addition & 1 deletion lib/lrama/states.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class States
include Lrama::Tracer::Duration

def_delegators "@grammar", :symbols, :terms, :nterms, :rules,
:accept_symbol, :eof_symbol, :undef_symbol, :find_symbol_by_s_value!
:accept_symbol, :eof_symbol, :undef_symbol, :find_symbol_by_s_value!, :ielr_defined?

attr_reader :states, :reads_relation, :includes_relation, :lookback_relation

Expand Down
4 changes: 2 additions & 2 deletions sig/generated/lrama/reporter/states.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ module Lrama
# @rbs (itemsets: bool, lookaheads: bool, solved: bool, counterexamples: bool, verbose: bool, **untyped _) -> void
def initialize: (itemsets: bool, lookaheads: bool, solved: bool, counterexamples: bool, verbose: bool, **untyped _) -> void

# @rbs (IO io, Lrama::States states) -> void
def report: (IO io, Lrama::States states) -> void
# @rbs (IO io, Lrama::States states, ielr: bool) -> void
def report: (IO io, Lrama::States states, ielr: bool) -> void
end
end
end
24 changes: 24 additions & 0 deletions spec/lrama/states_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1824,6 +1824,10 @@ class go to state 5

S go to state 3

inadequacy annotation manifesting state 14, token a
state 0 always contributes to shift by a
state 0 always contributes to reduce by 'E: '


State 1

Expand All @@ -1833,6 +1837,10 @@ class go to state 5

A go to state 5

inadequacy annotation manifesting state 14, token a
state 1 always contributes to shift by a
state 1 always contributes to reduce by 'E: '


State 2

Expand All @@ -1842,6 +1850,10 @@ class go to state 5

A go to state 6

inadequacy annotation manifesting state 14, token a
state 2 always contributes to shift by a
'b • A B b' never contributes to reduce by 'E: '


State 3

Expand All @@ -1859,6 +1871,10 @@ class go to state 5
C go to state 9
D go to state 10

inadequacy annotation manifesting state 14, token a
state 4 always contributes to shift by a
'a • C D E' potentially contributes to reduce by 'E: '


State 5

Expand Down Expand Up @@ -1904,6 +1920,10 @@ class go to state 5

D go to state 14

inadequacy annotation manifesting state 14, token a
state 9 always contributes to shift by a
'a C • D E' potentially contributes to reduce by 'E: '


State 10

Expand Down Expand Up @@ -1941,6 +1961,10 @@ class go to state 5

E go to state 18

inadequacy annotation manifesting state 14, token a
state 14 always contributes to shift by a
'a C D • E' potentially contributes to reduce by 'E: '


State 15

Expand Down