Details of this Paper

Java STACK Balanced symbol Checker EEL 4854 ? IT Data Structures




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.;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.;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.;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.;Course: EEL 4854 ? IT Data Structures;Homework #4


Paper#67883 | Written in 18-Jul-2015

Price : $27