Compilers check programs for syntax errors, but frequently a lack of one symbol (such as a missing brace or comment starter) will cause the compiler to spill out a number of diagnostics without identifying the real error. A useful tool in this situation is a program that checks whether every pair of symbols is balanced. Thus, every right brace, bracket, and parenthesis must correspond to its left counterpart. For instance, the sequence [()] is legal, but [(]) is not.
In this assignment, you are asked to write a balance-symbol checker which checks for the following pairs of symbols in the source code files of Java programs: (), [], {}. This checker must implement the following algorithm:
1. Make an empty stack.
2. Read symbols until the end of the source code file.
a. If the symbol is an opening symbol, push it onto the stack.
b. If it is a closing symbol, do the following:
i. If the stack is empty, report an error.
ii. Otherwise, pop the stack. If the symbol popped is not the corresponding opening symbol, report an error.
3. At the end of the file, if the stack is not empty, report an error.
As the algorithm above shows, a stack data structure must be used in this programming assignment. You are encouraged to use the Stack class available in the collections package of the Java API.
Input
Your program must take as input the name of a Java source code file such as the source file containing the source code of this assignment.