Fall 2022 Programming Languages Homework 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 Make I do not sure you complete the entire submission process in Brightspace before leaving the page recommend 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 a single PDF document Your Flex and Bison program must be tested to execute properly on the CIMS computers using Flex 2 6 and Bison 3 7 Use the commands module load bison 3 7 and module load flex 2 6 on the CIMS computers to use these versions You can use any system you want to perform the development work but in the end it must run on the CIMS machines All students registered in this course who do not already have accounts on CIMS should have received an email with instructions on how to request an 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 collaborate with other students or use materials from an outside source i e people books Internet etc in answering specific homework questions However you may collaborate and utilize reference material for understanding the general topics covered by the homework For example discussing the topic of regular expressions or the C C programming languages with a classmate is permitted as long as the 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 be downloaded from the Assignments tab in NYU Brightspace 1 1 15 points Language Standards A programming language s standard serves as an authoritative source of information concerning that language Someone who claims expertise in a particular programming language should be thoroughly familiar 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 documents on the course web page which contain recent publicly available documents1 In your answers to every question below you must cite the specific sections and passages in the relevant standard s serving as the basis for your answer No prior knowledge of either language is assumed nor expected but you cannot simply provide the answer with no evidential support or you will lose credit Do not cite to web pages books textbooks Stack Overflow or any other source besides the language 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 which are implicitly final What are the different kind of these variables Section 4 12 4 Page 99 Three kinds of variable are implicitly declared final a field of an interface 9 3 a local variable declared as a resource of a try with resources statement 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 but may be effectively final 2 As far as floating pointing calculations in Java are concerned the JVM implementation is free to use extra precision where available thus giving different precision across different platforms In order to prevent this behavior Java allows the use of a modifier keyword What is the this keyword Give an example usage of this modifier Section 8 1 1 3 Page 224 The effect of the strictfp modifier is to make all float or 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 allowed in Java If yes give an example If no what is an alternative to string data type which can be used 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 char is 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 in JLS 15 where this question is answered See Example 8 3 1 1 2 Hiding of Class Variables See Example 8 3 1 1 3 Hiding of Instance Variables 5 In C a common way to access objects created on the heap is using pointers However use of pointers sometimes creates memory management issues when programmers have many pointers pointing to the same object This can result in the creation of zombie pointers In an effort to mitigate this issue the concept of smart pointers was introduced in C Two of the most commonly used smart pointers are unique ptr and shared ptr What is the difference between these 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 2017 working draft is free We therefore use the 2017 working draft for the purposes of this assignment and course Page 2 Section 23 11 1 and Section 23 11 2 2 A unique pointer is an object that owns another object and manages that other object through a pointer The shared ptr class template stores a pointer usually obtained via new shared ptr implements semantics of shared ownership A shared ptr is to be used over a unique ptr when there we need to use multiple pointers to point to the same object or when we need the objects to be CopyConstructible or CopyAssignable like cases where multiple different process modify the data but using different pointers A unique ptr is used over a shared pointer when we want the data to be only modified through one pointer and this is not shared by any other pointer
View Full Document
Unlocking...