KBP Chapter 7

Dear Mr. TriDjoko Wahjono

 

Review questions
 1. Define operator precedence and operator associativity.
Operator precedence is a rule used to clarify which procedures should be performed first in a given mathematical expression.
 2.    What is a ternary operator?
A ternary operator is an operator with three operands.
 
 3.    What is a prefix operator?

 A prefix operator is an operator that precede their operands

 
 9.    What is a coercion?
A coercion is the implicit type convertion.
 
10. What is a conditional expression?
Conditional expression is a statement that uses if-then-else statements.
 
11. What is an overloaded operator?
 An overloaded operator is the multiple uses of an operator.
 
15. What is referential transparency?
Referential transparency is 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.
 
28. What is a cast?
A cast is an operator to convert a data type into another data types.
 
 
Problem Set
 
 3.    Do you think the elimination of overloaded operators in your favorite language would be beneficial? Why or why not?
I think it is not beneficial because it can be ambigious if we want to use that operator with the same type.
 
 
5.    Should C’s assigning operations (for example, +=) be included in other languages (that do not already have them)? Why or why not?
Yes, because we can make the operator simpler than before. We can just write a+=b instead a=a+b.
 
20.  Consider the following C program:
             int fun(int *i) {
                    *i += 5;
                      return 4;
              }
             void main() {
                      int x = 3;
                      x = x + fun(&x);
               }
 
What is the value of x after the assignment statement in main, assuming
a. operands are evaluated left to right.
b. operands are evaluated right to left.
 
a. 12
b. 7
 
21. Why does Java specify that operands in expressions are all evaluated in left-to-right order?
Java specify that operands in expressions are all evaluated in left-to-right order because Java is an associative language because associative in common language is evaluated from left to right.

KBP Chapter 6

Dear Mr. TriDjoko Wahjono

Review Question
1. What is a descriptor ?
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 ? and Should strings have static or dynamic length ?

4. Describe the three string length options.
The length can be static and set when the string is created, allow strings to have varying length up to a declared and fixed maximum set by the variable’s definition. And allow strings to have varying length with no maximum.

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

6. What are the advantages of user-defined enumeration types ?
Improved writability and readibility, No arithmetic operations are legal on enum types and no enumeration types can be assigned values outside its defined range.

8. What are the design issues for arrays ?
-What types are legal for subscripts ?
-Are subscripting expressions in element references range checked ?
– When are subscripts ranges bound ?
– When does array allocation take place ?
– Are ragged or rectangular multidimensional arrays allowed, or both ?
– Can arrays be initialized when they have their storage allocated ?
– What kinds of slices are allowed, if any ?

10. What happens when an nonexistent element of an array is referenced in Perl ?
No error will be reported

11. How does JavaScript support sparse arrays ?
The value of subscripts need not to be contiguous

12. What languages support negative subscripts ?
Ruby and Lua

13. What languages support array slices with stepsizes ?
Python,Perl and Ruby

14. What array initialization feature is available in Ada that is not available in other common imperative languages ?
Listing arrays in order in which they are to be stored or direcly assigning them to an index position using the => operator

15. What is an aggregate constant ?
Nonscalar constant which value never change or are not changed during execution of the program

16. What array operations are provided specifically for single-dimensioned arrays in Ada ?
Ada allows array assignments, including those where the right side is an aggregate value rather than an array name. Ada also provides catenation, which is defined between two single-dimensioned arrays and between a single-dimensioned array and a scalar. Nearly all types in Ada have built-in relational operators for equality and inequality.

17. Define row major order and column major order.
Row major order is where elements of the array that have as their first subscript the lower bound value of the subscript are stored first.
Column major order has elements of an array that have as their last subscript the lower bound value of that subscript are stored first.

18. What is an access function for an array ?
For multidimensional array : the mapping of its base address and a set of index values to the address in memory of the element specified by index values.
For two-dimensional array : the address of an element is the base address of the structure plus the element size times the number of elements that precede it in the structure.

21. What is the purpose of level numbers in COBOL records ?
It represents relation between groupd and elementary items in COBOL

22. Define fully qualified and elliptical references to field in records.
A fully qualified reference is one in which all intermediate record names, from the largest enclosing record to the specific field are named in reference.
Elliptical reference has the field named, but any or all of the enclosing record names can be omitted, as long as the resulting reference is unambiguous in the referencing environment.

24. Are the tuples of Python mutable ?
No. They are not.

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

45. Define strongly typed.
Characteristic of programming language where the typing errors are always detected

Problem Set
2. How are negative integers stored in memory ?
It uses most-significant-bit (the leftmost number). The “sign bit”. If it is 1, the number is negative. Vice versa.

6. Compare the use of Boolean data types in C++ and Java. Give emphasis on their use in conditional statements and conditional loops.
The use of boolean in C++ and Java is almost the same. Boolean is a variable which has only 2 values : true and false. The only difference would be the primitive in C++ is bool while Java uses Boolean. On their use of conditional statements, they determine whether a loop or conditional statement is executed. The difference is that Boolean in Java does not accept integers as true / false value. They only accept the value either “true” or “false”. While in C++, it is possible to assign 1 as the value of a boolean which means true and 0 as false.

17. What kind of conversion is called a nonconverting cast ? explain with an example in Ada language .
Nonconverting cast is a conversion which happen between types of the same storage size.
Example :
generic
type Source (<>) is limited private;
type Target (<>) is limited private;
function Ada.Unchecked_Conversion (S : Source) return Target;

21. In what way is dynamic type checking better than static type checking ?
Dynamic type checking allows the programmer to be more flexible. Because the dynamic checking is happening on compile time, not run time. And earlier correction is less costly.
Than later correction in case of static type checking usage, which runs on runtime of the application.

KBP Chapter 5

Dear Mr TriDjoko Wahjono

 

Review Questions
1. What are the design issues for names ?
Are names case sensitive ? and Are the special words of the language reserved words or keywords ?

2. What is the potential danger of case-sensitive names ?
Because case sensitivity violates the design principle that language constructs that look similar should have similar meanings

4. What is an alias ?
Alias is more than one variable name that accesses the same memory location

7. Define binding and binding time.
Binding is association between an attribute and an entity, such as variable and its value or between operation and symbol.
Binding time is the time at which a binding takes time

8. After language design and implementation [what are the four times bindings can take place in a program ? ]
Compile time, load time , link time and run time

9. Define static binding and dynamic binding
Static binding is done at compile time when a function is called in order to match it with the definition, while Dynamic binding is at run time where we can specify that the compiler matches a function call with the correct function definition at run time.

18. What is a block ?
A block is a section of code that has its own local variable whose scope is minimized. The variables are typically stack dynamic, so their storage is allocated when the section is entered and deallocated when the section is exited.

19. What is the purpose of the let constructs in functional languages ?
A let construct is a call to the function LET.

Problem Set
1. Decide which of the following identifier names is valid in C language. Support your decision.
_Student = valid, it starts with an underline and it is allowed.
Int = invalid. It is a reserved name for integer data type.
Student = valid. It uses capital letter which is allowed.
123Student=invalid. Variable names in C cannot be started with numbers. 
Student123=valid. Variable in C can contain numbers as long it is not on the front.

2.What is l-value ? Write a statement in C language which gives the compile time error “l-value required”
L-value is memory address that are programmatically accessible to the running program.
printf(“%s\n”,*words++);

4.Why is the type declaration of a variable necessary ? What is the value range of the int type variable in Java ?
Because it associates a type and an identifier / name with the variable. Tyhe type allows the compiler to interpret statements correctly. For example, instruction in the CPU for adding two integers is different from the instruction of adding two float values. Hence, the compiler must know the type of the variables so it can generate the correct add instructions.The range of Java Int is -2,147,483,648 to 2,147,483,647

KBP Chapter 4

Dear Mr TriDjoko Wahjono

 

Review Questions
1.What are three reasons why syntax analyzers are based on grammars ?
-BNF descriptions of the syntax of programs are clear and concise, both for humans and for software systems that use them.
– BNF description can be used as the direct basis for the syntax analyzer.
– Implementations based on BNF are relatively easy to maintain because of their modularity

3. Define lexeme and token.
Lexeme is logical grouping that consists of collection of characters collected by lexical analyzer.   Token is internal code for categories of the lexeme

4. What are the primary tasks of a lexical analyzer ?
It serves as front end of a syntax analyzer.

6. What is a state transition diagram ?
State diagram is a directed graph whose nodes are labeled with state names.

8. What are the two distinct goals of syntax analysis ?
First, syntax analyzer must check the input program to determine whether it is syntactically correct. The second goal is to produce a complete parse tree, or at least trace the structure of the complete parse tree, for syntactically correct input.

9. Describe the differences between top-down and bottom-up parsers.
A top down parser builds from root downward to leaves, while bottom up parser builds from the leaves upward to the root

17. Describe the pairwise disjointness test.
It is a test of non-left recursive grammar that indicates whether left recursion can be done. It requires the ability to compute a set based on the RHSs of a given nonterminal symbol in a grammar.

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

19. What is a phrase of a sentential form ?
A phrase is a subsequence of a sentential form that is eventually reduced to a single non-terminal

Problem Set

1. Perform the pairwise disjointness test for the following grammar rules.
A->aB|b|cBB
FIRST(aB)=a
FIRST(b)=b
FIRST(cBB)=c
They don’t intersect and pass the test

B-> aB|bA|aBb
FIRST(aB)=a
FIRST(bA)=b
FIRST(aBb)=a
They intersect and fail the test

C->aaA|b|caB
FIRST(aaA)=a
FIRST(b)=b
FIRST(caB)=c
They don’t intersect and pass the test

2.Perform the pairwise disjointness test for the following grammar rules.
S->aSb|bAA
FIRST(aSb)=a
FIRST(bAA)=b
They don’t intersect and pass the test

A->b{aB} | a
FIRST(b{aB}) = b
FIRST (a) = a
They don’t intersect and pass the test

B->aB | a
FIRST(aB)=a
FIRST(a) = a
They intersect and do not pass the test

4. Show a trace of the recursive descent parser given in Section 4.4.1 for the string a * (b + c)
call lex      // return a
            enter <expr>
            enter <term>
            enter <factor>
          call lex      // return *
            exit <factor>
          call lex      // return (
            enter <factor>
          call lex      // return b
            enter <expr>
            enter <term>
            enter <factor>
          call lex      // return +
            exit <factor>
            exit <term>
          call lex      // return c
            enter <term>
            enter <factor>
          call lex      // return )
            exit <factor>
            exit <term>
            exit <expr>
          call lex      // return EOF
            exit <factor>
            exit <term>
            exit <expr>

5. Given the following grammar and the right sentential form, draw a parse tree and show the phrases and simple phrases, as well as the handle.
S – > aAb | bBA A-> ab|aAB B->aB|b
A)aaAbb
parse tree = 
                     S
                  / | \
                 a  A  b
                    /|\
                  a A B
                         |
                         b
Handles = b, aAB
Phrases = aaAbb, aaABb, aAb
Simple Phrase = b

B)bBab
parse tree = 
              S
          /   |  \
         b  B  A
                 / \
                 a b 
Handles = ab
Phrases = bBab, bBA
Simple phrase = ab

C)aaAbBb = aSBb = aSBB = x
therefore the last string cannot be derived from given grammar

KBP Chapter 3

Dear Mr TriDjoko Wahjono

Review Question

1. Define syntax and semantics.
Syntax : The form of its expressions, statements, and program units.
Semantics : The meaning of those expressions, statements, and program units.

5. What is the difference between a sentence and a sentential form?
Sentence : The strings of a language.
sentential : Each of the strings in the derivation, including .

7. What three extensions are common to mose EBNFs?
C if-else statement.
The use of braces in an RHS to indicate that the enclosed part can be repeated indefinitely or left out altogether.
The third common extension deals with multiple-choice options.

8. Distinguish between static and dynamic semantics.
Static semantics is more on the legal forms of programs (syntax rather symantics) and is only indirectly related to the meaning of the programs during execution. Static semantics is so named because the analysis required to check these specifications can be done at compile time. In many cases, the semantic rules of language state its type constraints.

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 synthesized and an inherited attribute?
Synthesized attributes are used to pass semantic information up a parse tree. Inherited attributes pass semantic information down and across a tree.

12. What is the primary use of attribute grammars?
An attribute grammar is a device used to describe more of the structure of a programming language that can be described with a context-free grammar. An attribute grammar is an extension to a context-free grammar.

14. Why can machine languages not be used to define statements in operational semantics?
Machine language can’t be used to define statements in operational semantics because the individual steps in the execution of machine language and the resulting changes to the state of machine are too small and too numerous.

Problem Set

1. Syntax error and semantic error are two types of compilation error. Explain the difference between the two in a program with examples.
syntax error : if (a==1) b=2
–>syntax error : there’s no semicolon (;) at the end of the statement

semantic error : for (int i=0;isemantic error : basically a logical error

15. Convert the BNF of Example 3.1 to EBNF.
-> begin {stmt} end
-> =
-> A | B | C
-> [ ( + | – ) ]

16. Convert the BNF of Example 3.3 to EBNF.
-> =
-> A | B | C
-> { ( + | * ) }
| ( )
|

17. Convert the following EBNF to BNF:
S -> A{bA}
A -> a[b]A

-> | b
-> a | ab

18. What is a fully attributed parse tree?
– a parse tree with all attribute values computed
– conceptually attribute values are computed after
parse tree is constructed by compiler
–  not really the way it’s done.

KBP Chapter 2

Evolution of the Major Programming Languages

Chapter 2
For my lecture Tri Djoko Wahjono

Review Questions

1. In what year was Plankalkul designed? in what year was that design published?

Plankalkul is a computer language designed for engineering purporses by Konrad Zuse in 1945. It was published in year 1972.

2. Mention an intereseting feature of Zuse’s programs.

One of the interesting feature of Zuse’s programs is the inclusion of mathematical expressions showing the current relationships between program variables.

3. What does Plankalkul mean?

Plankalkul means program calculus.

4. Speedcoding was invented to overcome two significant shortcomings of the computer hardware of the early 1950s. What were they ?

The first hardware shortcoming was the lack of floating point hardware. The second was the lack was automatic incrementing address registers.

5. What is the number of bits in a single word of the UNIVAC I’s memory? How are the bits grouped?

The number of bits is 72. It is grouped into 12 parts which contains 6 bit bytes each.

6. What hardware capability that first appeared in the IBM 704 computer strongly affected the evolution of programming languages ? Explain why.

Its capabilities prompted the development of Fortran because it was able to support floating-point operations hardware.

7. Who developed the Speedcoding system for the IBM 701 ?

The speedcoding was developed by John Backus.

8. Who developed Short Code? Why is Short Code called automatic programming?

The shortcode was developed by John Mauchly in 1949. Short Code is called automatic programming because Short Code was not
translated to machine code, it was implemented with a pure interpreter.

10. What was the most significant feature added to Fortran I to get Fortran II?

Independent-compilation capability

11. What control flow statements were added to Fortran IV to get Fortran 77?

logical loop statements and IF with an optional ELSE

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

Fortran 90

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

Fortran 77

14. Why were linguists interested in artificial intelligence in the late 1950s?

Linguists were concerned with natural language processing.

15. What are the different data types and structures in Common LISP?

Common LISP has a large number of data types and structures, including records, arrays, complex number, and character strings. It also has a form of packages for modularizing collection of function and data providing access control.

16. In what way are scheme and Common LISP opposites of each other?

Common LISP allows for static scoping and dynamic scoping Scheme only uses static scoping. Scheme is relatively small while Common LISP is large and complex.

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

Scheme

18. What two professional organizations together designed ALGOL 60?

ACM and GAMM

19. What was the goal for developing C?

C has adequate control statements and data-sructuring facilities to allow its use in many application areas. It alse has a rich set of operators that provide a high degree of expressiveness.

20. What were the significant modifications to ALGOL 58 to produce ALGOL 60?

The concept of block structure was introduced, two different means of passing parameters to subprograms were allowed, procedures were allowed to be recursive, stack-dynamic arrays were allowed.

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

BNF

22. On what language was COBOL based?

FLOW-MATIC

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

1959

24. What data structure that appeared in COBOL originated with Plankalkul?

Hierarchical data structures (records)

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

Department of Defense (DoD)

27. Why was BASIC an important language in the early 1980s?

Its smaller dialects could be implemented on computers with very small memories

28. PL/I was designed to replace what two languages?

COBOL and Fortran

29. For what new line of computers was PL/I designed?

the IBM system/360 line of computers

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

Data abstraction

31. What innovation of data structuring was introduced in ALGOL 68 but is often credited to Pascal?

User-defined data types

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

Orthogonality

33. What language introduced the case statement?

The case statement was introduced in ALGOL-W, a version of ALGOL 60 created by Niklaus Wirth and C. A. R. (Tony) Hoare.

34. What operators in C were modeled on similar operators in ALGOL 68?

for and switch statements, in its assigning operators, and in its treatment of pointer

35. What are two characteristics of C that make it less safe than Pascal?

Lack of complete type checking and flexibility

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

The statements that populate a Prolog database are called facts and rules.

38. What is the primary application area for which Ada was designed?

Embedded systems

39. What are the concurrent program units of ada called?

tasks (using the rendezvous mechanism)

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

Classes, objects and methods

 

Problem Set
1. What features of Fortran IV do you think would have had the greatest influence on Javaif the Java designers had been familiar with Fortran?
 Logical data type – boolean, used mainly for the control expressions of itscontrol statements (such as if and while)
 
2. Which of the three original goals of the ALGOL design committee, in your opinion, wasmost difficult to achieve at that time?
 The first requirement, “as close as possible to standard mathematical notation,and …should be readable with little further explanation” appear to be the directionprogramminglanguages were heading, especially with scientists andmathematicians leading the way and scientific programming was a primary focus of computing.
 Without implementing the last requirement, “…the new language must bemechanically translatable into machine language,” it would be impossible for the system IO to determine what instructions were being requested since computerscan’t guess in that capacity.
Developing a language that mimicked pseudocode or symbolic description for thepurpose of publication was definitely be the most difficult challenge of the three atthat time.
 
3.LISP began as a pure functional language but gradually acquired more and moreimperative features. Why?
John McCarthy’s original interest in developing LISP was to meet the demand forartificial intelligence as a functional programming language, but there soonemerged different dialects, cleaners, more modern, and more imperative, thatbegan to deviate from the functional form into Scheme. COMMON LISP combinedthe different forms into a single form that was more imperative, includingassignment and iteration.
 
4. Describe in detail the two most important reasons, in your opinion, why Speedcodingdid not become a very widely used language.
 Slow, compared with other common used languages
 Only 700 words provided for user program
 
5. Outline the major development in ALGOL 60.
 The concept of block structure was introduced
 Two different means of passing parameters to subprograms were allowed: pass byvalue and pass by name.
 Procedures were allowed to be recursive
 Stack-dynamic arrays were allowed.
 Input and output statements with formatting.
 
6. What is the primary reason why C became more widely used than Fortran?
C is closer to assembly language, so you can have finer control over what thecomputer is doing, and thereby make faster programs.
 
7. What are the arguments both for and against the idea of a typeless language?Arguments for are obvious flexibility and ease of use. Without having to define adata type the programmer is free to develop code that is generated quickly andwithout much thought. Learning the language is much simpler because one doesn’thave to determine size or how the compiler will interpret the type later on, onlywhat information must be included.
Arguments against include data insecurity, such as the assignment of a charactertype ‘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 tointegers. The resulting arithmetic would also cause serious problems; like adding 5+ “happy” and how they are interpreted different than perhaps the programmerintended.
 
8.Give a brief general description of the Java servlet.
A servlet is a Java programming language class used to extend the capabilities of aserver. Although servlets can respond to any types of requests, they are commonlyused to extend the applications hosted by web servers, so they can be thought ofas Java Appletsthat run onserversinstead of inweb browsers. These kinds ofservlets are theJavacounterpart to non-Java dynamic Web content technologiessuch as PHP and ASP.NET.

KBP Chapter 1

Concepts of Programming Languages 10th edition
Chapter 1

Dear Mr.TriDjoko Wahjono

Review Questions :
1. Increased capacity to express ideas, Improved background for choosing appropriate languages, Increased ability to learn new languages, Better understanding of the significance of implementation, Better use of languages that are already known, Overall advancement of computing.
2. It makes learning a new language easier, make a newly written program language easier to be learnt by new user, and get more people involved in on a global scale which would actually benefit the entire computing community.
3. Language that has dominated scientific computing over pas 50 years is Fortran.
4. Language that has dominated business applications over pas 50 years is Cobol.
5. Language that has dominated artificial intelligence over pas 50 years is LISP.
6. Most UNIX is written in C language.
7. If there are too many features then the basic simplicity of reading a program could be lost. The simpler and more user-friendly programming languages allow for a smoother creation process, especially if there are many people working on the same code.
8. Because the build in operator has the precision and the compiler knows all the precision the operators, and it works on that precision. But if user create his/her own operator, the compiler doesn’t know how to make precision of this operator.
9. C has 2 structured data types (arrays and structs). Arrays can be returned from functions, but structs can’t.
10. Algol 68 is using orthogonality as a primary design criterion.
11. The selection statement plus GOTO is used to build more complicated control statement such as FOR loop.
12. Sub-programs.
13. A program is said to be reliable if it performs to its specifications under all conditions.
14. Because it can lead to lots of hard-to-debug errors.
15. Aliasing : two or more distinct names that can be used to access the same memory cell.
16. The ability of the program to intercept run time error.
17. If it is hard to read, then it is hard to write.
18. Many run time checks will prohibit fast code execution. If optimization is used, compiling will be slower but execution will be faster.
19. The basic architecture of computers (von Neumann).
20. Imperative languages.
21. Incompleteness of type checking and inadequacy of control statements.
22. Data abstraction, inheritance and dynamic (run-time) method.
23. Smalltalk.
24. Reliability and Cost of execution.
25. Compilation, Pure Interpretation, Hybrid Implementation System.
26. Compiler.

Problem set :

1. Yes, in programming, a problem can be solved by so many ways, but to solve it in a particular algorithmic step, the programmer required to have programming language skills. The programmer might have to use some of the built-in functions in specific programming language to solve it in a particular algorithmic step. The programmer have to have that specific programming language skills to be able to use the functions properly.

2.  Functionality : the way a programming language is to be used, and implemented or learned
 Abstractions : to define and manipulate data structures or controlling the flow of execution
 Efficiency : programs written in a good programming language are efficiently translate into
machine code
3. Java uses a semicolon to mark the end of all statements. What are the advantages for and
against this design?
 Avoid getting confused while ending a statement (fullstop mark and comma)
 Easier to separate some statements into several line and blocks
4. Most languages use functions and subroutines. What are the pros and cons of this design
decision?
 Pros : increase error handling, maintenance, portability
 Cons : decrease reliability of programs if it doesn’t used properly
5. Describe the advantages and disadvantages of using different computer architecture for
writing a program.
 Advantages :
6. Name some programs which use preprocessor directives and some which don’t. What are the
advantages and disadvantages of processor directives?
7. Does a Just-In-Time (JIT) implementation system affect the execution of code? Why or why
not?
8. Some programming languages-for example, SQL-use “=” to check the equality of two
expressions, while C uses it to assign values to variable. Which of these, in your opinion, is
most natural and least likely to result in syntax errors? Support your answer.