input = (ARGV[1] && ARGV[1] != '-') ? File.open(ARGV[1], "r") : STDIN
statements = []
input.each_line.each_with_index do
vars = [{ var: 'b', var2: 'c' }]
ce = ''
line.each_char do
if /[0-9]/ === c
ce += c
elsif ce.length > 0
var = vars.last
case ARGV[0]
when '1'
statements << " = "
when '2'
statements << " = "
var[:o2] = '+'
end
ce = ''
end
if /[\*\+]/ === c
case ARGV[0]
when '1'
vars.last[:op] = c
when '2'
var = vars.last
if '*' === c
statements << " = "
var[:o2] = nil
var[:o1] = '*'
else
end
end
elsif '(' === c
var = vars.last
vars << case ARGV[0]
when '1'
{ var: var[:var].succ }
when '2'
s = var[:var2].succ
{ var: s, var2: s.succ }
end
elsif ')' === c
var = vars.pop
next_var = vars.last
case ARGV[0]
when '1'
statements << " = "
when '2'
statements << " = "
statements << " = "
next_var[:o2] = '+'
end
end
end
if '2' === ARGV[0]
if ce.length > 0
statements << " = "
end
statements << " = "
end
statements << "a = b"
end
func = "-> do\n\n a\nend"
func = binding.eval func
puts func.call