Skip to main content

No project description provided

Project description

S3 - Simple Stack Script

License: MIT Python 3.9+ Built with Python PyPI version CodeQL GitHub last commit

S3 (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.

Important: We are now an officially published Python package!!!

🚀 Features

  • 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.

📥 Installation

If you are reading this on PyPI, please use the first installation choice below:

pip install simplestackscript

This is the easiest way to install S3. pip will automatically download and install the latest version from PyPI. If you would rather install from source, follow the instructions below:

  1. Clone the repository:

    git clone [https://github.com/CaptioDev/simplestackscript.git](https://github.com/CaptioDev/simplestackscript.git)
    cd simplestackscript
    
  2. Install the interpreter:

    pip install .  # Installs the s3 command
    
  3. Run an S3 program:

    s3 my_program.s3
    

📖 Language Reference

S3 uses a stack-based architecture, where most operations manipulate a stack of values. Instructions are processed sequentially.

Stack Manipulation

  • 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. The top element becomes the bottom, the second becomes the top, and the third becomes the second.
  • 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.

Arithmetic Operations

  • 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 pushes b - a onto the stack. (Order matters!)
  • MUL: Pops the top two elements, multiplies them, and pushes the result.
  • DIV: Pops the top two elements (a, b) and performs integer division b // a, pushing the result. (Order matters!)

Input/Output

  • 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.

Control Flow

  • JUMP.IF.0 <label>: Pops the top element. If it is 0, execution jumps to the line marked by <label>. Otherwise, execution continues to the next instruction.
  • JUMP.IF.POS <label>: Pops the top element. If it is greater than 0, execution jumps to the line marked by <label>. Otherwise, execution continues.
  • LOOP <line_number>: Jumps back to the specified line_number. Be careful to avoid infinite loops.

Program Termination

  • HALT: Terminates the program execution.

Labels

  • <label>:: A label marks a specific location in the program code. It's used as a target for jump instructions. The label itself isn't an opcode; it's a marker.

📝 Examples

# Example: Adding two numbers
PUSH 5
PUSH 10
ADD
PRINT.TOP  # Output: 15
HALT

# Example: Loop and print numbers from 0 to 9
PUSH 0
LOOP_START:
  DUP
  PRINT.TOP
  PUSH 1
  ADD
  DUP
  PUSH 10
  SUB
  JUMP.IF.0 LOOP_END
  JUMP.IF.POS LOOP_START
LOOP_END:
HALT

# Example: Input and output
PRINT "Enter a number:"
READ
PRINT "You entered:"
PRINT.TOP
HALT

💡 Contributing

Contributions are welcome! Please open an issue or submit a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simplestackscript-0.2.9.tar.gz (5.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simplestackscript-0.2.9-py3-none-any.whl (8.6 kB view details)

Uploaded Python 3

File details

Details for the file simplestackscript-0.2.9.tar.gz.

File metadata

  • Download URL: simplestackscript-0.2.9.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for simplestackscript-0.2.9.tar.gz
Algorithm Hash digest
SHA256 210ffea40c9950025af8cf8308a7b7ac0d21fcf614a4d8fc48a9be79e57710e6
MD5 d0f2b4988fad36e43b36ebcf29948372
BLAKE2b-256 3eebd327f787403e365f1e3d275f473d2c12092facaf00df86a4e17cdf2b949a

See more details on using hashes here.

File details

Details for the file simplestackscript-0.2.9-py3-none-any.whl.

File metadata

File hashes

Hashes for simplestackscript-0.2.9-py3-none-any.whl
Algorithm Hash digest
SHA256 53750c7f02d5dab5b6c814aba7d413fea98af133227b300ee61720b1a769822c
MD5 8dd1ef60fe584e301c4d08206ee48086
BLAKE2b-256 d9a9695c707d4d44111bd87f3d198f9b96c866437471d7012c96da2b5a4a0a9f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page