Underload interpreter by tabasa

da=gets.chomp\x0d
$s=[]\x0d
\x0d
def intpr src,s\x0d
 le=src.size\x0d
 t=0\x0d
 while t<le\x0d
     #p s,src[t..-1],le,t\x0d
\x09 case src[t,1]\x0d
\x09 when ':'\x0d
\x09   s<<s[-1]\x0d
\x09 when '!'\x0d
\x09   s.pop\x0d
\x09 when '^'\x0d
\x09   s=intpr s.pop,s\x0d
\x09 when '~'\x0d
\x09   a=s.pop\x0d
\x09   b=s.pop\x0d
\x09   s+=[a,b]\x0d
\x09 when '*'\x0d
\x09   a=s.pop\x0d
\x09   a=s.pop+a\x0d
\x09   s<<a\x0d
\x09 when 'S'\x0d
\x09   print s.pop\x0d
\x09 when 'a'\x0d
\x09   s<<"("+s.pop+")"\x0d
\x09 when '('\x0d
\x09 c=0\x0d
\x09 le.times{|i|\x0d
\x09 c+=1 if src[t+i,1]=="("\x0d
\x09 c-=1 if src[t+i,1]==")"\x0d
\x09 (c=i;break)if c==0\x0d
\x09 }\x0d
\x09   /\(([^\)]*)\)/=~src[t..-1]\x0d
\x09   s<<src[t+1,c-1]\x0d
\x09   t+=c\x0d
\x09 else\x0d
\x09 end\x0d
\x09 t+=1\x0d
 end\x0d
 s\x0d
end\x0d
\x0d
$s=intpr da,$s\x0d
\x0d
# p $s

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page