BalanceCheckStack

Ratings: 1 Star2 Stars3 Stars4 Stars5 Stars (4.00 out of 5) - Rate Now!
Loading...

Download Category:

BalanceCheckStack.zip - (115.06 KB)
[
BalanceCheckStack/build.xml
BalanceCheckStack/build/
BalanceCheckStack/build/classes/
BalanceCheckStack/build/classes/balancecheckstack/
BalanceCheckStack/build/classes/balancecheckstack/BalanceCheckStack.class
BalanceCheckStack/helloworld.java
BalanceCheckStack/manifest.mf
BalanceCheckStack/nbproject/
BalanceCheckStack/nbproject/build-impl.xml
BalanceCheckStack/nbproject/genfiles.properties
BalanceCheckStack/nbproject/private/
BalanceCheckStack/nbproject/private/private.properties
BalanceCheckStack/nbproject/private/private.xml
BalanceCheckStack/nbproject/project.properties
BalanceCheckStack/nbproject/project.xml
BalanceCheckStack/Question.txt
BalanceCheckStack/Screenshot_1.png
BalanceCheckStack/src/
BalanceCheckStack/src/balancecheckstack/
BalanceCheckStack/src/balancecheckstack/BalanceCheckStack.java
BalanceCheckStack/test/
]

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);
}
}

Get a fresh solution of this question. Ask it now to our experts.
doubt

Ask Your Question

We have verified professionals who are ready to answer your question.

time

Save Time and Money

We choose experts who can quickly answer your question and that suit your budget.

download

Get Your Answer

Your satisfaction is 100% guaranteed. You can keep on asking questions until you get the answer you need.