118
4
章 能力を高める
end
def stuck?
state == STUCK_STATE
end
end
class DPDA
def
next_configuration(character)
if rulebook.applies_to?(current_configuration, character)
rulebook.next_configuration(current_configuration, character)
else
current_configuration.stuck
end
end
def stuck?
current_configuration.stuck?
end
def read_character(character)
self.current_configuration =
next_configuration(character)
end
def read_string(string)
strin
g.chars.each do |character|
read_character(character)
unless stuck?
end
end
end
これでDPDAは失敗することなく、行儀良く行き詰まり状態になります。
>>
dpda = DPDA.new(PDAConfiguration.new(1, Stack.new(['$'])), [1], rulebook)
=> #<struct DPDA ...>
>>
dpda.read_string('())'); ...