Skip to content

Instantly share code, notes, and snippets.

@CCXXXI
Created June 9, 2022 07:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CCXXXI/acc5d579d108aefb053ede5cae55aeee to your computer and use it in GitHub Desktop.
Save CCXXXI/acc5d579d108aefb053ede5cae55aeee to your computer and use it in GitHub Desktop.
import re
def convert(s: str) -> str:
start = re.search(r"/\* (.*) \*/\s*", s).group(1).replace("( ", "(")
s = re.search(r"T0_init.*;", s, re.S).group(0)
s = re.sub(r"/\*.*\*/\s*", "", s)
s = s.replace("init", "S1").replace("&&", "&").replace("(", "").replace(")", "")
s = re.sub(r"\s*(if|fi;)", "", s)
s = re.sub(r"T\d+_S(\d+)", r"\1", s)
s = re.sub(r":\s+::", "= ?\n =", s)
s = s.replace("::", "|").replace("\t", " " * 4).replace(" -> goto accept_all", "")
s = re.sub(r"-> goto (\d+)", r"& X(\1)", s)
s += "\n\ntrue = true & X(true) "
s = s.replace("1 = ?", "1 = " + start)
return s
if __name__ == "__main__":
with open("in.txt") as f:
print()
print(convert(f.read()))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment