PUSH
Designed by | Expliked |
---|---|
Appeared in | 2020 |
Memory system | Stack-based |
Computational class | Pushdown automata |
Major implementations | https://github.com/expliked/PUSH |
File extension(s) | *.txt |
PUSH is an esoteric programming language created by User:Expliked in November 2020. It is a stack-based language.
Syntax
Keyword | Meaning |
---|---|
PUSH: (integer);
|
Pushes the given value to the stack. |
ADD: (integer);
|
Adds the given value to the last value of the stack. |
SUBTRACT: (integer);
|
Subtracts the given value to the last value of the stack. |
PULL;
|
Outputs the first value from the stack, then removes it. |
INPUT;
|
Prompts for user input. Each individual character will be stored in the stack. |
DO;
|
Starts a do-while loop. A do-while loop cannot be created inside another do-while loop. |
WHILE;
|
The end of a do-while loop. If the last value of the stack is not 0, it will jump back to the DO; statement.
|
CLEAR;
|
Clears the stack. |
[
|
Denotes the start of a comment. |
]
|
Denotes the end of a comment. |
Code structure
In PUSH, spaces, newlines, carriage returns, and tabs are ignored.
All keywords must have a ;
after them.
Examples
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!"
The 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.
More examples
Cat program (expects at least one character of input):
INPUT; DO; PULL; WHILE;
https://pastebin.com/TQVxJT9v