Question: Need help writing the java code according to the requirement below. 1. A prettyprinter is a tool that takes program source code as input and

Need help writing the java code according to the requirement below.

Need help writing the java code according to the requirement below. 1.A prettyprinter is a tool that takes program source code as input

1. A prettyprinter is a tool that takes program source code as input and outputs the same code, nicely formatted for readability. In this problem, you will write a prettyprinter for a C like language. The input for your program will be a sequence of "words" on stdin, spanning one or more lines. The words denote tokens, the "pieces" that make up a program. The words will be separated from each other by one or more whitespace characters (space, tab, newline). Your program will take these tokens and arrange them nicely, according to the following rules: Initially, the code is flush to the left margin (i.e., not indented) If the word is print the word and go to the next line If the word is l, print the word, go to the next line, and the following lines will be indented by one more space than previously; If the word is), it should be printed on its own line, indented one character to the left of the lines between it and its matching (i.e., the indentation level will be the same as the indentation level of the line that contained the matching 0, and the following lines are indented to the same level as this word If the word is then the rest of the current line of input is considered a comment, and must be printed exactly as it is, including spacing Except for comments, all of the tokens on a line should be separated from one another by exactly one space. Sample input: int f int x This is my function int y x y y 1 return y END of my function int main int n 0 while n 10 f n f n Corresponding output: int f (int x) This is my function int y y 1 return y of my function END int main int n 0 while n 10) n Your solution must not print any extra whitespace at the end of the line (exception: if a comment ends with spaces, then you must keep those spaces in your output

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!