StupidStackLanguage

From Esolang
Jump to navigation Jump to search
SSL Logo

StupidStackLanguage (or SSL) is an esoteric programming language created by Lebster in which all operations take place on a Stack

SSL Uses the characters A-Z to perform actions. SSL is also case-insensitive.

Operations

Note: Items on the stack can only be numbers.

Character Operation
a Pushes 0 to the top of the stack
b Pops the 1st item from the stack
c Subtracts the 2nd item on the stack from the 1st item and pushes the result to the stack
d Decrements the 1st item of the stack by 1
e Pushes the 1st item mod the 2nd item onto the stack
f Prints the 1st item on the stack as an ASCII character
g Adds the first 2 stack items together and pushes the result to the stack
h Gets input from the user as a number and pushes to the stack
i Increments the 1st item of the stack by 1
j Gets input from the user as a character and pushes that character's ASCII code onto the stack
k Skips the next command if the 1st item on the stack is 0
l Swaps the 1st and 2nd items on the stack
m Multiplies the first two stack items together and pushes the result onto the stack
n If the 1st item on the stack is equal to the 2nd item, push a 1 to the stack, else push a 0
o Pops the (first item on the stack)th item on the stack
p Divides the 1st item on the stack by the 2nd item and pushes the result onto the stack
q Duplicates the 1st item on the stack
r Pushes the total length of the stack onto the stack
s Swaps the 1st and (first item on the stack)th items on the stack
t If the 1st item on the stack is 0, jumps to the corresponding 'u' in the program, otherwise does nothing
u If the 1st item on the stack is not 0, jumps back to the corresponding 't' in the program, otherwise does nothing
v Increments the top item on the stack by 5
w Decrements the top item on the stack by 5
x Prints the 1st item on the stack
y Deletes the entire stack
z Exits the script

Examples

Hello World

avqmimcfdddfviiffvddfavdegmfavdmcwfwdddfvddfwdfwdddf

The online interpreter also features macros, so you can compile a "hello world" program using the print macro:

.print("hello world")

Cat

jf

A+B Problem

hhgx

Truth-machine

htxux

Find the Factorial of a Number

hqdtmldubx
h # Set X
q # Duplicate x (z)
d # Decrement z (y)
t # Begin loop
	m # Multiply y by x
	l # Swap result and y
	d # Decrement y
u # End loop
b # Pop remaining 0
x # Print (x!)

Calculator

hhhtdtdtblpxzubmxzublcxzubgxz

Usage

Takes 3 inputs, X, Y and Z

Z Program output
0 X + Y
1 X - Y
2 X * Y
3 X / Y

Print the Fibonacci Sequence

# Note: Works best on tio.run as when run via command line it runs so fast that you can't really see any of the numbers.
axiqvvdflxlwwltgavvfbxu

Print a box of any character

jfffavvflflqvvvviifblflflfff

Ackermann function

hhaitbltlanlbailtbbbdaiaaubtbdlqdlavdqslobaublubirdubx
hh # read m and n
ait # loop while len(stack) > 1
    b # drop stack length
    l # n m
    t # loop while m != 0
        l # m n
        anlb # push case2=(n == 0)
        ail # push case3=1 to below top of stack
        tb # if case2
            b # drop case3
            b # drop n
            d # m -= 1
            ai # push n=1
            a # push case3=0
        aub # endif
        tb # if case3
            d # n -= 1
            l # n-1 m
            qdl # n-1 m-1 m
            avdqslob # lift 3rd (stack: m-1 m n-1)
        aub # endif
        l # n m
    u
    b # drop m (== 0)
    i # n += 1
    rd # push len(stack)-1
u
b # drop stack length
x # print result

Implementations

Website

You can use the website to run SSL code online. Note that this executes programs slower than the Python interpreter.

Python

There is also a python interpreter, which can be accessed on tio.run

import sys, re

if len(sys.argv) < 2:
    print(f"Usage: python {sys.argv[0]} [filename]")
    sys.exit(1)

file = open(sys.argv[1], "r")
prg = file.read()
file.close()

stack = []
prg = re.compile("#(?=.*).*").sub("", prg)
prg = re.compile("[^abcdefghijklmnopqrstuvwxyz]*", re.IGNORECASE).sub("", prg)
prgPos = 0
shouldSkip = False

while prgPos < len(prg):
    if shouldSkip:
        shouldSkip = False
        prgPos += 1
        continue

    char = prg[prgPos].lower()
    if char == "a":
        stack.insert(0, 0)
    elif char == "b":
        stack.pop(0)
    elif char == "c":
        stack.insert(0, stack[0] - stack[1])
    elif char == "d":
        stack[0] -= 1
    elif char == "e":
        stack.insert(0, stack[0] % stack[1])
    elif char == "f":
        print(chr(stack[0]), end="")
    elif char == "g":
        stack.insert(0, stack[0] + stack[1])
    elif char == "h":
        stack.insert(0, int(input("\nNumber: ")))
    elif char == "i":
        stack[0] += 1
    elif char == "j":
        stack.insert(0, ord(input("\nInput: ")[0]))
    elif char == "k" and stack[0] == 0:
        shouldSkip = True
    elif char == "l":
        temp = stack[1]
        stack[1] = stack[0]
        stack[0] = temp
    elif char == "m":
        stack.insert(0, (stack[0] * stack[1]))
    elif char == "n":
        stack.insert(0, int(stack[0] == stack[1]))
    elif char == "o":
        stack.pop(stack[0])
    elif char == "p":
        stack.insert(0, stack[0] / stack[1])
    elif char == "q":
        stack.insert(0, stack[0])
    elif char == "r":
        stack.insert(0, len(stack))
    elif char == "s":
        temp = stack[stack[0]]
        stack[stack[0]] = stack[0]
        stack[0] = temp
    elif char == "t":
        if stack[0] == 0:
            opened = 0
            prgPos += 1
            while prgPos < len(prg):
                if prg[prgPos] == "u" and opened == 0:
                    break
                elif prg[prgPos] == "t":
                    opened += 1
                elif prg[prgPos] == "u":
                    opened -= 1
                prgPos += 1
    elif char == "u":
        if stack[0] != 0:
            closed = 0
            prgPos -= 1
            while prgPos >= 0:
                if prg[prgPos] == "t" and closed == 0:
                    break
                elif prg[prgPos] == "u":
                    closed += 1
                elif prg[prgPos] == "t":
                    closed -= 1
                prgPos -= 1
    elif char == "v":
        stack[0] += 5
    elif char == "w":
        stack[0] -= 5
    elif char == "x":
        print(stack[0], end="")
    elif char == "y":
        stack = []
    elif char == "z":
        sys.exit(0)
    else:
        print("Invalid character:", char, "at", prgPos)
        sys.exit(0)
    prgPos += 1

Usage

$ python SSL.py [filename]

Where [filename] is the name/path of a file containing the SSL program to execute

Comments

Comments can be written as such:

# Comment