Advertisement
akosiraff

BalanceCheckStack

Mar 6th, 2014
151
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.02 KB | None | 0 0
  1.  
  2. Download: http://solutionzip.com/downloads/balancecheckstack/
  3. 1 Parenthesis Matching
  4. You are asked to write a balance-symbol checker which checks for the following
  5. pairs of symbols in the source code ?les of Java programs: (), [], fg. This checker
  6. must implement the following algorithm:
  7. 1. Make an empty stack.
  8. 2. Read symbols until the end of the source code file.
  9. a. If the symbol is an opening symbol, push it
  10. onto the stack.
  11. b. If it is a closing symbol, do the following:
  12. i. If the stack is empty, report an error.
  13. ii. Otherwise, pop the stack. If the symbol
  14. popped is not the corresponding opening
  15. symbol, report an error.
  16. 3. At the end of the file, if the stack is not empty,
  17. report an error.
  18. The same algorithm can be found in slide 24 of the presentation slides or on
  19. page 215 of the textbook. As the algorithm above shows, a stack data structure
  20. must be used in this programming assignment. You are encouraged to use the
  21. Stack class available in the collections package of the Java API.
  22. 12 Input
  23. Your program must take as input the name of a Java source code ?le such as the
  24. source ?le containing the source code of this assignment.
  25. 3 Output
  26. While your balance-symbol checker is running, it should print errors described in
  27. the algorithm above when they occur in the source code. To visualize the stack
  28. of your checker, your program can display the contents of the stack while it is
  29. running in an easily readable format. You are free to experiment with any format
  30. for easy readability.
  31. 4 Submission
  32. This assignment is due by the date above. Only the source code ?le should be
  33. turned in following the same instructions as for Assignment 1.
  34. 5 Sample Run
  35. Below you will ?nd an illustrated run of the algorithm given above. It will be
  36. run on the โ€Hello Worldโ€ program. For ease of reading the source code of โ€Hello
  37. Worldโ€ is as follows:
  38. public class HelloWorld {
  39. public static void main (String [] args) {
  40. System.out.println(Hello World);
  41. }
  42. }
  43. Download: http://solutionzip.com/downloads/balancecheckstack/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement