Xand
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}
labs = {}
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, i):
inp = line.split(", ")
if inp[0] != "loop":
varibs[inp[0]] = (varibs[inp[0]] ^ varibs[inp[1]]) & varibs[inp[2]]
elif inp[2] == "0":
labs[inp[1]] = i
elif not varibs[inp[1]]:
i = labs[inp[2]]-1
i = 0
while i < len(inpu):
doline(inpu[i].split("\n")[1:], i)
i += 1
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")