Repository navigation
Home
S# (Simple Stack Script) is a lightweight, stack-based programming language designed for simplicity and power. It combines stack-based execution with variable support, making it an excellent choice for scripting, automation, and embedded systems. This is our official Wiki page hosted on GitHub!
Important
We are now an officially published Python package!!! Find us on PyPI, our project name is simplestackscript. Download on pip!
- Stack-Based Execution: Operates on a Last-In-First-Out (LIFO) stack.
- Named Variables: Store and retrieve values easily.
- Concise Syntax: Readable and intuitive for programmers.
- Control Flow: Supports conditionals and loops.
- Function Support: Define and reuse stack-based functions.
- Minimal & Fast: Designed for lightweight execution.
- Published Python Package: You can find our package as simplestackscript on PyPI.
- Enhanced Error Handling: Improved validation and debugging messages.
-
New Opcodes:
WAITfor delay execution and enhanced loop support.
If you are reading this on PyPI, please use the first installation choice below:
pip install simplestackscriptThis is the easiest way to install S#. pip will automatically download and install the latest version from PyPI. If you would rather install from source, follow the instructions below:
-
Clone the repository:
git clone https://github.com/CaptioDev/simplestackscript.git cd simplestackscript -
Install the interpreter:
pip install . # Installs the s3 command
-
Run an S3 program:
s3 my_program.s3
Note
You can also clone the repository using SSH and your GitHub Public Key by replacing the first line within the first step to: git clone git@github.com:CaptioDev/simplestackscript.git
S# uses a stack-based architecture, where most operations manipulate a stack of values. Instructions are processed sequentially.
-
PUSH <number>: Pushes the given<number>onto the top of the stack. -
POP: Removes the top element from the stack. -
DUP: Duplicates the top element of the stack and pushes the copy onto the stack. -
SWAP: Swaps the top two elements on the stack. -
OVER: Copies the second element from the top of the stack and pushes it onto the top. -
ROT: Rotates the top three elements of the stack. -
DROP: Discards (pops) the top element of the stack. -
NIP: Removes the second element from the top of the stack. -
TUCK: Copies the top element and inserts it under the second element.
-
ADD: Pops the top two elements from the stack, adds them, and pushes the result back onto the stack. -
SUB: Pops the top two elements (a, b) and pushesb - aonto the stack. -
MUL: Pops the top two elements, multiplies them, and pushes the result. -
DIV: Pops the top two elements (a, b) and performs integer divisionb // a, pushing the result.
-
PRINT <string_literal>: Prints the given<string_literal>to the console. -
READ: Reads an integer from the user's input and pushes it onto the stack. -
PRINT.TOP: Prints the value at the top of the stack without removing it.
-
JUMP <label>: Jumps to the specified<label>. -
JUMP.IF.0 <label>: Pops the top element. If it is 0, execution jumps to<label>. -
JUMP.IF.POS <label>: Pops the top element. If it is greater than 0, execution jumps to<label>. -
LOOP <line_number> <repeat_count>: Loops execution fromline_numberforrepeat_counttimes.
-
HALT: Terminates the program execution.
-
<label>:: A label marks a specific location in the program code. Used as a target for jump instructions.
-
WAIT <milliseconds>: Pauses execution for the specified number of milliseconds before proceeding.
# Example: Adding two numbers
PUSH 5
PUSH 10
ADD
PRINT.TOP # Output: 15
HALT
# Example: Input and output
PRINT "Enter a number:"
READ
PRINT "You entered:"
PRINT.TOP
HALT
# Example: Looping
PUSH 5
LOOP 0 3 # Loop 3 times, jumping to line 0
HALT
# Example: Using WAIT
PRINT "Waiting for 3 seconds..."
WAIT 3000
PRINT "Done!"
HALT
Contributions are welcome! Please open an issue or submit a pull request. If you want to email us, contact at: sapinyo@proton.me
This GitHub Wiki and document is a work in process and we'd love to have more contributions. If anyone could contribute, fork the wiki and open a pull request if you really care about our project.
Thank you!