All pastes #792589 Raw Edit

Stuff

public javascript v1 · immutable
·published 2007-11-21 15:24 UTC
rendered paste body
// Released to the public domain.// Modified by Elliott Hird to work standalone.var _={s: "", p:"",o:""};function pop(){  if(_.s.indexOf("<>")==-1) {throw("ERROR: Empty stack");}  var t=_.s.substr(0,_.s.indexOf("<>"));  _.s=_.s.substr(_.s.indexOf("<>")+2);  return t;}function push(t){  _.s=t+"<>"+_.s;}function step(){try{  var c=_.p.substr(0,1);  if(_.p=="") return _.o;  _.p=_.p.substr(1);  if(c=='S') _.o+=pop();  else if(c=='~') {var t1, t2; t1=pop(); t2=pop(); push(t1); push(t2);}  else if(c==':') {var t1; t1=pop(); push(t1); push(t1);}  else if(c=='!') pop();  else if(c=='*') {var t1, t2; t1=pop(); t2=pop(); push(t2+t1);}  else if(c=='a') {var t1; t1=pop(); push("("+t1+")");}  else if(c=='^') _.p=pop()+_.p;  else if(c==')') throw("ERROR: Unmatched )");  else if(c=='(')  {    var t1,i,n;    i=0; n=1;    while(n)    {      if(_.p.substr(i,1)==')') n--;      if(_.p.substr(i,1)=='(') n++;      i++;      if(i>_.p.length) throw("ERROR: Unmatched (");    }    t1=_.p.substr(0,i-1);    _.p=_.p.substr(i);    push(t1);  }  else throw("ERROR: Unrecognized command");  return step();}catch(s){  print(s);}}function unl2ul(){  var v=new Array();  var vi=0;  var c;  while(_.p!="")  {    c=_.p.substr(0,1);    _.p=_.p.substr(1);    if(c=='`') v[vi++]=0;    if(c=='.') {_.o+='.'; c=_.p.substr(0,1); _.p=_.p.substr(1);}    else if(c=='`') continue;    _.o+=c;    while(1)    {      if(v[vi-1]) {_.o+='`'; vi--;}      else {v[vi-1]=1; break;}    }  }  while(vi>0) {_.o+='`'; vi--;}  while(_.o!="")  {    c=_.o.substr(0,1);    _.o=_.o.substr(1);    if(c=='`') _.p+='~^';    if(c=='s') _.p+='((:)~*(~)*a(~*(~^)*)*)';    if(c=='k') _.p+='(a(!)~*)';    if(c=='i') _.p+='()';    if(c=='.')    {      c=_.o.substr(0,1);      _.o=_.o.substr(1);      _.p+='(('+c+')S)';    }  }  return _.p;}var op=readline();if (op == "0") {_.p=readline();print(step());} else if (op == "1") {_.p=readline();print(unl2ul());} else {print("wtf?");}