and matched with the preceding right parenthesis thusunbalanced delimiters in which there are more closing delimiters than opening ones can be detected when trying to pop from the stack and we detect the stack is empty operation stack current point of scan push int sumlistpop match empty int sumlistint valuespop match error int sumlistint values)scanningint sumlistint values)]int size operation stack push push push pop match pop match current point of scan int sumlistint sumlistint int sumlistint (valuesint sumlistint values[int sumlistint values[]int size scanningint sumlistint (values[]int size table sequence of steps scanning an invalid set of delimiters the function header(topcontains more closing delimiters than opening and (bottomcontains more closing delimiters than opening delimiters can also be out of balance in the reverse case where there are more opening delimiters than closing ones consider another version of the function headeragain containing typographical errorint sumlistint (thelist[]int size the result of applying our algorithm to this code fragment is illustrated in the bottom chart in table if this were the complete code segmentyou can see we would end up with the stack not being empty since there are opening delimiters yet to be paired with closing ones thusin order to have complete algorithmwe must check for both of these errors python implementation for the validation algorithm is provided in listing the function isvalidsource(accepts file objectwhich we assume was previously opened and contains +source code the file is scanned one line at time and each line is scanned one character at time to determine if it contains properly paired and balanced delimiters stack is used to store the opening delimiters and either implementation can be used since the implementation is independent of the definition herewe have chosen to use the linked list version as the file is scannedwe need only examine