Skip to content

Instantly share code, notes, and snippets.

@bkerley
Created June 12, 2012 01:07
Show Gist options
  • Save bkerley/2913759 to your computer and use it in GitHub Desktop.
Save bkerley/2913759 to your computer and use it in GitHub Desktop.
@stack = []
@stack.push 3
@stack.push 5
@stack.push(@stack.pop + @stack.pop)
puts @stack.pop
3 5 add printi
require 'pp'
program = $stdin.read
puts "@stack = []"
split_prog = program.split
split_prog.each do |thing|
case thing
when /^\d+$/
puts "@stack.push #{thing.to_i}"
when 'add'
puts "@stack.push(@stack.pop + @stack.pop)"
when 'mult'
puts "@stack.push(@stack.pop * @stack.pop)"
when 'printi'
puts "puts @stack.pop"
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment