PRINTASKSWITCHINPUTCASEXGOTOACASEYGOTOBELSEGOTOC

The PRINTASKSWITCHINPUTCASEXGOTOACASEYGOTOBELSEGOTOC programming language is an esoteric programming language by User:Rdococ, aimed at augmenting the Goto programming language with better I/O.
== Structure ==
As the name of the language suggests, every instruction prints something, asks for input, and then checks the input in a SWITCH clause. Syntax goes a little like this:
PRINT "STUFF TO PRINT HERE." ASK SWITCH INPUT CASE "DERP" GOTO 2 CASE "HERP" GOTO 3 ELSE GOTO 1
And that's it. Programs are lines after lines of this same instruction with different parameters. Strings can only have capital letters to add to the feel of the language. Additionally, if the program tries to go to an invalid line number, it halts.
== Computational Class ==
Like in Goto, lines of code in PRINTASKSWITCHINPUTCASEXGOTOACASEYGOTOBELSEGOTOC are like the states of a finite state machine.
== Examples ==
=== Hello World ===
PRINT "HELLO WORLD!" ASK SWITCH INPUT ELSE GOTO 0
=== Very bad RPG ===
PRINT "YOU'RE IN A DARK ROOM MADE OF STONE. THERE'S A DOOR TO THE NORTH AND ONE TO THE SOUTH." ASK SWITCH INPUT CASE "GO NORTH" GOTO 2 CASE "GO SOUTH" GOTO 3 ELSE GOTO 1
PRINT "EVERYTHING FADES TO WHITE. I WONDER WHAT HAPPENED." ASK SWITCH INPUT ELSE GOTO 0
PRINT "YOU'RE IN A DARK ROOM MADE OF DIRT. THERE'S A DOOR TO THE SOUTH BUT NOT TO THE NORTH... HANG ON A MINUTE..." ASK SWITCH INPUT CASE "GO SOUTH" GOTO 4 CASE "GO NORTH" GOTO 2 ELSE GOTO 3
PRINT "YOU'RE IN A BRIGHT ROOM MADE OF GOLD! THERE'S A DOOR TO THE SOUTH AND A DOOR TO THE NORTH." ASK SWITCH INPUT CASE "GO SOUTH" GOTO 0 CASE "GO NORTH" GOTO 3 ELSE GOTO 4
PRINT "YOU'RE OUTSIDE! YOU WIN YAY! WHO CARES ANYWAY? YOU WERE IN A ROOM OF GOLD AND LOOK, THE DOOR'S GONE. YOU CANT GET TO THE GOLD. GREAT, NOW WHAT DO WE DO? I GUESS WE CANT DO ANYTHING... LET'S JUST GET HOME." ASK SWITCH INPUT ELSE GOTO 0
== Implementations ==
=== Python 3 ===
The spec is not at all clear on how to handle the shorter version of the instruction with no case statement, but here's a best guess as to an implementation:
 import sys,re
 if len(sys.argv)<2:
 print("No filename to execute.")
 else:
 try: 
 with open(sys.argv[1], "r") as f:
 prog = f.read()
 except IOError: print("File '"+filename+"' not found."); sys.exit(1)
 if prog!=prog.upper():
 print("PROGRAM MUST CONTAIN ONLY CAPITAL LETTERS.")
 sys.exit(1)
 prog = prog.splitlines()
 pat = re.compile('PRINT "(.*)" ASK SWITCH INPUT CASE "(.*)" GOTO (.*) CASE "(.*)" GOTO (.*) ELSE GOTO (.*)')
 pat2 = re.compile('PRINT "(.*)" ASK SWITCH INPUT ELSE GOTO (.*)')
 ptr = 0
 while 0<=ptr<len(prog):
 parsedins = pat.fullmatch(prog[ptr])
 if parsedins is None:
 parsedins = pat2.fullmatch(prog[ptr])
 if parsedins is None:
 print(f"ILLEGAL INSTRUCTION ON LINE {ptr}.")
 sys.exit(1)
 else:
 try:
 c = int(parsedins.group(2))
 except ValueError:
 print(f"ILLEGAL GOTO LINE NUMBER ON LINE {ptr}.")
 sys.exit(1)
 input(parsedins.group(1)+"\n") #not clear if we're supposed to actually get input for this instruction type
 ptr = c
 else:
 try:
 a,b,c = map(int,parsedins.group(3,5,6))
 except ValueError:
 print(f"ILLEGAL GOTO LINE NUMBER ON LINE {ptr}.")
 sys.exit(1)
 instr = input(parsedins.group(1)+"\n")
 if instr==parsedins.group(2):
 ptr = a
 elif instr==parsedins.group(4):
 ptr = b
 else:
 ptr = c
Category:Languages Category:Implemented Category:Finite state automata