Class: Ibex::Verify::LanguageWitness::Machine

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

Overview

A stack machine shared by the canonical reference and submitted IR.

Instance Method Summary collapse

Constructor Details

#initialize(states, grammar) ⇒ Machine

Returns a new instance of Machine.



243
244
245
246
247
# File 'lib/ibex/verify/language_witness.rb', line 243

def initialize(states, grammar)
  @states = states
  @grammar = grammar
  @eof = grammar.symbol("$eof") || raise(Ibex::Error, "missing $eof terminal")
end

Instance Method Details

#simulate(initial, tokens) ⇒ Object



250
251
252
253
254
255
256
257
258
259
260
261
# File 'lib/ibex/verify/language_witness.rb', line 250

def simulate(initial, tokens)
  stack = [initial]
  tokens.each do |token_id|
    status = consume(stack, token_id)
    return status unless status == :shifted
  end
  loop do
    status = consume(stack, @eof.id)
    return :accepted if status == :accepted
    return :error unless status == :shifted
  end
end