Programming Language assignment

Programming Language assignment

Kim 4

Textbook Assignment 2 : Introduction

1. Question 3.2. In Fortan 77, local variables were typically allocated statically. In Algol and its descendants (e.g., Ada and C), they are typically allocated in the stack. In Lisp they are typically allocated at least partially in the heap. What accounts for these differences? Give an example of a program in Ada or C that would not work correctly if local variables were allocated statically. Give and example of a program in Scheme or Common Lisp that would not work correctly if local variables were allocated on the stack.

2. Question 3.4. Give three concrete examples drawn from programming languages with which you are familiar in which a variable is live but not in scope.

3. Question 3.5. Consider the following pseudocode: Suppose this was code for a language with the declaration-order rules of C(but with nested subroutines) – that is, names must be declared before use, and the scope of a name extends from its declaration through the end of the block. At each print statement, indicate which declarations of a and b are in the referencing environment. What does the program print (or will the compiler identify static semantic errors)? Repeat the exercise for the declaration-order rules of C# (names must be declared before use, but the scope of a name is the entire block in which it is declared) and of Modula-3 (names can be declared in any order, and their scope is the entire block in which they are declared).

 

 

4. Question 3.7. A part of the development team at MumbleTech.com, Janet has written a list manipulation library for C that contains, among other things, the code in Figure 3.16.

a. Accustomed to Java, new team member Brad includes the following code in the main loop of his program: Sadly, after running for a while, Brad’s program always runs out of memory and crashes. Explain what’s going wrong.

b. After Janet patiently explains the problem to him, Brad gives it another try: This seems to solve the insufficient memory problem, but where the program used to produce correct results (before running out of memory), now its output is strangely corrupted, and Brad goes back to Janet for advice. What will she tell him this time?

5. Question 3.14. Consider the following pseudocode: What does this program print if the language uses static scoping? What does it print with dynamic scoping? Why?

 

6. Question 3.18. Consider the following pseudocode: Assume that the language uses dynamic scoping. What does the program print if the language uses shallow binding? What does it print with deep binding? Why?

 
Do you need a similar assignment done for you from scratch? Order now!
Use Discount Code "Newclient" for a 15% Discount!