4. Properly Nested Delimiters A Java program can have the following type of delimiters: (, }, (, ), [, and 1. In a correct Java program, these delimiters must be properly nested. Think of each left...


Please show an example  of how or how to solve coding the problem from Starting out with Java from control structures through data structures 4th edition: chapter 20  programming challenge 4


4. Properly Nested Delimiters<br>A Java program can have the following type of delimiters: (, }, (, ), [, and 1. In a correct Java<br>program, these delimiters must be properly nested. Think of each left delimiter (, (, and [ as opening<br>a scope, and think of each right delimiter }, ), and ] as closing a scope opened by a corresponding<br>left delimiter. A string of characters containing these delimiters has proper nesting of delimiters if<br>each scope that is opened is eventually closed, and the scopes are opened and closed in a last-<br>opened-first-closed fashion.<br>Write a program that reads a file containing Java source code and checks it for proper nesting of<br>delimiters. Your program should read the source code from the file and print it to the screen. If the file<br>is properly nested, all of it is printed to the screen and a message is printed that the file is properly<br>nested. If the file is not properly nested, then copying of the file to the screen stops as soon as<br>improper nesting is detected, and your program prints a message that the file has errors. To simplify<br>your task, you may assume these delimiters do not appear inside of comments and string literals, and<br>that they do not appear in the program as character literals.<br>

Extracted text: 4. Properly Nested Delimiters A Java program can have the following type of delimiters: (, }, (, ), [, and 1. In a correct Java program, these delimiters must be properly nested. Think of each left delimiter (, (, and [ as opening a scope, and think of each right delimiter }, ), and ] as closing a scope opened by a corresponding left delimiter. A string of characters containing these delimiters has proper nesting of delimiters if each scope that is opened is eventually closed, and the scopes are opened and closed in a last- opened-first-closed fashion. Write a program that reads a file containing Java source code and checks it for proper nesting of delimiters. Your program should read the source code from the file and print it to the screen. If the file is properly nested, all of it is printed to the screen and a message is printed that the file is properly nested. If the file is not properly nested, then copying of the file to the screen stops as soon as improper nesting is detected, and your program prints a message that the file has errors. To simplify your task, you may assume these delimiters do not appear inside of comments and string literals, and that they do not appear in the program as character literals.

Jun 09, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here