|Computational class||Pushdown automata|
PUSH is an esoteric programming language created by User:Expliked in November 2020. It is a stack-based language.
||Pushes the given value to the stack.|
||Adds the given value to the last value of the stack.|
||Subtracts the given value to the last value of the stack.|
||Outputs the first value from the stack, then removes it.|
||Prompts for user input. Each individual character will be stored in the stack.|
||Starts a do-while loop. A do-while loop cannot be created inside another do-while loop.|
||The end of a do-while loop. If the last value of the stack is not 0, it will jump back to the |
||Clears the stack.|
||Denotes the start of a comment.|
||Denotes the end of a comment.|
In PUSH, spaces, newlines, carriage returns, and tabs are ignored.
All keywords must have a
; after them.
Simple Hello, World! program:
PUSH: 72; PUSH: 101; PUSH: 108; PUSH: 108; PUSH: 111; PUSH: 44; PUSH: 32; PUSH: 87; PUSH: 111; PUSH: 114; PUSH: 108; PUSH: 100; PUSH: 33; PUSH: 10; [Output all characters:] DO; PULL; WHILE;
Breaking down "Hello, World!"
PULL keyword will output the first value of the stack, then delete that value. It then shifts all values after it to the left.
After we are done pushing all of our values to the stack, this is what it will appear as:
H e l l o , " " W o r l d ! \n 72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 10
After the first
PULL is used, the stack looks like this:
e l l o , " " W o r l d ! \n 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33, 10
If you repeat this process you will have eventually printed out all characters.
Instead of doing
PULL after every
PUSH, we can just use
DO; PULL; WHILE;. This will output every character until there are no more left.
Cat program (expects at least one character of input):
INPUT; DO; PULL; WHILE;