Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Download: http://solutionzip.com/downloads/balancecheckstack/
- 1 Parenthesis Matching
- You are asked to write a balance-symbol checker which checks for the following
- pairs of symbols in the source code ?les of Java programs: (), [], fg. 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.
- The same algorithm can be found in slide 24 of the presentation slides or on
- page 215 of the textbook. 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.
- 12 Input
- Your program must take as input the name of a Java source code ?le such as the
- source ?le containing the source code of this assignment.
- 3 Output
- While your balance-symbol checker is running, it should print errors described in
- the algorithm above when they occur in the source code. To visualize the stack
- of your checker, your program can display the contents of the stack while it is
- running in an easily readable format. You are free to experiment with any format
- for easy readability.
- 4 Submission
- This assignment is due by the date above. Only the source code ?le should be
- turned in following the same instructions as for Assignment 1.
- 5 Sample Run
- Below you will ?nd an illustrated run of the algorithm given above. It will be
- run on the โHello Worldโ program. For ease of reading the source code of โHello
- Worldโ is as follows:
- public class HelloWorld {
- public static void main (String [] args) {
- System.out.println(Hello World);
- }
- }
- Download: http://solutionzip.com/downloads/balancecheckstack/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement