------art_14526_5119337.1196684011257
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

Sorry, in previous post I forgot about parenthess in case of - and /.

# this program understands simple operations and also sin, cos, tg and ctg
# to use, provide string in RPN as argument
# example: ruby postf2inf '3 5 + sin 5 3 cos + /'
# result in "sin(3 + 5) / (5 + cos(3))"

str_postf ۰
str_inf
prior  '+','-','*','/'}
stack  tr_postf.split(' ')

0.upto stack.size-1 do |l|
  if ['+','-','*','/'].include?(stack[l])
    arg1  tr_inf.pop
    arg2  tr_inf.pop
    arg1[1]'+arg1[1]+')' if arg1[0]<prior[stack[l]]
    arg1[1]'+arg1[1]+')' if ['-','/'].include?(stack[l]) and
arg1[0]rior[stack[l]]
    arg2[1]'+arg2[1]+')' if arg2[0]<prior[stack[l]]
    str_inf.push([prior[stack[l]] , arg2[1]+" #{stack[l]} "+arg1[1]])
  elsif ['sin','cos','tg','ctg'].include?(stack[l])
    str_inf.push([5 , "#{stack[l]}(#{str_inf.pop[1]})"])
  else
    str_inf.push([5,stack[l]])
  end
end

p str_inf.pop[1]

------art_14526_5119337.1196684011257--