We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.

ShiftAlpha

From Esolang
Jump to navigation Jump to search

ShiftAlpha (shift for short) is a programming language developed by User:Broxol in which programming the language is a block-sliding puzzle.

This is not a turing-complete language. I intend to make a turing complete version, which I call ShiftAleph.

INTRODUCTION

Shift works on a 2x2 grid, with each function as a block. There are 3 commands you can shift - print, input, and stack.

On the grid, the rows are labeled A and B and the columns 1 and 2. B2 always starts empty. To shift a block, you input its coordinates and the direction you want to push it. For example, b1> will push whatever’s on b1 to the right.

(note: stack only stacks hello world. In shiftaleph, this will be changed to numbers 1-15 in hexadecimal.)


Example: Hello World Program

b1>#a1va2<b2^b1>#

INTERPRETER


code = "b1>#a1va2<b2^b1>#"
code = list(code)
grid = [["print", "input"], ["stack", None]]
stack = []

i = 0
while i < len(code):
    if code[i] == "#":
        if grid[1][1] == "print":
            print(stack.pop())
        elif grid[1][1] == "input":
            stack.append(str(input()))
        elif grid[1][1] == "stack":
            stack.append("Hello, World!")
        else:
            assert 1 == 2, "NullError: Tried to run 'None' object"
        i += 1
    else:
        test = code[i] + code[i + 1]
        i += 2
        if code[i] == ">":
            if test == "a1":
                assert grid[0][1] == None, f"SwapError: Swaped {test} with {grid[0][1]} instead of None Object"
                grid[0][0], grid[0][1] = grid[0][1], grid[0][0]
            elif test == "b1":
                assert grid[1][1] == None, f"SwapError: Swaped {test} with {grid[1][1]} instead of None Object"
                grid[1][0], grid[1][1] = grid[1][1], grid[1][0]
        elif code[i] == "<":
            if test == "a2":
                assert grid[0][0] == None, f"SwapError: Swaped {test} with {grid[0][0]} instead of None Object"
                grid[0][1], grid[0][0] = grid[0][0], grid[0][1]
            elif test == "b2":
                assert grid[1][0] == None, f"SwapError: Swaped {test} with {grid[1][0]} instead of None Object"
                grid[1][1], grid[1][0] = grid[1][0], grid[1][1]
        elif code[i] == "^":
            if test == "b1":
                assert grid[0][0] == None, f"SwapError: Swaped {test} with {grid[0][0]} instead of None Object"
                grid[1][0], grid[0][0] = grid[0][0], grid[1][0]
            elif test == "b2":
                assert grid[0][1] == None, f"SwapError: Swaped {test} with {grid[0][1]} instead of None Object"
                grid[1][1], grid[0][1] = grid[0][1], grid[1][1]
        elif code[i] == "v":
            if test == "a1":
                assert grid[1][0] == None, f"SwapError: Swaped {test} with {grid[1][0]} instead of None Object"
                grid[1][0], grid[0][0] = grid[0][0], grid[1][0]
            elif test == "a2":
                assert grid[1][1] == None, f"SwapError: Swaped {test} with {grid[1][1]} instead of None Object"
                grid[1][1], grid[0][1] = grid[0][1], grid[1][1]
            pass
        else:
            assert 1 == 2, f"SyntaxError: '><^v' expected, {code[i]} found"
        i += 1
        
print(grid)