Skip to content

Instantly share code, notes, and snippets.

@usure
Last active August 29, 2015 14:27
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 usure/ebe2cc4129c197e22028 to your computer and use it in GitHub Desktop.
Save usure/ebe2cc4129c197e22028 to your computer and use it in GitHub Desktop.
stack lang
#!/usr/bin/env ruby
def push(element); $stack << element; end
def pop; $stack.pop end
$stack = []
$dictionary = {
'.' => -> { puts(pop) },
'..' => -> { puts($stack) },
'.,' => -> { pp($dictionary)},
'words' => -> { p $dictionary.keys.sort },
}
def parse(expression)
puts "=> #{expression}"
begin
expression.split.each do |statement| case; when $dictionary.has_key?(statement); $dictionary[statement].call; when statement == Integer; push statement.to_i; else push statement.to_str
end; end; end; end
puts "stackr."
while ARGV.size > 0; open(ARGV.shift).each { |line| parse(line) }; end
while true; print "[>] "; break unless gets; parse $_; end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment