Created
April 13, 2009 13:23
-
-
Save bmaland/94442 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rton" | |
include Automaton | |
pda = Automaton.setup(:pda) do | |
initial_state :q0 do | |
transition ['a', EMPTY], [:q0, 'A'] | |
transition ['b', 'A'], [:q1, EMPTY] | |
end | |
state :q1 do | |
transition ['b', 'A'], [:q1, EMPTY] | |
end | |
final_states :q0, :q1 | |
end | |
loop do | |
print "Input: " | |
input = gets | |
break if input.nil? | |
input = input.chomp.strip.split("") # simple tokenization | |
if pda.recognize?(input) | |
puts "The input was recognized by the automaton" | |
else | |
puts "The input was rejected by the automaton" | |
end | |
end | |
# $ ruby rton_cli.rb | |
# Input: aabb | |
# The input was recognized by the automaton | |
# Input: aaaabbbb | |
# The input was recognized by the automaton | |
# Input: abb | |
# The input was rejected by the automaton |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment