Chapter 7 Assignment from Mr. Tri Djoko Wahjono. Ir., M.Sc.



2.     What is a ternary operator?

Answer: operator that has three operands.


3.     What is a prefix operator?

Answer: operator that precedes operands.


5.     What is a non-associative operator?

Answer: A non-associative operator is an operator that should be parenthesized to show the order


9.     What is coercion?

Answer: Coercion is an implicit type conversion that is initiated by the compiler.


14.   What is a mixed-mode expression?

Answer: A mixed-mode expression is one that has operands of different types.


15.   What is referential transparency?

Answer: Any two expressions in the program that have the same value can be substituted for one another anywhere in the program without affecting the action of the program.


16.   What are the advantages of referential transparency?

Answer: The advantage of referential transparency is to apply program transformations, including optimizations and partial evaluations at compile-time.






1. When might you want the compiler to ignore type differences in an expression?



Suppose ‘X’ is a sub range of Integer.  It may be useful for the difference between ‘X’ and Integer to be ignored by the compiler in an expression.


2. State your own arguments for and against allowing mixed-mode arithmetic expressions.




a mixed mode arithmetic expression is needed in calculating expression that might have decimal results. it is compulsory as it allows two different types of number data type such as float and integer to be summed without losing the precision of the float.



while it is compulsory to have mixed-mode expressions, it is more error prone when expressions made are more likely to have non-decimal results. a mixed mode might produce a decimal result even though the result wanted is non-decimal.



4. Would it be a good idea to eliminate all operator precedence rules and require parentheses to show the desired precedence in expressions ? Why and why not ?



No. Because it will affect the readability and writability, and maybe it can make the answer ambiguous.


5. Should C’s assigning operations (for example, +=) be included in other languages (that do not already have them) ? Why or why not ?

No. assigning operations of C should not be included in other languages. Because the assigning operations would be the different part of the code if it is implemented on other code that might cause confusion of the programmer.



7. Describe a situation in which the add operator in a programming language would not be commutative.



It won’t be commutative when it deals with the negative integers.


Chapter 6 Assignment from Mr. Tri Djoko Wahjono. Ir., M.Sc.



1.   What is a descriptor?

      Answer: A descriptor is the collection of the attributes of a variable


3.   What are the design issues for character string types?


-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, limited dynamic length string, and dynamic length string


8.   What are the design issues for arrays?


  -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?


12.  What languages support negative subscripts?

Answer: Ruby and Lua


13. What languages support array slices with stepsizes?

Answer: Python, Perl and Ruby


15. What is an aggregate constant?



Nonscalar constant which value never change or are not changed during execution of the program


18. What is an access function for an array?

Answer: Access function is a function that maps subscript expressions to an address in the array


20. What is the structure of an associative array?



      An associative array is an unordered collection of data elements that are indexed by an equal number of values called keys. User-defined keys must be stored.


21. What is the purpose of level numbers in COBOL records?


    The level numbers in COBOL records are used to establish a hierarchical structure of related records.


24. Are the tuples of Python mutable?

Answer: No


27. What is the action of the Scheme function CAR?

Answer: Returning the first element of its list parameter.


32. What are the design issues for unions?



  – Should type checking be required? Note that any such type checking must be dynamic?

      – Should unions be embedded in records?


35. What are the design issues for pointer types?



      – What are the scope and lifetime of a pointer variable?

      – Are pointers restricted as to the type of value to which they can point?

      – Should the language support pointer types, reference types, or both?


36. What are the two common problems with pointers?



      – May lead to several kinds of programming errors.

      – The problems present in the pointers of subsequent languages.


38. What is a C++ reference type, and what is its common use?



      C++ reference type is a constant pointer that is always implicitly dereferences. Its common use is to provide two-way communication between the caller and the called functions


43. What is a compatible type?



      A compatible type is one that is either legal for the operator or allowed under language rules to be implicitly converted by compiler generated code to a legal type.



47. What is a non-converting cast?



      A non-converting cast is the kind of conversion that no actual conversion takes place, just merely a means of extracting the value of a variable of one type and using it as if it were of a different type.






1. What are the arguments for and against four signed integer sizes in Java?



             Arguments for and against four signed integer sizes are Bytes (1 byte), short (2 bytes), integer (4 bytes), long (8 bytes).



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 pointers determines its meaning. This detracts from the readability of the language and makes it slightly more difficult to learn.



21. In what way is dynamic type checking better than static type checking?

Dynamic type checking is better than static because dynamic checking happens in compile time not in run time, so the correction is earlier and less costly then in static checking which is happens in run time, so the correction is done later.

Chapter 5 Assignment from Mr. Tri Djoko Wahjono. Ir., M.Sc.



 1. What are the design issues for names?




– Are name case sensitive

– Are the special words of the language reserved words or keywords



3. In what way are reserved words better than keyword?




The main way that reserved words are better than keywords is that the meaning for reserved words is static.



4. What is an alias?




Alias is when more than one variable name can be used to access the same memory location



7. Define binding and binding time.




Binding is an association between an attribute and an entity.


Binding time is the time at which a binding takes place.



9. Define static binding and dynamic binding.




A binding is static if it occurs before run time and remains unchanged throughout program execution

A binding is dynamic if it occurs during execution or can change during execution of the program


18. What is a block?




Block is a stack dynamic variables which is allocated when the section is entered and deallocated when the section is exited.







 1. Which of the following identifier forms is most readable? Support your decision.







Sum_of_sales is the most readable. It is because it’s doesn’t have any problem with case sensitive, because the following identifier doesn’t use any caps lock.



4. Dynamic type binding is closely related to implicit heap-dynamic variables. Explain this relationship.




Implicit heap-dynamic variables acquire types only when assigned value, which must be at runtime. Therefore, this variable are always dynamically bound to types.



5. Describe a situation when a history-sensitive variable in a subprogram is useful.




To describe a situation when a history-sensitive variable in a subprogram is useful, suppose that a FORTRAN subroutine is used to implement a data structure as an abstraction. In this situation, it is essential that the structure persists between different calls to the managing subroutine.

Chapter 3 Assignment from Mr. Tri Djoko Wahjono. Ir., M.Sc.

Review Question chapter 3


1. Define syntax and semantics
Answer:    Syntax is a set of rules in programming language which is arranged in a word
or phrases or symbols which are considered to be correctly structured.
Semantics is the meanings of those expression, statements, and program

3. Describe the operation of a general language generator.
Answer:    General language generator is a device that is used to generate the sentences
of the language. This device use to generate unpredictable sentences. People
prefer certain forms of generators over recognizer because they can be more
easily read and understand them.


4. Describe the operation of a general language recognizer.
Answer:    General language recognizer is a recognition device that is capable to read
strings of character. These recognition devices are like filters separating
correct sentences from those that are incorrectly.


5. What is the difference between a sentence and a sentential form?
Answer:    A sentence is a sentential form that has only terminal symbols. A sentential
form is every string of symbols in the derivation.


7. What three extensions are common to most EBNFs?
Answer:    3 extensions that are common to most Extended Backus Naur Form (EBNF) are
first, denotes an optional part of a RHS, which is delimited by brackets.
Second, the use of braces in an RHS to indicate that the enclosed part can be
repeated indefinitely or left out altogether.
Third, multiple choice options.


8. Distinguish between static and dynamic semantics.
Answer:    Static semantics is indirectly related to the meaning of the programs during
execution. Static semantics is used to analysis and check
these specifications can be done at compile time.

Dynamic semantics is describing the meaning of the programs. Programmers
need to know precisely what statements of a language do. Compile writers
determine the semantics of a language for which they are writing compilers
from English descriptions


10. What is the difference between a synthesized and an inherited attribute?
Answer:   The synthesized attributes are the result of the attribute evaluation rules, and
may also use the values of the inherited attributes. The inherited attributes are
passed down from parent nodes. In some approaches, synthesized attributes
are used to pass semantic information up the parse tree, while inherited
attributes help pass semantic information down it.


12. What is the primary use of attribute grammars?
Answer: The primary purpose of an attribute grammar is it allows certain
language rules to be described.


21. What is a predicate transformer function?
Answer:    A function that maps predicates to predicates.


29.  In what fundamental way do operational semantics and denotation semantics differ to?
Answer:           Total correctness and partial correctness.




1. The two mathematical models of language description are generation and recognition. Describe how each can define the syntax of a programming language.

syntax error refers to an error in the syntax of a sequence of which is written in a particular programming language.
Semantic Error: it is a logical error. it is due to wrong logical statements


3. Rewrite the BNF of Example 3.4 to give + precedence over * and force + to be right associative.

<expr>→< term >*< expr >| <term>
<term>→<term>+<factor>| <factor>
<factor>→(<expr>) | <id>


4. Rewrite the BNF of Example 3.4 to add the ++ and — unary operators of Java.


→ <id> = <expr>


→ A | B | C


→ <expr> + <term> class  <Unary – condition- statement>

| (++/–) <term>


→ <factor> + <term>

| <factor>


→ ( <expr> )

| (++/–) <id>

16. Convert the BNF of Example 3.3 to EBNF.

<assign> -> <id> = <expr>

<id> -> A | B | C

<expr> -> <expr> { ( + | * ) <expr> }

| ( <expr> )

| <id>

18. What is the difference between an intrinsic attribute and a non intrinsic synthesized

Answer:  An intrinsic attribute is an inherent characteristic of a terminal symbol in the grammar. So the value of the attribute is determined solely from the terminal symbol. A nonintrinsic synthesized attribute is an attribute of a non-terminal symbol in the grammar.
19.       Write an attribute grammar whose BNF basis is that of Example 3.6 in
            Section 3.4.5 but whose language rules are as follows: Data types cannot be mixed in
            expressions, but assignment statements need not have the same types on both sides of
            the assignment operator.

1) Syntax rule: <assign> → <var> = <expr>

2) Syntax rule: <expr> → <var>[2] + <var>[3]

Predicate: <var>[2].actual_type == <var>[3].actual_type

3) Syntax rule: <expr> → <var>

4) Syntax rule: <var> → A | B | C

Semantic rule: <var>.actual_type ← lookup(<var>.string)

20.       Write an attribute grammar whose base BNF is that of Example 3.2 and
            whose type rules are the same as for the assignment statement example of Section 3.4.5.

1) syntax rule: <assign> → <id> = <expr>

semantic rule: <expr>.expected_type ← <id>.actual_type

predicate: <expr>[1].actual_type == <expr>[1].expected_type

2) syntax rule: <expr>[1] → <id> + <expr>[2]

semantic rule: <expr>[1].actual_type ←

if (<id>.actual_type = int and <expr>[2].actual_type = int)

then int

else float

end if

3) syntax rule: <expr>[1] → <id> * <expr>[2]

semantic rule: <expr>[1].actual_type ←

if (<id>.actual_type = int and <expr>[2].actual_type = int)

then int

else float

end if

4) syntax rule: <expr>[1] → ( <expr>[2] )

semantic rule: <expr>[1].actual_type ← <expr>[2].actual_type

5) syntax rule: <expr> → <id>

semantic rule: <expr>.actual_type ← <id>.actual_type

6) syntax rule: <id> → A | B | C

semantic rule: <id>.actual_type ← lookup(<



21.       Using the virtual machine instructions given in Section, give an
operational semantic definition of the following:

a. java do-while
do {


} while ( expr );

b. ada for

for I in first..last loop
loop: if I<last go out

goto loop
out: …

c. c++ if-then-else


d. c for

evaluate (<expr1>);
loop=control= evaluate(<expr2>)
if control == 0 goto out
evaluate (<expr3>)
goto loop
out: …

e. C switch

switch (condition){
case 1:




26.       Explain the four criteria for proving the correctness of a logical pretest loop construct of
            the form while B do S end.
– Look axiom

– where P is called a loop variant

– finding a loop invariant requires some ingenuity, like when doing a proof by induction

– compute the weakest precondition for S for consecutive iterations.

Chapter 2 Assignment from Mr. Tri Djoko Wahjono. Ir., M.Sc.

Review Question

1. In what year was Plankalkül designed? In what year was that design published?
Answer: Plankalkül designed in 1945 and published in 1972.

2. What two common data structures were included in Plankalkül?
Answer: array data structure and record data structure

3. How were the pseudocodes of the early 1950s implemented?
Answer: Implemented by a pure interpreter.

7.   In what year was the Fortran design project begun?
      Answer: In 1954

8.   What was the primary application area of computers at the time Fortran was designed?

      Answer: Mathematic application area.

9.   What was the source of all of the control flow statements of Fortran I?

      Answer: 704 Instructions.

12. Which version of Fortran was the first to have any sort of dynamic variables?

      Answer: Fortran99.

13. Which version of Fortran was the first to have character string handling?

      Answer: Fortran77.

15. Where was LISP developed? By whom?

      Answer: John McCarthy of MIT.

17. What dialect of LISP is used for introductory programming courses at some universities?

      Answer: Scheme.

18. What two professional organizations together designed ALGOL 60?

      Answer: ACM and GAMM.

19. In what version of ALGOL did block structure appear?

      Answer:  ALGOL60.

20. What missing language element of ALGOL 60 damaged its chances for widespread use?

      Answer: The lack of input and output statements.

21. What language was designed to describe the syntax of ALGOL 60?

      Answer: BNF language

22. On what language was COBOL based?

      Answer: FLOW-MATIC language

23. In what year did the COBOL design process begin?

      Answer: 1959

25. What organization was most responsible for the early success of COBOL (in terms of extent of

      Answer: DoD (Department of Defense)

30. What features of SIMULA 67 are now important parts of some object oriented

      Answer: Data abstraction

32. What design criterion was used extensively in ALGOL 68?

      Answer: Orthogonality

37. What are the two kinds of statements that populate a Prolog database?

      Answer: Facts and rules

42. What three concepts are the basis for object-oriented programming?

      Answer: Classes, objects, and methods

50. What characteristic of Java is most evident in JavaScript?

      Answer: Similar syntax

65. What are the inputs to an XSLT processor?

      Answer: An XML data document and an XSLT data document



Problem Set


1. What features of Plankalkül do you think would have had the greatest influence on Fortran 0 if the Fortran designers had been familiar with Plankalkül?

Answer: The loop feature control statement and the selection (if/else) statement


5. Which of the three original goals of the ALGOL design committee, in your opinion, was most difficult to achieve at that time?

Answer: “the new language must be mechanically translatable into machine language”.
It would be impossible for the system to determine what instructions were being requested since computers can’t guess in that capacity.


7. LISP began as a pure functional language but gradually acquired more and more imperative features. Why?

Answer: In developing LISP for artificial intelligence as a functional programming language, but there soon emerged different dialects, cleaners, more modern, and more imperative, that began to deviate from the functional form into Scheme. COMMON LISP combined the different forms into a single form that was more imperative, including assignment and iteration.


8. Describe in detail the three most important reasons, in your opinion, why ALGOL 60 did not become a very widely used language.

Answer: Excessive flexibility hurt ALGOL60 since languages that are difficult to learn were not as well received as languages with a more rigid structure. Then the most important reason that ALGOL60 was not very widely used was because of a lack of support from IBM, who was at the time the preeminent company for using computer languages. Without some help from a large corporation, ALGOL60 did not have much of a chance, much like COBOL without the DoD.


9. Why, in your opinion, did COBOL allow long identifiers when FORTRAN and ALGOL did not?

Answer: COBOL required that managers without a background in programming should be able to read programs. This caused identifiers to be longer, making the language more English-like.


13. Describe, in your own words, the concept of orthogonality in programming language design.

Answer: It appears that orthogonality means the simplicity of programming constructs, or a minimal number of control and data structures in a language. Each additional construct increases the complexity, removing orthogonality.


14. What are the arguments both for and against the idea of a typeless language?

            Answer: Arguments for are obvious flexibility and ease of use. Without having to define a data type the programmer is free to develop code that is generated quickly and without much thought. Learning the language is much simpler because one doesn’t have to determine size or how the compiler will interpret the type later on, only what information must be included.

Arguments against include data insecurity, such as the assignment of a character type ‘A’ that could in fact be “defined” as a HEX value by the programmer. The compiler would also have trouble interpreting floating point values compared to integers. The resulting arithmetic would also cause serious problems; like adding 5 + “happy” and how they are interpreted different than perhaps the programmer intended.

Chapter 1 Assignment from Mr. Tri Djoko Wahjono. Ir., M.Sc.

Review Question


3.   What programming language has dominated scientific computing over the past 50

      Answer:     Programming language that dominated scientific computing over the past 50
                        years is FORTRAN. (Source:

4.   What programming language has dominated business applications over the past 50

      Answer:     Programming language that dominated business computing over the past 50
                        years is COBOL. (Source:

 5.   What programming language has dominated artificial intelligence applications over the
       past 50 years?

      Answer:     Programming language that dominated business computing over the past 50    
                       years is LISP.



6.   In what language is most of UNIX written?

      Answer: UNIX is most written in C language.


9.   What is one example of a lack of orthogonality in the design of C?

Answer:     Using pointer in C programming. It should be possible to define a pointer to
point to any specific type defined in the C language. However, if pointers are not allowed to point to arrays, many potentially useful user-defined data structures cannot be defined.


10. What language used orthogonality as a primary design criterion?

      Answer:     C++ is the language that used orthogonality as a primary design criterion.


13. What does it mean for a program to be reliable?

Answer:     A program is said to be reliable if it performs to its specifications under all


15. What is aliasing?

      Answer:     Aliasing is having two or more distinct names that can be used to access the
                        same memory cell.


16. What is exception handling?

      Answer:     The ability of a program to intercept run-time errors.


28. What does a linker do?

      Answer:     collecting system programs and linking them to user program which usually
                        called linking and loading.

Problem Set


  1. Do you believe our capacity for abstract thought is influenced by our language skills? Support your opinion.

Answer:     Yes, I absolutely agree with that. How well we implementing language skills are depends on how well does our logic.

4.   What arguments can you make against the idea of a single language for all     
      programming domains?

      Answer:     There are 3 programming domains (scientific, business, artificial intelligence)
that absolutely have different requirements. All of those differences couldn’t group in a single language based on their requirements, purpose, and complexity.

6.   What common programming language statement, in your opinion, is most detrimental to

      Answer:     poorly written, unordered, and undocumented programming language is the
                  most commonly problem that another person will hard to follow and read.

8.   Many languages distinguish between uppercase and lowercase letters in user-defined
     names. What are the pros and cons of this design decision?

      Answer:    (Pros) the distinguished between uppercase and lowercase can effect for the
                  quantity of the variable in the programming language. For example, ‘A’ and ‘a’
                  are the different variable and it has 2 variables.

                  (Cons) the distinguished between uppercase and lowercase can affect the
                  programmer or even another user. Because it’s make a confusion between

9.   Explain the different aspects of the cost of a programming language.

      Answer:There are 2 aspects of the cost of a programming language. Such as, first, the
                  cost of testing/running the program. Second, the cost of maintaining and
                  documenting the program.

12. In your opinion, what major features would a perfect programming language include?

      Answer:     In my opinion Syntax, documentation, and error message are the most
important features in a perfect programming language.