Concept of Programming Language Chapter 7

Name: William Gunawan

NIM: 1601211306

Instructor: Tri Djoko Wahjono

REVIEW QUESTIONS

1. Define operator precedence and operator associativity.
The operator precedence rules for expression evaluation partially define
the order in which the operators of different precedence levels are evaluated.
An operator can have
either left or right associativity, meaning that when there are two adjacent
operators with the same precedence, the left operator is evaluated first or the
right operator is evaluated first, respectively.

2. What is a ternary operator?
ternary, meaning it has three operands.

3. What is a prefix operator?
prefix, which means they precede their operands.

6. What associativity rules are used by APL?
the order of evaluation of operators in APL expressions is
determined entirely by the associativity rule, which is right to left for all operators.

8. Define functional side effect.
occurs when
the function changes either one of its parameters or a global variable.

10. What is a conditional expression?
if-then-else statements can be used to perform a conditional expression
assignment.

11. What is an overloaded operator?
This multiple
use of an operator is called operator overloading and is generally thought to
be acceptable, as long as neither readability nor reliability suffers.

Continue reading

Concept of Programming Language Chapter 6

Name: William Gunawan

NIM: 1601211306

Instructor: Tri Djoko Wahjono

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.

3. What are the design issues for character string types?
The two most important design issues that are specific to character string types are the following:
– Should strings be simply a special kind of character array or a primitive type?
– Should strings have static or dynamic length?

4. Describe the three string length options.
-static length string: the length can be static and set when the string is created.
-limited dynamic length strings: to allow strings to have varying length up to a
declared and fixed maximum set by the variable’s definition.
-dynamic length strings: to allow strings to have varying length with no maximum,
as in JavaScript, Perl, and the standard C++ library.

5. Define ordinal, enumeration, and subrange types.
-An ordinal type is one in which the range of possible values can be easily
associated with the set of positive integers.
-An enumeration type is one in which all of the possible values, which are
named constants, are provided, or enumerated, in the definition.
-A subrange type is a contiguous subsequence of an ordinal type.

8. What are the desgin issues for arrays?
The primary design issues specific to arrays are the following:
• What types are legal for subscripts?
• Are subscripting expressions in element references range checked?
• When are subscript ranges bound?
• When does array allocation take place?
• Are ragged or rectangular multidimensioned arrays allowed, or both?
• Can arrays be initialized when they have their storage allocated?
• What kinds of slices are allowed, if any?

17. Define row major order and column major order.
-In row major order, the
elements of the array that have as their first subscript the lower bound value of
that subscript are stored first, followed by the elements of the second value of
the first subscript, and so forth.
-In column major order, the elements of an array that have as their last subscript
the lower bound value of that subscript are stored first, followed by the
elements of the second value of the last subscript, and so forth.

18. What is an access function for an array?
The access function for a multidimensional array is the mapping of its
base address and a set of index values to the address in memory of the element
specified by the index values.

20. What is the structure of an associative array?
In an
associative array, however, the user-defined keys must be stored in the structure.
So each element of an associative array is in fact a pair of entities, a key and a
value.

31. Define union, free union, and discriminated union.
-A union is a type whose variables may store different type values at different
times during program execution.
-free unions, because programmers
are allowed complete freedom from type checking in their use.
-discriminated union: Type checking of unions requires that each union construct include a type
indicator.

43. What is a compatible type?
A compatible type is one that either is legal for
the operator or is allowed under language rules to be implicitly converted by
compiler-generated code (or the interpreter) to a legal type.

44. Define type error.
A type error is the application of an operator to an operand of an inappropriate
type.

47. What is a nonconverting cast?
No actual
conversion takes place; it is merely a means of extracting the value of a variable of one type and using it as if it were of a different type.

48. What languages have no type coercions?
ML and F#.

Continue reading

Concepts of Programming Language Chapter 5

Name: William Gunawan

NIM: 1601211306

Instructor: Tri Djoko Wahjono

REVIEW QUESTIONS

7. Define binding and binding time.
A binding is an association between an attribute and an entity, such as
between a variable and its type or value, or between an operation and a symbol.
The time at which a binding takes place is called binding time.

10. What are the advantages and disadvantages of implicit declarations?
implicit declarations
can be detrimental to reliability because they prevent the compilation
process from detecting some typographical and programmer errors.

11. What are the advantages and disadvantages of dynamic type binding?
The primary advantage of
dynamic binding of variables to types is that it provides more programming
flexibility.

The disadvantage is it causes
programs to be less reliable, because the error-detection capability of the
compiler is diminished relative to a compiler for a language with static type
bindings.

13. Define lifetime, scope, static scope, and  dynamic scope.

-Lifetime is the time during which the variable is bound to a specific memory location.
-Scope is the range of statements in which the variable is visible.
-Static scope is the scope of variable that can be statically determined inside subprograms and prior to execution.
-Dynamic scope is the scope that is based of calling sequence of subprograms, not on their spatial relationship to each other and can be determined only at run time.

18. What is a block?
Block is a section of a code.

22. What are the advantages and disadvantages of dynamic scoping?
during the time span beginning when a subprogram begins its execution
and ending when that execution ends, the local variables of the subprogram
are all visible to any other executing subprogram, regardless of its textual
proximity or how execution got to the currently executing subprogram.

Dynamic scoping is based on the calling sequence of subprograms, not
on their spatial relationship to each other.

Continue reading

Concepts of Programming Language Chapter 4

Name: William Gunawan

NIM: 1601211306

Instructor: Tri Djoko Wahjono

REVIEW QUESTIONS

2. Explain the three reasons why lexical analysis is separated from syntax
analysis.

1. Simplicity—Techniques for lexical analysis are less complex than those
required for syntax analysis, so the lexical-analysis process can be simpler
if it is separate. Also, removing the low-level details of lexical analysis
from the syntax analyzer makes the syntax analyzer both smaller and
less complex.
2. Efficiency—Although it pays to optimize the lexical analyzer, because
lexical analysis requires a significant portion of total compilation time,
it is not fruitful to optimize the syntax analyzer. Separation facilitates
this selective optimization.
3. Portability—Because the lexical analyzer reads input program files
and often includes buffering of that input, it is somewhat platform
dependent. However, the syntax analyzer can be platform independent.
It is always good to isolate machine-dependent parts of any software
system.

3. Define lexeme and token.
– Lexeme is an abstract unit of morphological analysis in linguistics, that roughly corresponds to a set of forms taken by a single word.
– Token is the the internal codes for categories.

6. What is a state transition diagram?
A directed graph.

8. What are the two distinct goals of syntax analysis?
-checking the input program to determine whether it is syntactically correct
-producing a complete parse tree.

9. Describe the differences between top-down and bottom-up parsers.
top-down, in which the tree is built
from the root downward to the leaves, and bottom-up, in which the parse tree
is built from the leaves upward to the root.

18. What is left factoring?
Left factoring is the action taken when a grammar leads backtracking while making parsing/syntax tree.

23. Describe three advantages of LR parsers.
– LR parsers can be constructed to recognize virtually all programming-language constructs for which context-free grammars can be written.

– The LR parsing method is the most general non-backtracking shift-reduce parsing method known, yet it can be implemented as efficiently as other shift-reduce methods.

– The class of grammars that can be parsed using LR methods is a proper subset of the class of grammars that can be parsed with predictive parsers.

Continue reading

Concepts of Programming Language Chapter 3

Name: William Gunawan

NIM: 1601211306

Instructor: Tri Djoko Wahjono

REVIEW QUESTIONS

1. Define syntax and semantics.
– syntax of a programming language is the form of its expressions, statements, and program
units.
– semantics is the meaning of those expressions, statements, and program units.

2. Who are language descriptions for?
Language descriptions is for programming language implementors.

5. What is the difference between a sentence and a sentential form?
– A sentence is a language, whether natural (such as English) or artificial (such as Java), is a set
of strings of characters from some alphabet.
– A sentential form is an each successive string in the
sequence is derived from the previous string by replacing one of the nonterminals
with one of that nonterminal’s definitions.

6. Define a left-recursive grammar rule.
When a grammar rule has its LHS also appearing at the beginning of its
RHS, the rule is said to be left recursive. This left recursion specifies left
associativity.

7. What three extensions are common to most EBNFs?
– the denotes an optional part of an RHS, which is delimited by
brackets.
– the use of braces in an RHS to indicate that the
enclosed part can be repeated indefinitely or left out altogether.
– deals with multiple-choice options.

8. Distinguish between static and dynamic semantics.
– The static semantics of a language is only indirectly
related to the meaning of programs during execution; rather, it has to do
with the legal forms of programs.
– no universally accepted notation or approach has been devised for dynamic semantics.

10. What is the difference between a synthesized and an inherited attribute?
Synthesized attributes are used to pass semantic information up a parse tree, while inherited attributes
pass semantic information down and across a tree.

12. What is the primary use of attribute grammars?
To describe both the syntax and the static semantics of programs.

15. Describe the two levels of uses of operational semantics.
At the highest level, the interest is in the final result of the execution of a complete program.
This is sometimes called natural operational semantics.
At the lowest level, operational semantics can be used to determine the precise meaning of a program
through an examination of the complete sequence of state changes that
occur when the program is executed.

18. Which semantics approach is most widely known?
Denotational semantics is the most rigorous and most widely known formal
method for describing the meaning of programs. It is solidly based on recursive
function theory.

Continue reading