from list_stack import Stack """Various stack applications""" def is_valid_source( srcfile ): """Check to see if the pairs in source code are valid""" s = Stack() for line in srcfile : for token in line : if token in "{[(" : s.push( token ) elif token in "}])" : if s.is_empty() : return False else : left = s.pop() if (token == "}" and left != "{") or \ (token == "]" and left != "[") or \ (token == ")" and left != "(") : return False return s.is_empty() f = open('c_source.txt', 'r') text = f.read() print('check to see if source is valid : ', is_valid_source(text))