Skip to content

Instantly share code, notes, and snippets.

@hornc hornc/APLBAONWSJAS.py
Last active Dec 4, 2018

Embed
What would you like to do?
A ridiculous interpreter for the joke esoteric programming language APLBAONWSJAS https://esolangs.org/wiki/APLBAONWSJAS
#!/usr/bin/env python3
import re
import subprocess
"""
This is a ridiculous interpreter for the joke esoteric programming language APLBAONWSJAS
see https://esolangs.org/wiki/APLBAONWSJAS for details.
!!!WARNING!!! this takes user input and runs it without checking as system commands,
this could have unintended consequences, and what you type could make changes to your
filesystem etc, use at your own risk, don't run as root, or with scissors.
Any argument you pass to the EXECUTE() command will be run as a subprocess as if
you typed it into a shell.
!!!WARNING!!! this is for entertainment purposes only, and should not be used for anything,
ever.
"""
PROMPT = 'Ǝ '
CMD = re.compile('EXECUTE\(\s*(.*)\s*\)')
THRESH = [7, 14, 27]
def init():
assistant = Rosie()
v = assistant.__version__**(1/7)
print("A Programming Language By Any Other Name Would Smell Just As Sweet (APLBAONWSJAS) Interpreter v{:.3f}".format(v))
print("[Rosie intelligent assistant v{}]".format(assistant.__version__))
return assistant
def main(e, rosie):
c = input(PROMPT)
if CMD.match(c):
orig = CMD.match(c).group(1).strip()
cmd = orig
if cmd == 'APLBAONWSJAS':
cmd = __file__
tries = 0
while tries < 30:
if not cmd: break # successfully execute null program
try:
tries += 1
subprocess.run(cmd)
break
except FileNotFoundError:
if cmd == cmd.lower():
cmd = rosie.find(orig)
else:
cmd = cmd.lower()
else:
print("! %s NOT FOUND" % orig)
elif c:
print('! UNKNOWN COMMAND')
e += 1
for t in THRESH:
if e == t:
print(rosie.advise(THRESH.index(t)))
return e
class Rosie:
__version__ = 1.1
interpreters = {}
msg_hello = "\nHi! I'm Rosie, the APLBAONWSJAS intelligent assistant.\n\n"
msgs_hello = [msg_hello, "\nHi Again! Rosie here; ", msg_hello]
msg_looks = "It looks like you are "
msgs_error = [
"""typing randomly into an extremely limited command-line interface which only accepts one command:
EXECUTE()
You should try using that.""",
"""having trouble using the one available EXECUTE() command.
You should type
EXECUTE(n)
where 'n' is the name of the programming language interpreter that you want to EXECUTE.
Then hit <enter> on your keyboard. APLBAONWSJAS will then run the EXECUTE command and display an interpreter for that programming language.""",
"""having trouble comprehending or following simple instructions.
Unfortunately I am unable to help you with that."""
]
msg_sig = "\n\n%s\U0001f495\n%sxxx Rosıe" % (' '*37, ' '*30)
msgs_sig = [msg_sig, msg_sig, "\n\n" + ' '*34 + "Rosie \U0001F940"]
def advise(self, n):
advice = [self.msgs_hello[n], self.msg_looks, self.msgs_error[n], self.msgs_sig[n]]
return ''.join(advice)
def find(self, interpreter):
if interpreter in self.interpreters:
#TODO: what if the path is bad and Rosie keeps returning it?
#TODO: Rosie should write known interpreters to .config
return self.interpreters[interpreter]
msg_execute = "trying to EXECUTE '{0}'\nUnfortunately I can't find {0} on your computer at this time."
find_help = [self.msg_hello, self.msg_looks, msg_execute]
print(''.join(find_help).format(interpreter))
msg_help ="\n\nPlease help me to help you by typing the full path to the {} executable: ".format(interpreter)
path = input(msg_help)
msg_thanks = "\nThank you! I'll remember that for next time.\n Have a lovely day!"
print(''.join([msg_thanks, self.msg_sig]))
self.interpreters[interpreter] = path
return path
if __name__ == '__main__':
rosie, e = init(), 0
while 1:
e = main(e, rosie)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.