Parse arguments
This file contains 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
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