In honor of Star Wars day, I've put together this small Python program I'm calling JediScript. JediScript is essentially a scrapped-down version of BrainFuck without input or looping. Here are the commands in JediScript.
SlashWithSaber: Move forward on the tape.ParryBladeWithSaber: Move backward on the tape.StabWithSaber: Increment a cell.BlockBladeWithSaber: Decrement cell.UseForceWithHands: Output the current cell.
Each command is semicolon ; separated, like so: StabWithSaber;UseForceWithHands. Here's an example input. This will output the character p.
StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;StabWithSaber;UseForceWithHands;
This is something that I threw together in about 20 minutes, so it's not the greatest, but I'd still appreciate a review.
#!/usr/bin/env python """ JediScript, BrainFuck for Star Wars. May the 4th be with you. """ DEFAULT_SPLIT = ";" """ Variables below this are environment variables for the user to modify. """ data_tape = [0 for _ in range(256)] tape_pos = 0 def increment_cell(): global data_tape global tape_pos data_tape[tape_pos] += 1 if data_tape[tape_pos] <= 127 else 0 def decrement_cell(): global data_tape global tape_pos data_tape[tape_pos] -= 1 if data_tape[tape_pos] >= 0 else 0 def move_forward(): global tape_pos tape_pos += 1 if tape_pos <= len(data_tape) - 1 else 0 def move_backward(): global tape_pos tape_pos -= 1 if tape_pos >= 0 else 0 def output_cell(): print chr(data_tape[tape_pos]) """ Dictionary contains tokens that reference their relevant functions. """ TOKENS = { "SlashWithSaber": move_forward, "ParryBladeWithSaber": move_backward, "StabWithSaber": increment_cell, "BlockBladeWithSaber": decrement_cell, "UseForceWithHands": output_cell, } def execute_commands(tokenized_string): """ Executes commands from the tokenized string. tokenized_string - The tokenized string """ for token in tokenized_string: if token in TOKENS: TOKENS[token]() def tokenize_input(string): """ Tokenize a string into it's the form [ token, ... ] string - The string to tokenize. """ string = string.replace(" ", "") string = string.split(DEFAULT_SPLIT) return string def get_user_input(prompt): """ Get input from the user. prompt - The prompt to be used. """ while True: string = raw_input(prompt) string = tokenize_input(string) execute_commands(string) if __name__ == "__main__": get_user_input("JediScript $ ")
sphericalnotes do? Other than error? \$\endgroup\$