import time Commands = {} Variables = {} def INPUT(String): String = String.split(';',1)…
- User
import time Commands = {} Variables = {}
def INPUT(String): String = String.split(';',1) if String[1] in Variables: Variables[String[0]] = input(Variables[String[1]])
def PRINT(String): if String in Variables: print(Variables[String])
def SHIFT(String): String = String.split(';',1) if String[0] in Variables: try: if not String[1] in Variables: Index = 0 else: Index = int(Variables[String[1]],13) Variables[String[0]] = list(Variables[String[0]]) Value = ord(Variables[String[0]][Index]) Value = (Value+1)%128 Variables[String[0]][Index] = chr(Value) Variables[String[0]] = ''.join(Variables[String[0]]) except ValueError: pass
def DELCHAR(String): if not String in Variables: Variables[String] = '' Variables[String] = Variables[String][:-1]
def ADDCHAR(String): if not String in Variables: Variables[String] = '' Variables[String] = list(Variables[String]) Variables[String].append(chr(0)) Variables[String] = ''.join(Variables[String])
def GETCHAR(String): String = String.split(';',2) if String[0] in Variables and String[1] in Variables: try: Index = int(Variables[String[1]],13) Variables[String[2]] = Variables[String[0]][Index] except ValueError: pass
def EQUAL(String): global LineNumber String = String.split(';',1) if String[0] in Variables and String[1] in Variables: if Variables[String[0]] != Variables[String[1]]: LineNumber += 1
def GOTO(String): global LineNumber global LastJump LastJump = LineNumber LineNumber = int(Variables[String],13)
def RETURN(String): global LineNumber global LastJump LineNumber = LastJump LastJump = 0
Commands[">"] = INPUT Commands["<"] = PRINT Commands["^"] = SHIFT Commands["*"] = DELCHAR Commands["+"] = ADDCHAR Commands["?"] = GETCHAR Commands["="] = EQUAL Commands["@"] = GOTO Commands["#"] = RETURN
File = [Foo.replace('\n','') for Foo in open(input("File: ")).readlines()] global LineNumber global LastJump LineNumber = 0 LastJump = 0 while LineNumber < len(File): Line = File[LineNumber] for Command in Commands: if Command == Line[0]: Function = Commands[Command] break else: Function = 'Comment' if Function != 'Comment': Function(Line[1:]) LineNumber += 1
print('\n=== END ===') time.sleep(5)
This code is valid I think but since it always has a space before each line python compiles please remoeve the one space before each line
- Assistant