Skip to content

Instantly share code, notes, and snippets.

@robbrit
Created August 4, 2010 01:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save robbrit/507502 to your computer and use it in GitHub Desktop.
Save robbrit/507502 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
grammar, iterations, extra = ARGV
if grammar == nil or !File.exists?(grammar)
puts "no grammar file"
exit
end
symbols = {}
File.open(grammar, "r") do |file|
file.each do |line|
next if line =~ /^\s*#/
if line =~ /^\s*(\w+)\s*->\s*(.+)\s*$/
symbols[$1] = $2.split(//)
end
end
end
str = $stdin.gets.chomp.split(//)
iterations.to_i.times do
str = str.map { |c|
symbols.key?(c) ? symbols[c] : c
}.flatten
end
puts str.join + 0.chr
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment