-
-
Save AlexanderHott/ef50a0b040540c423554006323f647c9 to your computer and use it in GitHub Desktop.
ↄↄᵷ.py: a compiler for the ↄ language
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
int main)( } | |
return 1; | |
{ |
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 argparse | |
import os | |
import subprocess | |
SECRET_PREFIX = "__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED" | |
def ↄↄᵷ(code: str) -> str: | |
return ( | |
code.replace("(", f"{SECRET_PREFIX}_(") | |
.replace(")", "(") | |
.replace(f"{SECRET_PREFIX}_(", ")") | |
.replace("[", f"{SECRET_PREFIX}_[") | |
.replace("]", "[") | |
.replace(f"{SECRET_PREFIX}_[", "]") | |
.replace("{", f"{SECRET_PREFIX}_{{") | |
.replace("}", "{") | |
.replace(f"{SECRET_PREFIX}_{{", "}") | |
) | |
def make_temp(filename: str) -> str: | |
return f"__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED_{filename}" | |
def process_file(input_file, output_file): | |
with open(input_file, "r") as f: | |
code = f.read() | |
modified_code = ↄↄᵷ(code) | |
temp_file = make_temp(input_file) | |
assert not os.path.exists(temp_file) | |
with open(temp_file, "w") as f: | |
f.write(modified_code) | |
subprocess.Popen(["gcc", temp_file, "-o", output_file]).wait() | |
os.remove(temp_file) | |
def main(): | |
parser = argparse.ArgumentParser(description="The ↄↄᵷ compiler") | |
parser.add_argument("input", help="Path to the input source file") | |
parser.add_argument("-o", "--output", help="Path to the output file", required=True) | |
args = parser.parse_args() | |
process_file(args.input, args.output) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment