Pointstack

Pointstack is an esoteric programming language created by User:catto.4 in 2024. It is similar to brainfuck, except that it uses a stack instead of a tape. Items on the stack can only contain numbers.
== Commands ==
Symbol	Explanation
! 	Pushes a 0 to the top of the stack.
^ 	Increments the top value on the stack.
_ 	Decrements the top value on the stack.
+ 	Adds the top two values on the stack and pushes the result.
- 	Subtracts the top two values on the stack and pushes the result.
* 	Multiplies the top two values on the stack and pushes the result.
/ 	Divides the top two values on the stack and pushes the result.
. 	Pops the top value on the stack and prints it.
, 	Takes one byte of input as an ASCII character and pushes it to the top of the stack.
: 	Duplicates the top value on the stack.
$ 	Swaps the top two values on the stack.
? 	Pops and discards the top value on the stack.
[ 	Marks the start of a loop.
] 	If the top value on the stack is a 0, continue. Otherwise, jump back to the matching [.
= 	If the top two values on the stack are equal, discard those values and push a 1. Else, push a 0.
~ 	If the top two values on the stack are not equal, discard those values and push a 1. Else, push a 0.
` 	If the top value on the stack is a 0, then skip the next command.
\ 	If the top value on the stack is a 1, then skip the next command.
== Examples ==
=== Hello World ===
Outputs "Hello World".
 !^^^^^^^^!^^^^^^^^^*.
 !^^^^^^^^^^!^^^^^^^^^^*^.
 !^^^^^^^^^!^^^^^^^^^^^^*:..
 !^^^^^^^^^^^!^^^^^^^^^^*^.
 !^^^^^^^^!^^^^*.
 !^^^^^^^^!^^^^^^^^^^^*_.
 !^^^^^^^^^^^!^^^^^^^^^^*^.
 !^^^^^^^!^^^^^^^^^^^^^^^^*^^.
 !^^^^^^^^^!^^^^^^^^^^^^*.
 !^^^^^^^^^^!^^^^^^^^^^*.
=== Cat program ===
Takes one character and outputs it.
 ,.
== Computational class ==
Pointstack's computational class is Turing-complete, as long as stack hold unbounded integers which would be shown by translating Portable Minsky Machine Notation to it:
The program starts with:
 !!
This will initialise the stack with two elements, each representing the register. To switch between this two registers we use swap command $. Incrementing and decrementing the reigster is easy, they can be done with ^ and _ respectively. With a while loop there is more difficulty, since I am not sure whether [...]is a while or do-while loop, so I will assume that it is a while loop, and if it actually was a do-while loop I would fix the translation. The while loop then would simply be [...] and an if statement would be :[?...!]?, what it does is duplicates the current register, so that if the statement is not true it would not remove actual register, if the condition is true then it would remove that duplicated element, after the code is executed it would push 0 and finish the loop, and then that zero is removed from the stack
 
== Interpreter ==
_windowsbuilder on Discord has written a C++ interpreter for Pointstack:
#include <stdio.h>
#define S 10000
void main(int a, char *b[]) {if (a < 2) return;int s[S]={0},p=-1,l[S],q=-1;char *c=b[1];while(*c){switch(*c){case'!':if(p+1<S)s[++p]=0;break;case'^':if(p>=0)s[p]++;break;case'_':if(p>=0)s[p]--;break;case'+':if(p>=1)s[p-1]+=s[p],p--;break;case'-':if(p>=1)s[p-1]-=s[p],p--;break;case'*':if(p>=1)s[p-1]*=s[p],p--;break;case'/':if(p>=1&&s[p])s[p-1]/=s[p],p--;break;case'.':if(p>=0)putchar(s[p]);break;case',':if(p+1<S)s[++p]=getchar();break;case':':if(p>=0&&p+1<S)s[p+1]=s[p],p++;break;case'$':if(p>=1){int t=s[p];s[p]=s[p-1];s[p-1]=t;}break;case'?':if(p>=0)p--;break;case'[':if(p>=0&&!s[p]){int r=1;while(r){c++;if(*c=='[')r++;if(*c==']')r--;}}else l[++q]=c-b[1];break;case']':if(p>=0&&s[p])c=b[1]+l[q];else q--;break;case'=':if(p>=1)s[p-1]=(s[p-1]==s[p])?1:0,p--;break;case'~':if(p>=1)s[p-1]=(s[p-1]!=s[p])?1:0,p--;break;case'`':if(p>=0&&!s[p])c++;break;case'\\':if(p>=0&&s[p])c++;break;}c++;}}
Category:Languages Category:Stack-based Category:Turing complete Category:Implemented Category:2024