Concepts of Programming Languages ---- Chapter 5 Names, Bindings, and Scopes
Name : Fandy Limardi
NIM : 1601210713
Lecture : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment : Concept of programming languages ---- Chapter 5 Names, Bindings, and Scopes
Name : Fandy Limardi
NIM : 1601210713
Lecture : Tri Djoko Wahjono, Ir., M.Sc. (D0206)
Assignment : Concept of programming languages ---- Chapter 5 Names, Bindings, and Scopes
Review Questions
1.
What are the design issues for names?
-
Are names case sensitive?
-
Are the special words of the language reserved
words or keywords?
2.
What is the potential danger of case sensitive
names?
Case sensitive violates the design
principle that language constructs that look similar should have similar
meanings. But in language whose variable names are case-sensitive, although for
example rose and Rose look similar, there is no connection between them.
3.
In what way are reserved words better than keywords
As a language design choice, reserved words
are better than keywords because the ability to redefine keywords can be
confusing.
4.
Which category of C++ reference variables is
always aliases?
Union type category of C++ reference
variables is always aliases.
5.
What is the referencing environment of a
statement?
The referencing environment of a statement
is the collection of all variables that are visible in the statement.
6.
What is a block?
Block is a section of code which the
section is entered and deallocated when the section is exited.
7.
What are the advantages and disadvantages of
dynamic scoping?
Adavantages :
-
Easier to read
-
More reliable
-
Execute faster than equivalent programs in
dynamic scoped languages.
Disadvantages :
-
There is no way to protect local variables from
this accessibility.
-
Inability to type check references to nonlocals
statically.
-
Dynamic scooping makes programs much more
difficult to read, because the calling sequence of subprograms must be known to
determine the meaning of references to nonlocal variables.
8.
What are the advantages of named constants?
The advantages of named constants are useful
as aids to readability and program reliability.
Problem Set
1.
Decide which of the following identifier names
in valid in C language. Support your decision
_Student
Int
Student
123Student
Student123
Answer : _Student, Student,Student123
2.
What is l-value? Write a statement in C language
which gives the compile time error “l-value required”
The address of a variable is sometimes
called its I-value. The statement in C language which gives the compile time
error is scanf(“%d”, value);
3.
Why is the type declaration of a variable
necessary? What is the value range of the int type variable in Java?
Because the program have to know what data
type of a variable and the value of the variable. The value range of the int
type variable in Java is around -2147483648 to 2147483647.
4.
Assume the following JavaScript program was
interpreted using static-scoping rules. What value of x is displayed in
function sub1?
Under dynamic-scoping rules, what value of x is displayed in sub1?
Under dynamic-scoping rules, what value of x is displayed in sub1?
var
x;
function sub1() {
document.write("X="+ x +
" <br />");
}
function sub2() {
var x;
x=10
sub1();
}
x=5;
sub2();
Answer
: Static scope: x=5 Dynamic scoping: x=10.
No comments:
Post a Comment