Class: Lrama::Counterexamples

Inherits:
Object
  • Object
show all
Defined in:
lib/lrama/counterexamples.rb,
lib/lrama/counterexamples/path.rb,
lib/lrama/counterexamples/triple.rb,
lib/lrama/counterexamples/example.rb,
lib/lrama/counterexamples/derivation.rb,
lib/lrama/counterexamples/start_path.rb,
lib/lrama/counterexamples/state_item.rb,
lib/lrama/counterexamples/production_path.rb,
lib/lrama/counterexamples/transition_path.rb

Overview

See: www.cs.cornell.edu/andru/papers/cupex/cupex.pdf

4. Constructing Nonunifying Counterexamples

Defined Under Namespace

Classes: Derivation, Example, Path, ProductionPath, StartPath, StateItem, TransitionPath, Triple

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(states) ⇒ Counterexamples

Returns a new instance of Counterexamples.



20
21
22
23
24
# File 'lib/lrama/counterexamples.rb', line 20

def initialize(states)
  @states = states
  setup_transitions
  setup_productions
end

Instance Attribute Details

#productionsObject (readonly)

Returns the value of attribute productions.



18
19
20
# File 'lib/lrama/counterexamples.rb', line 18

def productions
  @productions
end

#transitionsObject (readonly)

Returns the value of attribute transitions.



18
19
20
# File 'lib/lrama/counterexamples.rb', line 18

def transitions
  @transitions
end

Instance Method Details

#compute(conflict_state) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/lrama/counterexamples.rb', line 31

def compute(conflict_state)
  conflict_state.conflicts.flat_map do |conflict|
    case conflict.type
    when :shift_reduce
      # @type var conflict: State::ShiftReduceConflict
      shift_reduce_example(conflict_state, conflict)
    when :reduce_reduce
      # @type var conflict: State::ReduceReduceConflict
      reduce_reduce_examples(conflict_state, conflict)
    end
  end.compact
end

#to_sObject Also known as: inspect



26
27
28
# File 'lib/lrama/counterexamples.rb', line 26

def to_s
  "#<Counterexamples>"
end