Write a program to implement Algorithm 3-9, “Parse Parentheses,” matching
braces rather than parentheses. In your implementation, push the line
number into the stack rather than the opening brace. When an error
occurs, print the line number for the unmatched opening brace or
unmatched closing brace. Test your program by running the source code
through itself (there should be no errors)
Here's the algorithm
Algorithm parseParens
This algorithm reads a source program and parses it to make
sure all opening-closing parentheses are paired.
1 loop (more data)
1 read (character)
2 if (opening parenthesis)
1 pushStack (stack, character)
3 else
1 if (closing parenthesis)
1 if (emptyStack (stack))
1 print (Error: Closing parenthesis not matched)
2 else
1 popStack(stack)
3 end if
2 end if
4 end if
2 end loop
3 if (not emptyStack (stack))
1 print (Error: Opening parenthesis not matched)
end parseParens