Review Question: Static Binding: First Occurs Before Run

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

CHAPTER 5

REVIEW QUESTION
1. What are the design issues for l-value :Address of a variable is called
names? its l-value. Address is what is required
Design issues for names are when the name of a variable appears in
the left side of an assignment. r-value:
• Case sensitive or not Variables value is called its rvalue. It is
• Special words what it is required when the name of
• Reserved words Keywords. the variable appears in the right side of
an assignment statement.

2. What is the potential danger of 7. Define binding and binding time. A


casesensitive names? binding is an association, such as
Readability is a potential danger of case association between an attribute and an
sensitive names. The names may look entity, or between an operation and a
similar but they will be pointing towards symbol. Binding time is the time at
two different values which will affect the which binding takes place.
readability of code.
8. After language design and
3. In what way are reserved words implementation [what are the four
better than keywords? times bindings can take place in a
Reserved words are better than keywords program?]
because it is special only in certain context
can be sometimes user defined but reserved • Compile time
words cannot be used as user defined name 4. • Load time
What is an alias? • Link time
When multiple variables points towards a • Run time
same memory location and one memory
can be access by multiple variable, all
those variables are called alias. 9. Define static binding and
dynamic binding.
5. Which category of C++ reference Static Binding: First occurs before run
variables is always aliases? time and remains unchanged throughout
Union types. It is a type whose variables program execution. Dynamic Binding:
may store different type values at different First occurs during execution or can
times during program execution. change during execution of the program.
10. What are the advantages and
6. What is the l-value of a variable? disadvantages of implicit
What is the r-value? declarations?
Advantage: Writability.
Disadvantages:
Reliability: They prevent the compilation Advantage: provides for dynamic
process from detecting some typographical storage management
and programmer errors. Implicit heap-dynamic: Variables are
Readability. bound to heap storage only when they
are assigned values.
11. What are the advantages and Advantage: flexibility (generic code)
disadvantages of dynamic type
binding? 13. Define lifetime, scope, static
Advantages: scope, and dynamic scope.
Lifetime: A time during which the
• Flexibility variable is bound to a specific memory
• No definite types location. The lifetime begins when it is
declared(PHP, JavaScript). bound to a specific cell and ends when
it is unbound from that cell. Scope:
Disadvantages:
Range of statements in which the
• Adds to the cost of variable is visible. A variable is visible
implementation. in a statement if it can be referenced in
that statement.
• Type error detection by the
compiler is difficult. Static scope: Based on program text
and to connect a name reference to a
variable.
12. Define static, stack-dynamic, Dynamic scope: Based on the calling
explicit heap-dynamic, and implicit sequence of subprograms, not on their
spatial relationship to each other. Can
heap dynamic variables. What are their
be determined only at run time.
advantages and disadvantages?
14. How is a reference to a
Static: Bound to memory cells before
execution begins and remains bound to nonlocal variable in a static-scoped
the same memory cell throughout the program connected to its
execution. definition?
Advantages: efficiency (direct A reference to a non-locally variable in a
addressing), history-sensitive subprogram static-scoped language with nested
support. subprograms requires a two-step access
Stack-dynamic: Variables are those process:
whose storage bindings are created when
• Find the correct activation record
their declaration statements are
instance.
elaborated, but whose types are statically
bound. • Determine the correct offset within
Advantages: recursion; conserves storage that activation record instance.
Explicit heap-dynamic: Variables are
nameless (abstract) memory cells that are
allocated and de allocated by explicit run- 15. What is the general problem with
time instructions written by the static scoping?
programmer.
• Too much access. 19. What is the purpose of the let
• Scope structure destroyed as program constructs in functional languages?
evolves. “let” introduces a new variable scope, and
16. What is the referencing allows you to bind variables to values for
environment of a statement? that scope. It is often read as “let x be
Referencing environment of a statement is the [value] in …”
collection of all names that are visible in the 20. What is the difference between
statement. the names defined in an ML let
construct from the variables declared
17. What is a static ancestor of a in a C block?
subprogram? What is a dynamic ML C Block
ancestor of a subprogram? In ML, the form of The variable's scope starts
Static ancestors: All the procedures in the a let construct is as from the point of the
program within which the procedure sub() is follows: let declaration to the end of the
defined, the definition of the procedure sub() val name 1 = block (next closing brace).
is nested. The definition of a procedure may expression 1 if( a< 15 ){ printf("%d",
be directly nested within only one procedure, ... 24); // b is not in scope in
called its static parent procedure. This static val name n = this line
parent procedure may itself be nested within expression n int b = 32;
another procedure, and so on up to the main() in expression printf("%d", b); // b is in
program. All these procedures are considered end; scope in this line
to be static ancestors of the procedure sub(). }
The static ancestors are those that strictly
contain the subprogram in question. Dynamic
ancestors: All the procedures called before
sub() during the execution of a program, that 22. What are the advantages and
have not yet finished executing. These are the disadvantages of dynamic scoping?
procedures that are waiting for procedure
Advantages:
sub() to finish executing before they can
terminate. In short, dynamic ancestors are • Writability.
those that are called to reach the subprogram • Convenient.
in question. • More flexibility than static scoping.

18. What is a block? Block: Some Disadvantages:


languages allows a section of code to have its
• Cant type-check at compile time.
own local variables whose scope is
minimized. Such variables are typically stack • Poor readability.
dynamic, so their storage is allocated when • Takes longer time to access non local
the section is entered and deallocated when variable.
the section is exited. Such a section of code is
23. What are the advantages of
called a block.
named constants?
Advantages:
• Readability. • Modifiability.
• Reliability.

You might also like