标签:sem top symbols print tac 复杂 pre als arc
from pythonds.basic.stack import Stack
def parchecker(SymbolString):
s=Stack()
balance=True
index=0
while index<len(SymbolString) and balance:
if SymbolString[index] in ‘{[(‘:
s.push(SymbolString[index])
elif s.isEmpty():
balance=False
else:
top=s.pop()
if not match(top,SymbolString[index]):
balance=False
if s.isEmpty() and balance:
return True
else:
return False
def match(open,close):
a=‘{[(‘
b=‘}])‘
if a.index(open)==b.index(close):
return True
else:
return False
print(parchecker(‘{{([][])}()}‘))
标签:sem top symbols print tac 复杂 pre als arc
原文地址:https://www.cnblogs.com/masterhu/p/9665394.html