Skip to content

Instantly share code, notes, and snippets.

@tyler-boyd
Created October 21, 2015 22:56
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 tyler-boyd/f978f7d17d41bc43b9e0 to your computer and use it in GitHub Desktop.
Save tyler-boyd/f978f7d17d41bc43b9e0 to your computer and use it in GitHub Desktop.
states = ['start']
transitions = []
final_states = []
simple_symbols = '()[]{}!=<>+-*/%;&,'.split('')
special_symbols = [">=", "<=", "==", "!="]
alpha = ('A'.ord .. 'Z'.ord).map(&:chr) + ('a'.ord .. 'z'.ord).map(&:chr)
numeric = (1..9).map(&:to_s)
alphabet = alpha + numeric + simple_symbols + ['0']
stupid_symbols = ['!']
simple_symbols.each do |symbol|
transitions << "start #{symbol} #{symbol}"
states << symbol
final_states << symbol unless stupid_symbols.include? symbol
end
special_symbols.each do |special_symbol|
transitions << "#{special_symbol[0]} #{special_symbol[1]} #{special_symbol}"
states << special_symbol
final_states << special_symbol
end
alpha.each do |symbol|
transitions << "start #{symbol} id"
transitions << "id #{symbol} id"
states << 'id'
end
final_states << "id"
numeric.each do |symbol|
transitions << "start #{symbol} number"
transitions << "number #{symbol} number"
# transitions << "- #{symbol} negnumber"
# transitions << "negnumber #{symbol} negnumber"
transitions << "id #{symbol} id"
end
states << 'number'
# states << 'negnumber'
transitions << "number 0 number"
transitions << "id 0 id"
# transitions << "negnumber 0 negnumber"
final_states << "number"
# final_states << "negnumber"
states << 'zero'
transitions << "start 0 zero"
final_states << "zero"
puts alphabet.size
alphabet.each { |s| puts s }
puts states.uniq.size
states.uniq.each { |s| puts s }
puts 'start'
puts final_states.uniq.size
final_states.uniq.each { |s| puts s }
puts transitions.uniq.size
transitions.uniq.each { |s| puts s }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment