Question: Description Write a program that will take an input file called input.txt which will contain a Java program and parse it and output an annotated
Description
Write a program that will take an input file called input.txt which will contain a Java program and parse it and output an annotated version.
Your program will track the nesting depth of the braces of the input file and will output an annotated version of the file.
Your final program will:
List the nesting depth of curly braces
Ignore braces inside quotes or comments
Test for unmatched braces expected but found EOF; output an error message
Allow for multiple braces on the same line, for example ending a loop and a function
Handle block comments that cross multiple lines of the input file.
example:
comment with
ignored brace
Use Python
Assume that braces can be anywhere
Assume that all quoted strings begin and end on the same line.
Sample INPUT:
import blah;
class Foo
void Foo
System.out.printlnbraces are fun! ; ignored
if condition
also ignored:
int a ;
as is this:
what if this were on one line?
end of program
Sample annotated OUTPUT:
import blah;
class Foo
void Foo
System.out.printlnbraces are fun! ; ignored
if condition
also ignored:
int a ;
as is this:
end of program
Extra credit A points
Output the source code to be properly indented, even if the input was all one line. This is also known as pretty print
INPUT:
if condition int a ;
BECOMES:
if condition
int a ;
Extra Credit B points
Handle input in which characters can be escaped using the backslash character
Example:
System.out.println; how do you print a single quote character? This is not it
System.out.println; you have to escape it does the close brace get ignored?.PLEASE DO THE EXTRA CREDIT TOO
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
