Skip to content

Instantly share code, notes, and snippets.

@guysoft
Last active April 8, 2017 12:22
Show Gist options
  • Save guysoft/c43e94da4f23a5f37daee04d0ec194c1 to your computer and use it in GitHub Desktop.
Save guysoft/c43e94da4f23a5f37daee04d0ec194c1 to your computer and use it in GitHub Desktop.
Parse arguments
a='base(octopi,a(b,c(a2)),mm)'
def parse(a):
stack=[]
token = ""
for char in a:
if char == "(":
stack.append(token)
if token != "":
print("start_" + token)
token = ""
elif char == ")":
parrent = stack.pop()
if token != "":
print("start_" + token)
print("end_" + token)
token = ""
if parrent != "":
print("end_" + parrent)
elif char == ",":
if token != "":
print("start_" + token)
print("end_" + token)
token = ""
else:
token += char
if token != "":
print("start_" + token)
print("end_" + token)
if len(stack) > 0:
raise Exception(str(stack))
return
parse(a)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment