Skip to content

Instantly share code, notes, and snippets.

@Purah126
Last active March 30, 2023 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Purah126/ddc5eec748c12d72ce81c22e6921f36e to your computer and use it in GitHub Desktop.
Save Purah126/ddc5eec748c12d72ce81c22e6921f36e to your computer and use it in GitHub Desktop.
'''Implementation of Qwerty esoteric programming language by Purah126
This code is in the public domain'''
import re
def qwerty(code):
i = 0
t = [0]
c = 0
h = {}
s = []
sm = False
cm = re.findall('\(.*?\)', code)
for x in cm:
code = code.replace(x, '')
rp = re.findall('/.*?/.*?/', code)
for x in rp:
y = x.split('/')
code = code.replace(x, '')
code = code.replace(y[1], y[2])
if code.count('[') != code.count(']'):
return 4
def pop():
if len(s) == 0:
return 0
else:
return s.pop()
while i < len(code):
a = code[i]
if sm == True:
if a == '\\':
i += 1
s.append(ord(a))
elif a == '"':
sm = False
else:
s.append(ord(a))
elif a == '`':
s.reverse()
elif a == '~':
if len(s) > 0:
s.append(s.pop(0))
elif a == '!':
try:
print(chr(t[c]), end='')
except ValueError:
return 1
elif a == '@':
try:
code[pop()] = chr()
except IndexError:
return 2
except ValueError:
return 1
elif a == '#':
if len(s) > 0:
s.append(s[-1])
elif a == '$':
try:
s.append(h[t[c]])
except KeyError:
return 3
elif a == '%':
t[c] = t[c] % pop()
elif a == '^':
t[c] = -t[c]
elif a == '&':
h[t[c]] = pop()
elif a == '*':
t[c] = t[c] * pop()
elif a == '-':
t[c] = t[c] - pop()
elif a == '_':
t[c] = (t[c] - 1)
elif a == '=':
if t[c] == pop():
while code[i] != ']':
i += 1
elif a == '+':
t[c] = t[c] + pop()
elif a == '{':
if len(s) > 1:
s.append(s.pop(-2))
elif a == ']':
d = 1
while d > 0:
i -= 1
if code[i] == '[':
d -= 1
if code[i] == ']':
d += 1
elif a == '}':
t[c] = len(s)
elif a == '\\':
t[c] = int(t[c] // pop())
elif a == '|':
print(t[c], end=' ')
elif a == ';':
s.append(t[c])
t[c] = 0
elif a == ':':
t[c] = pop()
elif a == '\'':
t[c] = (t[c] + 1)
elif a == '"':
sm = True
elif a == ',':
c += 1
if c == len(t):
t += [0]
elif a == '<':
if t[c] < pop():
while code[i] != ']':
i += 1
elif a == '.':
if c == 0:
t = [0] + t
else:
c -= 1
elif a == '>':
if t[c] > pop():
while code[i] != ']':
i += 1
elif a == '?':
s += [ord(x) for x in input()]
i += 1
return 0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment