Whereismystack

From Esolang
Jump to navigation Jump to search

Overview

Whereismystack is a stack-based esoteric programming language that challenges the programmer to manipulate a string-array memory. Unlike traditional stack languages, its output is determined by a unique "Last-Two-Digits" consolidation rule, where only the final part of a concatenated memory string is preserved.

Architecture

  • Memory (Stack): A dynamic array of strings, initialized as ["1", "1"]
  • Output Buffer: A separate integer array that stores values processed by the = operator.
  • Execution: The interpreter processes each line independently, resetting the memory to its initial state for every new line.

Commands

Command Name Description
+ Add Add the last two elements from memory and pushes the result back to memory.
- Sub Subtracts the last element (Top) from the second-to-last element. If the result is negative, the absolute value is pushed to memory.
* Mul Multiplies the last two elements in memory and pushes the result.
/ Div Divides the second-to-last element by the last element. Note: Division by zero terminates the program immediately.
= Consolidate
  1. Concatenates all strings currently in memory into a single string.
  2. Takes the last two characters of this concatenated string (if length ≥ 2), converts them to an integer, and applies modulo 128.
  3. Core Logic: Pushes the resulting integer to the Output Buffer.
  4. Memory is reset to its initial state: ["1", "1"].
?MN Range Combine & Push Accesses a predefined sequence from index M to N-1. These values are summed into the current memory state. The final combined value modulo 128 is pushed to memory. (Constraint: N - M ≥ 2).
r Reverse Swaps the positions of the last element and the second-to-last element in memory.
^ Print / Flush This operator is context-sensitive based on the preceding character:
  1. If the previous character is = Iterates through the Output Buffer, converting each integer to its corresponding ASCII character and printing the resulting string.
  2. Otherwise: Performs a raw dump of all current memory elements (as literals, not ASCII).

Computational Model

The language utilizes two distinct storage structures:

  • Memory: A stack or list used for active calculations and string manipulations.
  • Output Buffer: A secondary storage area specifically for ascii code.

Implementation Notes

  • The initial state of memory is ["1", "1"].
  • All ASCII conversions should strictly follow the 7-bit standard (0-127) via modulo 128.

Implementation Details

  • Initial State: Every line starts with memory = {"1", "1"}.
  • Numeric Conversion: Strings are converted to integers for calculation and back to strings for storage.
  • The last Two values This is the core mechanic.

example

1) H

input : ++--?15r=^

output : H

2) Fibonacci sequence

input : +++++++++++^

output : 1123581321345589144

link

here is my interpreter :

https://github.com/realgitman1/whereismystack_interpreter.git