Unformatted text preview:

Fall 2022Programming LanguagesHomework 1 - Solutions• Due Sunday, October 2, 2022 at 11:59 PM Eastern Time.• Late submissions will not be accepted. No exceptions.• The homework must be submitted entirely through NYU Brightspace—do not send by email. Makesure you complete the entire submission process in Brightspace before leaving the page. I do notrecommend waiting until the last minute to submit, in case you encounter difficulties.• This assignment consists of programming tasks in Flex/Bison and also “pencil and paper” questions.Submit programs according to the instructions in question 4. Submit all other written responses in asingle PDF document.• Your Flex and Bison program must be tested to execute properly on the CIMS computers using Flex2.6 and Bison 3.7. Use the commands “module load bison-3.7” and “module load flex 2.6” on theCIMS computers to use these versions. You can use any system you want to perform the developmentwork, but in the end it must run on the CIMS machines. All students registered in this course who donot already have accounts on CIMS should have received an email with instructions on how to requestan account.• While you are working on this assignment, you may consult the lecture material, class notes, text-book, discussion forums, and/or recitation materials for general information concerning Flex, Bison,grammars, or any topics related to the assignment. You may under no circumstance collaboratewith other students or use materials from an outside source (i.e., people, books, Internet, etc.) inanswering specific homework questions. However, you may collaborate and utilize reference materialfor understanding the general topics covered by the homework. For example, discussing the topic ofregular expressions or the C/C++ programming languages with a classmate is permitted, as long asthe discussion does not involve homework questions or solutions.• The “util.h” file required in question 4 (Extended Calculator) and the source file for this pdf can bedownloaded from the Assignments tab in NYU Brightspace.11. (15 points) Language StandardsA programming language’s standard serves as an authoritative source of information concerning thatlanguage. Someone who claims expertise in a particular programming language should be thoroughlyfamiliar with the language standard governing that language.In the exercises below, you will look into the language standards of several well-known languages, in-cluding C++, Java, and C# to find the answers to questions. You should use the standards documentson the course web page, which contain recent publicly available documents1In your answers to every question below, you must cite the specific sections and passages in therelevant standard(s) serving as the basis for your answer. No prior knowledge of either language isassumed nor expected, but you cannot simply provide the answer with no evidential support or you willlose credit. Do not cite to web pages, books, textbooks, Stack Overflow, or any other source besides thelanguage standard.1. When a variable is declared final in Java, it can be assigned a value just once (when it is unassigned).To make a variable final, one needs to use the final keyword. However, there are variables whichare implicitly final. What are the different kind of these variables?Section 4.12.4 - Page 99. Three kinds of variable are implicitly declared final: afield of an interface (§9.3), a local variable declared as a resource of a try-with-resourcesstatement (§14.20.3), and an exception parameter of a multi-catch clause (§14.20).An exception parameter of a uni-catch clause is never implicitly declared final, butmay be effectively final.2. As far as floating pointing calculations in Java are concerned, the JVM implementation is free to useextra precision where available thus giving different precision across different platforms. In order toprevent this behavior, Java allows the use of a modifier keyword. What is the this keyword? Givean example usage of this modifier.Section 8.1.1.3 - Page 224. The effect of the strictfp modifier is to make all floator double expressions within the class declaration (including within variable initializers,instance initializers, static initializers, and constructors) be explicitly FP-strict(§15.4).3. In C++, we can change the contents of a string variable (i.e., string is mutable). Is the same allowedin Java? If yes, give an example. If no, what is an alternative to string data type which can beused for this purpose? Cite the specific section in Java Language Specification.Section 10.9 - Page 374. In the Java programming language, unlike C, an array of charis not a String, and neither a String nor an array of char is terminated by ’\u0000’(the NUL character). A String object is immutable, that is, its contents never change,while an array of char has mutable elements.4. We know that, generally, variables in an outer scope can be hidden by variables in an inner scope.What about class and instance variables in Java? Can those be hidden? Cite the location(s) inJLS 15 where this question is answered.See Example 8.3.1.1-2 Hiding of Class VariablesSee Example 8.3.1.1-3 Hiding of Instance Variables5. In C++, a common way to access objects created on the heap is using pointers. However, useof pointers sometimes creates memory management issues when programmers have many pointerspointing to the same object. This can result in the creation of zombie pointers. In an effortto mitigate this issue, the concept of smart pointers was introduced in C++. Two of the mostcommonly used smart pointers are unique ptr and shared ptr. What is the difference betweenthese two? When should one be used over the other?1For example, the C++20 standard is a copyrighted document that must be purchased at a high cost, but the earlier 2017working draft is free. We therefore use the 2017 working draft for the purposes of this assignment and course.Page 2Section 23.11.1 and Section 23.11.2.2. A unique pointer is an object that owns anotherobject and manages that other object through a pointer. The shared_ptr class templatestores a pointer, usually obtained via new. shared_ptr implements semantics of sharedownership. A shared_ptr is to be used over a unique_ptr when there we need to use multiplepointers to point to the same object or when we need the objects to be CopyConstructibleor CopyAssignable like cases where multiple different process/modify the data but


View Full Document

NYU CSCI-GA 2110 - Homework 1 - Solutions

Download Homework 1 - Solutions
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Homework 1 - Solutions and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Homework 1 - Solutions 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?