Skip to main content
2 of 6
added an explanation
Arnauld
  • 205.5k
  • 21
  • 187
  • 670

JavaScript (V8), 178 bytes

Transpiles to JS. Throws Z is not defined in case of division by zero.

s=>eval(s.replace(/./g,c=>`x=S.pop();S.push(${c>'}'?'x,Math.random()*1e5|0':c>'9'?'x,x':c=='.'?'x);print(x':c<')'?'x);do{(0':c<'*'?'x)}while(x':`1/(x${c}=S.pop())?x:Z`});`,S=[])) 

Try the 1st program online!

Try the 2nd program online!

Try the 3rd program online!

###How?

Each instruction is transpiled to x=S.pop();S.push(, followed by a specific pattern, followed by );.

 char. | JS code -------+-------------------------------------------- ~ | x=S.pop();S.push( x,Math.random()*1e5|0 ); + | x=S.pop();S.push( 1/(x+=S.pop())?x:Z ); - | x=S.pop();S.push( 1/(x-=S.pop())?x:Z ); * | x=S.pop();S.push( 1/(x*=S.pop())?x:Z ); / | x=S.pop();S.push( 1/(x/=S.pop())?x:Z ); : | x=S.pop();S.push( x,x ); . | x=S.pop();S.push( x);print(x ); ( | x=S.pop();S.push( x);do{(0 ); ) | x=S.pop();S.push( x)}while(x ); 
Arnauld
  • 205.5k
  • 21
  • 187
  • 670