NIM : 1801428434
Here is the sixth assignment of Programming Language Concepts course. The question is taken from "Concepts of Programming Language, 10th edition" from Robert W. Sebesta in chapter 6:
Review Questions
1. What is a
descriptor?
= A descriptor is the
collection of the attributes of a variable. In an implementation, a descriptor
is an area of memory that stores the attributes of a variable.
2. What are the
advantages and disadvantages of decimal data types?
= The advantage of
decimal types is being able to precisely store decimal values, at least those
within a restricted range, which cannot be done with floating-point.
The disadvantage of
decimal type is that the range of values is restricted because no exponents are
allowed, and their representation in memory is mildly wasteful.
3. What are the design
issues for character string types?
= Design issues for
character string types are
1) Should strings be
simply a special kind of character array or a primitive type?
2) Should strings have
static or dynamic length?
4. Describe the three
string length options.
= 1) Static length string : The length of
string is static and set when the string is created.
2) Limited dynamic length strings : Allow strings to have varying
length up to a declared and fixed maximum set by the variable’s definition.
Such string variables can store any number of characters between zero and the
maximum.
3) Dynamic length strings : Allow strings to have varying length with
no maximum.
5. Define ordinal,
enumeration, and subrange types.
= 1) Ordinal type is
one in which the range of possible values can be easily associated with the set
of positive integers. In Java, for example, the primitive ordinal types are
integer, char, and Boolean.
2) Enumeration is one
in which all of the possible values, which are named constants, are provided,
or enumerated, in the definition. Enumeration types provide a way of defining
and grouping collections of named constants.
3) Subrange is a
contiguous subsequence of an ordinal type. For example, 12..14 is a subrange of
integer type.
Problem Set
1. What are the
arguments for and against representing Boolean values as single bits in memory?
= A Boolean value could
be represented by a single bit. But, a single bit of memory cannot be accessed
efficiently on many machines, so they are often stored in smallest efficiently
addressable cell of memory, typically a byte.
2. How does a decimal
value waste memory space?
= Decimal types are
stored very much like character strings, using binary codes for decimal digits.
These representations are called binary coded decimal (BCD). In some cases,
they are stored one digit per byte, or two digits per byte. Either way, they
take more storage than binary representations. It takes at least four bits to
code a decimal digit. Therefore, to store a six-digit coded decimal number
requires 24 bits of memory. However, it takes only 20 bits to store the same
number in binary.
3. VAX minicomputers
use a format for floating-point numbers that is not the same as the IEEE
standard. What is this format, and why was it chosen by the designers of the
VAX computers? A reference for VAX floating –point representations is Sebesta
(1991).
= The existing DEC VAX
formats, inherited from the PDP-11, because the PDP-11 had several uniquely
innovative features, and was easier to program than its predecessors through
the additional general-purpose registers.
4. Compare the
tombstone and lock-and –key methods of avoiding dangling pointers, from the
points of view of safety and implementation cost.
= Tombstones take more
memory, while lock-and-key requires additional cpu time on each pointer
assignment to copy key as well as pointer. Pointer arithmetic could overwrite
key in the heap.
5. What disadvantages
are there in implicit dereferencing of pointers, but only in certain contexts?
For example, consider the implicit dereference of a pointer to a record in Ada
when it is used to reference a record field.
= When implicit
dereferencing of pointers occurs only in certain contexts, it makes the
language slightly less orthogonal. The context of the reference to the pointer
determines its meaning. This detracts from the readability of the language and
makes it slightly more difficult to learn.