Iflang

From Esolang
Jump to navigation Jump to search

Iflang is a language created in 2020 by User:Hanzlu. The memory consists of two cells, both containing 1 bit each. The language is supposed to be useless.

Command Explanation
( Loop
) If cell is 1, start loop over again
1 If cell is 1, move pointer to the other cell. If within a loop, flip the bit in the cell.
0 If cell is 0, output the bit in the cell. If within a loop, flip the bit in the cell.

Iflang code for printing out a '0'

(11001)

Interpreter:

file = open("ifcode", "r")
code = file.read()

loop = False
loops = 0

cell = [0, 0]
ptr = 0

i = 0
while i < len(code):

    if code[i] == "(":
        loop = True
        loops += 1

    elif code[i] == ")":
        if cell[ptr] == 1:
            x = 1
            while x != 0:
                i -= 1
                if code[i] == "(":
                    x -= 1
                elif code[i] == ")":
                    x += 1
        else:
            loop -= 1
            if loop == 0:
                loop = False

    elif code[i] == "1":
        if cell[ptr] == 1:
            ptr = 1 if ptr == 0 else 0
        if loop == True:
            cell[ptr] = 1 if cell[ptr] == 0 else 0

    elif code[i] == "0":
        if cell[ptr] == 0:
            print(cell[ptr])
        if loop == True:
            cell[ptr] = 1 if cell[ptr] == 0 else 0

    i += 1  

file.close()