Created
October 21, 2015 22:56
-
-
Save tyler-boyd/f978f7d17d41bc43b9e0 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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