Smalllang

From Esolang
Jump to navigation Jump to search

Smalllang is a joke esoteric programming language invented by User:A created in order to fullfill User:Hanzlu's definition of a usable language, as it tries its best to make itself as unusable as possible.

"In my opinion a programming language needs four essential parts in order to be a usable language. I list them in the following order of importance: 1. Changing values 2. Output 3. Control flow 4. Moving in memory"

Instructions

Smalllang has a tape that only has 2 binary cells. In order to increment a cell in memory, use the . instruction (1. changing values). If you increment a value, you can not decrement it back; it is always 1 and you can never change it anymore. In order to move right, use the > instruction (4. moving in memory). If you move right, you can not move back left, and if you reach the right end of the tape, you are not allowed to move right anymore.

Smalllang also has an output instruction, which is * (2. output). This outputs the bit to the console and then deletes that bit in the memory. Smalllang also has control flow, the ? instruction(3. control flow). It is a while loop (containing an if statement), and if the current cell is nonzero, it jumps back to the start of the program. Similar to the * instruction, it deletes the current cell before it switches the code execution.

Interpreter

Here is an interpreter for Smalllang by User:Hanzlu (modified by User:A to avoid the possibility of an Infinite loop by typing .?, and also prevents errors by checking them):

code = ""
l = len(code)
i = 0

memory = [0, 0]
ptr = 0

while i < l:
    c = code[i]
    
    if c == ".":
        try:
            memory[ptr] = 1
        except:
            break
        
    elif c == ">":
        ptr = 1
    
    elif c == "*":
        try:
            print(memory[ptr])
            memory.remove(memory[ptr])
        except:
            break
        
    elif c == "?":
        try:
            if memory[ptr]:
                i = -1
            memory.remove(memory[ptr])
        except:
            break

    i += 1