subject

A classic use of a stack if for checking whether an expression that contains a set of different kinds of bracketing (namely parentheses, square brackets, curly brackets, angle brackets) is "well formed". Such an expression is considered "well formed" if the open brackets match exactly the close brackets. This problem represents one portion of the design of a compiler that needs to check that all such pairs of brackets are properly balanced and nested. You will write a method that checks a given expression (a String) with characters and brackets ("()", "[]", "{}", "<>"), determine if it is well-formed by using the following algorithm in conjunction with a stack. β€’ Check the expression character by character. If the character is an opening bracket (characters β€˜(β€˜, β€˜[β€˜, β€˜{β€˜, β€˜<β€˜), then push it onto the stack β€’ Else if the character is a closing bracket (characters β€˜)’, β€˜]’, β€˜}’, β€˜>’), then: β€’ Check if the stack is empty. If it is, then there is no matching opening bracket. The expression is not well formed. β€’ If the stack is not empty, pop the top character off the stack, compare the current closing bracket to the top character. If they are matched brackets, continue to read next character in the expression; if they are not matched brackets, the expression is not well formed. β€’ If the end of the expression is reached, check if the stack is empty. If it is, the expression is well-formed. Otherwise, it is not well-formed.
Activities 1. Start Eclipse and create a new Java package lab2, create a new class named BalanceCheck. 2. Write a static method named matchCheck(String s). It should return true if the parameter string s is well-formed; return false otherwise. (1) Your code must instantiate a Stack to contain Character class objects using the java. util. Stack class. (2) Implement the algorithm in the introduction. (3) Your code should print meaningful error message when the expression is not well-formed. For example, "missing open bracket" if current character is a close bracket but stack is empty, "missing close bracket" if the end of string is reached but stack is not empty, or "mismatch brackets". 3. Write the main method in the same class, declare some strings and call the matchCheck(String s) method to check if your method works fine.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 24.06.2019 10:20
Write a program that keeps asking the user for new values to be added to a list until the user enters 'exit' ('exit' should not be added to the list). these values entered by the user are added to a list we call 'initial_list'. then write a function that takes this initial_list as input and returns another list with 3 copies of every value in the initial_list. finally, inside print out all of the values in the new list. for example: input: enter value to be added to list: a enter value to be added to list: b enter value to be added to list: c enter value to be added to list: exit output: a b c a b c a b c note how 'exit' is not added to the list. also, your program needs to be able to handle any variation of 'exit' such as 'exit', 'exit' etc. and treat them all as 'exit'.
Answers: 2
question
Computers and Technology, 24.06.2019 22:30
When can you access the bios setup utility?
Answers: 1
question
Computers and Technology, 25.06.2019 05:10
What is the disadvantage of a mesh topology?
Answers: 1
question
Computers and Technology, 25.06.2019 07:00
Asap 50 points ( paragraph pls) discuss the role of the concept behind the "internet of things (iot)" in today's digitally connected society.
Answers: 2
You know the right answer?
A classic use of a stack if for checking whether an expression that contains a set of different kind...
Questions
question
History, 24.06.2019 15:00
question
Mathematics, 24.06.2019 15:00
Questions on the website: 13722361