Chapter 5-Concepts of Programming Languages(Robert W. Sebesta)-Mr. Tri Djoko Wahjono, Ir, M.Sc.

REVIEW QUESTION

 1. What are the design issues for names?

-are name case sensitive?

-are the special words of language reserved words or keywords?

4. What is an alias?

An alias is variables that has different name but share the same memory allocation.

7. Define binding and binding time

Binding is an association between an attribute and an entity, such as between a variable and its type of value, or between an operation and a symbol. Binding time is the time at which binding takes place. Binding and binding times are prominent concepts in semantics of programming language.

9. Define static binding and dynamic binding

A static binding is a binding that occurs before run time begins and remains unchanged throughout program execution. A dynamic binding is when the binding first occurs during run time or can change in the course of program execution.

18. What is a block?

A block is a section of code. Blocks provide origin of phrase block-structures language

23. What are the advantages of named constant?

-aids to readability and program reliability

-to parameterized a program

 

PROBLEM SET

1. Decide which of the following identifier names is valid in C language, support your decision.

_Student, int, Student, 123Student, Student123.

The valid identifier names are _Student, Student, Student123. Because the rules are that it should not start with any number. Only underscore (_) symbol used in declaration. And the name should not a keyword.

 

9. Consider the following Phyton program:

x=1;

y=3;

z=5;

def sub1():

a=7;

y=9;

z=11;

…….

def sub2():

global x;

a=13;

x=15;

w=17;

……..

def sub3():

nonlocal a;

a=19;

b=21;

z=23;

…….

…….

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 scoping is used.

Variable           Where Declared

In sub1:

a                     sub1

y                     sub1

z                     sub1

x                     main

In sub2:

a                     sub2

x                     sub2

w                    sub2

y                     main

z                     main

In sub3:

a                     sub3

b                     sub3

z                     sub3

w                    sub2

x                     sub2

y                     main

 

10. Consider the following C program:

Void fun(void){

int a,b,c;

……..

while(….){

int b,c,d;

………//1

while(….){

int c,d,e;

………//2

}

………//3

}

……….//4

}

For each of the four marked points in this function, list each visible variable, along with the number of the definition statements that defines it.

1: a from function fun, and b,c,d in the while

2: a from function fun, and c,d,e in the inner while, b from outer while

3: a from function fun, and b,c,d in the while

4: a, b from function fun

 

Leave a comment