The world’s Largest Sharp Brain Virtual Experts Marketplace Just a click Away
Levels Tought:
Elementary,Middle School,High School,College,University,PHD
| Teaching Since: | Apr 2017 |
| Last Sign in: | 103 Weeks Ago, 4 Days Ago |
| Questions Answered: | 4870 |
| Tutorials Posted: | 4863 |
MBA IT, Mater in Science and Technology
Devry
Jul-1996 - Jul-2000
Professor
Devry University
Mar-2010 - Oct-2016
hi, i need a complete java code for this question.thanks for your help. :)
Â
Famous programmer and open source activistRichard Stallmanhasoften complained thatcode on the web is unreadable, and that it isimpossible to determine its intentions by looking at it. In order to makejavascript code (which is always accessible to a website's user) fast andunreadable, developers use code obfuscators, which rename variablesand remove whitespace. Minified and obfuscated code is oftenespecially difficult to read because it appears in blocks. In order to helpcranky old developers likeMr. Stallmanreadcode, you will be writing aprogram that neatly formats javascript code.Fortunately, JavaScript looks a lot like Java: its instructions are delimitedby semicolons and its code blocks are delimited with curly braces. Yourjob will be to add new lines after each instruction, correctly indent thecode, and make sure that curly braces and parentheses are closed inthe correct order. By using a stack and a counter, you should also beable to determine the indentation level of the code, and determine if anyparentheses and curly braces are missing, or in the wrong order. If youcatch any code block or parentheses errors while neatly formatting yourcode, the program should stop and report the error to the user at the endof the now neatly formatted file.How it works: Read through the JavaScript file character by characterand copy it over to a new string. Every time you encounter a curly brace,or a semicolon (outside a for loop), add a newline character, as well asthe correct number of tab characters to the new string. The number oftabs starts at 0. Every time you encounter an opening curly brace, addone to the number of tabs. Every time you encounter a closing curlybrace, subtract one. Every time you encounter an opening curly brace,push the BRACE BlockType to the stack. Every time you encounter theopening parenthesis (that isn't part of the for loop), push the PARENBlockType to the stack. Every time you encounter the string "for(, pushthe FOR BlockType to the stack. Every time you encounter a closingcurly brace or closing parenthesis, pop from the stack. If the item youpopped does not match the type of closing character you encountered(or is empty), stop and print a new line explaining the problem. You donot need to continue to parse the rest of the file. Note: closingparenthesis matches both PAREN and FOR block types.
Attachments:
-----------