0% found this document useful (0 votes)
16 views

Programming Languages Assignment 1: Deadline: Sunday 13 December 2020

This document outlines an assignment for a programming languages course. It includes two programming problems to solve. Problem 1 involves answering short questions about programming language concepts like variable naming, type inference, variable lifetime and scope, static and dynamic scoping, and language design. Problem 2 involves briefly answering questions about static and dynamic scoping in different programming languages, including describing situations where dynamic scoping can make a program difficult to read. It provides examples in JavaScript and C to analyze variable visibility under static and dynamic scoping. It also asks to time different ways of declaring large arrays in C++ to explain the results. The deadline for submission is December 13, 2020 and the document notes submissions must be in .docx or .pdf format and

Uploaded by

ali sheikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views

Programming Languages Assignment 1: Deadline: Sunday 13 December 2020

This document outlines an assignment for a programming languages course. It includes two programming problems to solve. Problem 1 involves answering short questions about programming language concepts like variable naming, type inference, variable lifetime and scope, static and dynamic scoping, and language design. Problem 2 involves briefly answering questions about static and dynamic scoping in different programming languages, including describing situations where dynamic scoping can make a program difficult to read. It provides examples in JavaScript and C to analyze variable visibility under static and dynamic scoping. It also asks to time different ways of declaring large arrays in C++ to explain the results. The deadline for submission is December 13, 2020 and the document notes submissions must be in .docx or .pdf format and

Uploaded by

ali sheikh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programming Languages

Assignment 1
Deadline: Sunday 13 December 2020
Note: You have to submit the assignment either in .docx or .pfd format. In case of plagiarism
you will be award zero.
Problem 1: Answer the following short questions. 15 Marks. [CLO 1]
1. In C++, C# and Java, how long a variable name can be?
2. What is type inference? give an example.
3. What is the life time and scope of a variable? Explain with example.
4. What is the general problem with static scoping?
5. What are advantages and disadvantages of dynamic type binding?
6. After language design and implementation, what are the four time bindings can take place in a
program.
7. How the reference to a nonlocal variable in static –scoped program connected to its definition.
8. What is static ancestor and dynamic ancestor of a subprogram?

Problem 2: Answer the following question briefly. 15 Marks. [CLO 3]


1. Write a simple assignment statement with one arithmetic operator in Java. For each of the
component of the statement, list the various bindings that are required when statement is
executed.
2. Describe the situation when dynamic scoping makes a program difficult to read.
3. Consider the following JavaScript skeletal program

//The main program

var x;
function sub1()
{
var x;
function sub2()
{
.......
}
}
function sub3()
{
.......
}
Assume that the execution of the program is in the following unit order
main call sub1
sub1 call sub2
sub2 call sub3
a) Assume the static scoping, in the following, which declaration of the x is corrected one for
a reference to x?
i. Sub1
ii. Sub2
iii. Sub3

b) Repeat part a but assume dynamic scoping.

4. Consider the following skeletal C program:

void fun1 (void);


void fun2 (void);
void fun3 (void);

void main()
{
int a,b,c ;
....
}
void fun1(void)
{
int b,c,d ;
....
}
void fun2(void)
{
int c,d,e ;
....
}
void fun3(void)
{
int d,e,f ;
....
}

Given the following calling sequences and assuming that the dynamic scoping is used, what
variable are visible during the execution of the last function called.
i. Main calls fun1; fun1 calls fun2; fun2 calls fun3;
ii. Main calls fun3; fun3 calls fun2; fun2 calls fun1;
5. Write three functions in C++: one that declares a large array statically, one that declares the
same large array on the stack, and one that creates the same large array from the heap. Call
each of the subprogram a large number of times (at least 100,000) and output the time required
by each. Explain the results.

You might also like