Created
February 6, 2017 11:48
-
-
Save BlueNexus/106f7013802e210dfaecc6ba7c342f98 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
python_file = '../PyROV/game.py' | |
workfile = None | |
basic_conversion_rules = {"=": "TO", "if": "IF", "==": "EQUALS", "while": "WHILE", "until": "UNTIL", "import": "IMPORT", "class": "DEFINE CLASS", "def": "DEFINE FUNCTION", "else": "ELSE", "elif": "ELSEIF", "except": "EXCEPT", "try": "TRY", "pass": "PASS"} | |
prefix_conversion_rules = {"=": "SET ", "#F": "CALL "} | |
advanced_conversion_rules = {"print": "OUTPUT", "return": "RETURN", "input": "INPUT"} | |
def f2list(to_list): | |
return to_list.readlines() | |
def l2pseudo(to_pseudo): | |
for line in to_pseudo: | |
line = str(line) | |
line = re.split(r'(\s+)', line) | |
for key, value in prefix_conversion_rules.items(): | |
if key in line: | |
line[2] = value + line[2] | |
for key, value in basic_conversion_rules.items(): | |
for word in line: | |
if key == str(word): | |
line[line.index(word)] = value | |
line = "".join(line) | |
print(line) | |
def main(): | |
main_file = open(python_file, 'r+') | |
work_file = f2list(main_file) | |
work_file = l2pseudo(work_file) | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment