{"id":79178,"date":"2021-12-02T23:22:53","date_gmt":"2021-12-02T23:22:53","guid":{"rendered":"https:\/\/papersspot.com\/blog\/2021\/12\/02\/instructions-name-your-document-as-netid_pa4-py-display-your-results-as-in-the\/"},"modified":"2021-12-02T23:22:53","modified_gmt":"2021-12-02T23:22:53","slug":"instructions-name-your-document-as-netid_pa4-py-display-your-results-as-in-the","status":"publish","type":"post","link":"https:\/\/papersspot.com\/blog\/2021\/12\/02\/instructions-name-your-document-as-netid_pa4-py-display-your-results-as-in-the\/","title":{"rendered":"INSTRUCTIONS Name your document as netid_PA4.py Display your results as in the"},"content":{"rendered":"<p>INSTRUCTIONS<\/p>\n<p> Name your document as netid_PA4.py <\/p>\n<p> Display your results as in the sample output.<\/p>\n<p> Write an explanation of your code using comments. If the explanation is not clear, you will NOT receive full credit.<\/p>\n<p> Use Python; it can be downloaded for free at python.org. <\/p>\n<p> There are two opportunities for extra credit described at the end and will turn them in as a separate source file by containing the base code and the extra credit code into a ZIP file using the same naming convention.<\/p>\n<p> Description<\/p>\n<p> 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.<\/p>\n<p> Your program will track the nesting depth of the braces of the input file and will output an annotated version of the file. <\/p>\n<p> Your final program will:<\/p>\n<p> 1. List the nesting depth of curly braces<br \/> 2. Ignore braces inside quotes or comments<\/p>\n<p> 3. Test for unmatched braces (expected \u2018}\u2019 but found EOF); output an error message<\/p>\n<p> 4. Allow for multiple braces on the same line, for example \u201c}}\u201d ending a loop and a function<\/p>\n<p> 5. Handle block comments that cross multiple lines of the input file.<br \/> example: <\/p>\n<p> \/* comment with <br \/> ignored brace { *\/<\/p>\n<p> Use Python<\/p>\n<p> Assume that braces can be anywhere<\/p>\n<p> Assume that all quoted strings begin and end on the same line. <\/p>\n<p> Sample INPUT:<br \/> &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br \/> import blah;<br \/> class Foo<br \/> {<br \/> \u00a0\u00a0 \u00a0 void Foo()<br \/> \u00a0\u00a0\u00a0 {<br \/> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;braces are fun! {{{{{&#8220;); \/\/ ignored<br \/> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (condition)<br \/> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br \/> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ also ignored: { <br \/> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int a = 1;<br \/> \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ as is this: }<\/p>\n<p> if (condition){ int b = 1; } a = 42; <\/p>\n<p> \u00a0\u00a0\u00a0\u00a0\u00a0 }\u00a0\/\/ what if this were on one line? }}}<br \/> \u00a0\u00a0\u00a0 }<br \/> } <br \/> \/\/end of program <\/p>\n<p> Sample annotated OUTPUT:<br \/> &#8212;&#8212;&#8212;&#8212;-<br \/> 0 import blah;<br \/> 0 class Foo<br \/> 1 {<br \/> 1 \u00a0\u00a0\u00a0void Foo()<br \/> 2 \u00a0\u00a0\u00a0{<br \/> 2 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 System.out.println(&#8220;braces are fun! {{{{{&#8220;); \/\/ ignored<br \/> 2 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 if (condition)<br \/> 3 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 {<br \/> 3 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ also ignored: { <br \/> 3 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 int a = 1;<br \/> 3 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 \/\/ as is this: }<br \/> 3 \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0 }<br \/> 2 \u00a0\u00a0\u00a0}<br \/> 1 }<br \/> 0 \/\/ end of program<\/p>\n<p> Extra credit A (10 points)<\/p>\n<p> Output the source code to be properly indented, even if the input was all one line. This is also known as \u2018pretty print\u2019. <\/p>\n<p> INPUT:<\/p>\n<p> if (condition){ int a = 1; }<\/p>\n<p> BECOMES:<\/p>\n<p> if (condition)<br \/> {<br \/> int a = 1;<br \/> }<\/p>\n<p> Extra Credit B (10 points)<\/p>\n<p> Handle input in which characters can be escaped using the backslash character \u201c\\\u201d<\/p>\n<p> Example:<\/p>\n<p> System.out.println(\u201c\u201d\u201d); \/\/ how do you print a single quote character? This is not it.<\/p>\n<p> System.out.println(\u201c{\\\u201d}\u201d); \/\/ you have to escape it, does the close brace get ignored?<\/p>\n<p> If you work on the extra credit you will turn in TWO source files, the base file named _PA4.py and your extra credit code file named _PA4_EC.py and your input file will be input_EC.txt. These files will be contained in a ZIP file named _PA4_EC.zip<\/p>\n<p> Note :- The sample input and output will not be the only test case used to test the working of your code. Do NOT contact the TA or instructor regarding the test cases.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>INSTRUCTIONS Name your document as netid_PA4.py Display your results as in the sample output. Write an explanation of your code using comments. If the explanation is not clear, you will NOT receive full credit. Use Python; it can be downloaded for free at python.org. There are two opportunities for extra credit described at the end [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[10],"class_list":["post-79178","post","type-post","status-publish","format-standard","hentry","category-research-paper-writing","tag-writing"],"_links":{"self":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/79178","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/comments?post=79178"}],"version-history":[{"count":0,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/posts\/79178\/revisions"}],"wp:attachment":[{"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/media?parent=79178"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/categories?post=79178"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/papersspot.com\/blog\/wp-json\/wp\/v2\/tags?post=79178"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}