User:Gamer

From Esolang
Jump to navigation Jump to search

yo whats up guys its gamer here ok actually my name is iBrow but i cant change my username on this website so fuck

i'm a 16 year old esolang noob ok bye

Esolangs

I've created 1 esolang with User:Andrew3335: TPLHBPTBOTEW

Implementations

Madbrain (Python 3)

Syntax (Windows): C:\path\to\folder>python madbrain.py program.mb

#!/usr/bin/env python

import sys


def main():

    f = open(sys.argv[1], 'r')
    prg = f.read().splitlines()
    f.close()

    prgPos = 0
    ptr = 0
    stk = []

    cmds = {
            '*': 'mul', '/': 'div', '+': 'add', '-': 'sub',
            '>': 'ga', '<': 'la', '^': 'gs', 'v': 'ls',
            '?': 'gza', '!': 'gzs', ':': 'eza', ';': 'ezs', '.': 'lza', ',': 'lzs',
            '=': 'ea', '_': 'es', '#': 'nea', '@': 'nes'
           }

    def j():
        nonlocal prgPos
        prgPos = stk.pop() - 1

    def g():
        nonlocal ptr
        j()
        ptr += stk.pop(0)

    def q():
        nonlocal ptr
        j()
        ptr -= stk.pop(0)

    def i():
        nonlocal ptr
        ptr += stk.pop()

    def d():
        nonlocal ptr
        ptr -= stk.pop()

    def x():
        sys.exit(0)

    def mul():
        stk.append(stk.pop() * stk.pop(0))

    def div():
        stk.append(stk.pop() / stk.pop(0))

    def add():
        stk.append(stk.pop() + stk.pop(0))

    def sub():
        stk.append(stk.pop() - stk.pop(0))

    def r():
        inp = input('\nAwaiting input: ')[0]
        while not inp.isdigit():
            inp = input('Input must be a digit.\nAwaiting input: ')
        stk.append(int(inp))

    def p():
        print(stk.pop(), end='')

    def c():
        i = stk.pop()
        if 0 <= i <= 255:
            print(chr(i), end='')

    def ga():
        nonlocal ptr
        ptr += stk.pop() > stk.pop(0)

    def la():
        nonlocal ptr
        ptr += stk.pop() < stk.pop(0)

    def gs():
        nonlocal ptr
        ptr -= stk.pop() > stk.pop(0)

    def ls():
        nonlocal ptr
        ptr -= stk.pop() < stk.pop(0)

    def gza():
        nonlocal ptr
        ptr += stk.pop() > 0

    def gzs():
        nonlocal ptr
        ptr -= stk.pop() > 0

    def eza():
        nonlocal ptr
        ptr += stk.pop() == 0

    def ezs():
        nonlocal ptr
        ptr -= stk.pop() == 0

    def lza():
        nonlocal ptr
        ptr += stk.pop() < 0

    def lzs():
        nonlocal ptr
        ptr -= stk.pop() < 0

    def ea():
        nonlocal ptr
        ptr += stk.pop() == stk.pop(0)

    def es():
        nonlocal ptr
        ptr -= stk.pop() == stk.pop(0)

    def nea():
        nonlocal ptr
        ptr += stk.pop() != stk.pop(0)

    def nes():
        nonlocal ptr
        ptr -= stk.pop() != stk.pop(0)

    while prgPos < len(prg):
        cmd = prg[prgPos][ptr]

        if (cmd in 'jidpc?!:;.,' and len(stk) < 1) or (cmd in 'gq*/+-><^v=_#@' and len(stk) < 2):
            raise IndexError('at ' + cmd + ': insufficient items in stack')

        if cmd.isdigit():
            stk.append(int(cmd))
            prgPos += 1
            continue

        try:
            exec(cmds.get(cmd, cmd) + '()')
        except NameError:
            pass
        prgPos += 1


if __name__ == '__main__':
    main()