Xand

From Esolang
Jump to navigation Jump to search

Xand is a programming language that is a OISC, x, y, z -> x = ((x xor y) and z)

Not

(a)
a, 1, 1 #a will be negated, 0 to 1, 1 to 0, numbers turn into binary, 4 -> 100, 8 -> 1000

And

(a, b)
a, 0, b #a and b will be combined, 1, 1 -> 1, else 0

Nand

(a, b)
a, 1, 1
a, 0, b #a will turn into (!(a&b))

Or

(a, b)
a, 1, 1
b, 1, 1
a, 0, b
a, 1, 1

Nor

(a, b)
a, 1, 1
b, 1, 1
a, 0, b

Shift

(a, b)
c, 1, 1
c, 0, a
a, 0, 0
a, 1, 1
a, 0, b
b, 0, 0
b, 1, 1
b, 0, c

Shift 3

(a, b, c)
d, 1, 1
d, 0, a
a, 0, 0
a, 1, b
b, 0, 0
b, 1, c
c, 0, 0
c, 1, d

Cut Shift

(a, b)
a, 0, 0
a, 1, b
b, 0, 0

Set

(a, b)
a, 0, 0
a, 1, b

Implementation

#python
import sys
try:
    inpu = open(sys.argv[1]).read()
    varibs = {"0": False, "1": True}
    if sys.argv[1][-5:len(sys.argv[1])] != ".xand":
        raise ZeroDivisionError("error for file type")
    for inputs in inpu.split("\n")[0][1:-1].split(", "):
        varibs[inputs] = bool(int(input("input for "+inputs)))
    def doline(line):
        inp = line.split(", ")
        varibs[inp[0]] = (varibs[inp[0]] ^ varibs[inp[1]]) & varibs[inp[2]]
    for lines in inpu.split("\n")[1:]:
        doline(lines)
    del varibs["0"]
    del varibs["1"]
    for varib in varibs:
        print(varib+": "+str(int(varibs[varib])))
except IndexError:
    print("You have not included the input file")
except ZeroDivisionError:
    print("You have used the wrong file type, .xand is the file type")
except FileNotFoundError:
    print(f"The file '{sys.argv[1]}' does not exist")