Class: Ibex::Verify::LanguageWitness::CanonicalMachine

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/verify/language_witness.rb

Overview

Canonical collection is intentionally built here rather than through the production construction entry point, keeping this witness independent from construction code.

Instance Method Summary collapse

Constructor Details

#initialize(grammar, max_states:, max_items:) ⇒ CanonicalMachine

Returns a new instance of CanonicalMachine.



145
146
147
148
149
150
151
152
# File 'lib/ibex/verify/language_witness.rb', line 145

def initialize(grammar, max_states:, max_items:)
  collection = ReferenceCollection.new(
    grammar, max_states: max_states, max_items: max_items
  ).build(:lr1)
  @grammar = grammar
  @states = build_states(collection)
  @entry_states = grammar.starts.each_with_index.to_h
end

Instance Method Details

#simulate(entry, tokens) ⇒ Object



155
156
157
158
# File 'lib/ibex/verify/language_witness.rb', line 155

def simulate(entry, tokens)
  state = @entry_states.fetch(entry)
  Machine.new(@states, @grammar).simulate(state, tokens)
end