Question: Probelm 1 1.Consider the following JavaScript program (6pts) var x, y, z; function sub1 ( ) { var a, y, z; function sub2 ( )
Probelm 1
1.Consider the following JavaScript program (6pts)
var x, y, z;
function sub1 ( ) {
var a, y, z;
function sub2 ( ) {
var a, b, z;
. }
. }
function sub3 ( ){
var a, x, w;
.......}
List all the variables, along with the program units where they are declared, that are visible in the bodies of sub1, sub2 and sub3, assuming static scope.
2.Show the order of evaluation of the expressions assuming that there are no precedence rules and all operators associate right to left. (9 pts)
(i) . a * b -1 + c
(ii) . (a-b)/c & (d*e/a-3)
(iii) . a * (b-1) /c mod d
3. Let the function fun be defined as (10 pts)
fun(int *k)
{
*k +=4;
return 3 * (*k) - 1; }
suppose fun is used in the program as follows
void main( ){
int i = 10, j = 10, sum1, sum2;
sum1 = (i / 2) + fun ( &i );
sum2 = fun ( &j ) + ( j / 2);}
What are the values of sum1 and sum2
a. Operands in the expressions are evaluated left to right?
b. Operands in the expressions are evaluated right to left?
4.Consider the following JavaScript Skeletal program (10 pts)
// the main program
var x;
function sub1( ) {
var x;
function sub2( ) {
}
}
function sub3 ( ) {
..
}
Assume that the execution of this program is in the following unit order:
main calls sub1
sub1 calls sub2
sub2 calls sub3
a. Assuming static scoping, in the following, which declaration of x is the correct one for reference to x
i)sub1 ii) sub2 ii) sub 3
b.Repeat part a but assume dynamic scoping.
5. Write a Scheme function get-odd-nums that accepts a list of numbers and returns a new list that contains only the odd numbers. (5 pts)
Example: (get-odd-nums ' (1 2 3 4 5 6 7 8 9 )) should return (9 7 5 3 1)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
