Selasa, 26 Maret 2013

chap 3 review question and problem set concepts of programming language sebesta


Chapter 3 Concepts of Programming Language

Review Question

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

3. Describe the operation of a general language generator
Answer: A language generator is a device that can be used to generate the sentences of a language. The particular sentence that is produced by a generator is unpredictable, a generator seems to be a device of limited usefulness as a language descriptor.

6. Define a left-recursive grammar rule
Answer: A left-recursive grammar rule means that a rule is recursive if its Left-Hand Side appears in its Right-Hand Side. Example:  <ident_list> -> identifier
                                                                                | Identifier, <ident_list>

7. What are three extensions are common to most EBNFs?
Answer:   The first of these denotes an optional part of an RHS, which is delimited by brackets.
The second extension is 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.

15. Describe the two levels of uses of operational semantics.
Answer:  There are different levels of uses of operational semantics.  At the highest level, the interest is in the final result of the execution of a complete program that called as 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. This use is sometimes called structural operational semantics.

 22. Give an example of an ambiguous grammar
Answer:
Example of an ambiguous grammar
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> + <expr>
| <expr> * <expr>
| ( <expr> )
| <id>

23. On what branch of mathematics is axiomatic semantics based?
Answer:  Axiomatic semantics is based on mathematic logic branch.

24. Give an unambiguous grammar for if-then-else.
Answer:  an unambiguous grammar for if-then-else
<stmt> → <matched> | <unmatched>
<matched> → if <logic_expr> then <matched> else <matched>
|any non-if statement
<unmatched> → if <logic_expr> then <stmt>
|if <logic_expr> then <matched> else <unmatched>

27. What is loop invariant? Explain with an example.
Answer:
Loop invariant is an assertion of the corresponding step in the axiomatic semantics of a while loop. Example:
The inference rule for computing the precondition for a while loop is

Where I is the loop invariant.

28. What is the use of the wp function? Why it is called a predicate transformer?
Answer:
wp function is helpful to treat the process of producing a weakest precondition as a function, wp.
A wp function is called as a predicate transformer, because it takes a predicate, or assertion, as a parameter and returns another predicate.

Problem Set

1. Syntax Error and semantic error are two types of compilation error. Explain the differences between the two in a program with examples.
Answer:
Syntax error is an error that cause by wrong typing or mistype of one or more character that represent a syntax or it can be en error because of breaking the rule of writing the syntax.
The program can’t be compiled because of syntax error
For example in C:
printf (Hello world) //it would be an error because of mistyping the “ ” and the semicolon
Semantic error is a logical error, it might be compiled but it has a logic error in the program.
For example :    int r  =  20;
int pi = 12345;
                        int area = pi *(r ^2);
It can be compiled but if assign the value of pi to calculate the circle area the result would be wrong.

5. Write a BNF of description of the relational operator of Java, including the two operators == and !=.
Answer:
<equality expression> ::= <relational expression> | <equality expression> == <relational expression> | <equality expression> != <relational expression>

6. Using the grammar in Example 3.2, show a parse tree for each of the following statements:
a. A = A * (B + (C * A))
            

b. B = C * (A * C + B)


c. A = A * (B + (C))




8. Prove that the following grammar is ambiguous:
<S> → <A>
<A> → <A> *<A> | <id>
<id> → x | y | z
Answer:
 It is ambiguous because it has two or more possibility parse trees to express a statement
Example:
The statement xyz with parse tree

  
                                                                                                                                         

11. Consider the following grammar:
<S> → <A> a <B> b
<A> → <A> b | b
<B> → a <B> | a
Which of the following sentences are in the language generated by this grammar?
a. bbaabb
b. bbaba
c. bbaaaabb
d. abaabb
Answer:
a. bbaabb and c.bbaaaabb


12. Consider the following grammar:
<S> → a <S> c <B> | <A> | b
<A> → c <A> | c
<B> → d | <A>
Which of the following sentences are in the language generated by this grammar?
a. abbccd
b. acccbda-
c. accbcbccc-
d. acddaccd-
e. acccdc
Answer:
e.acccdc

15. Convert the BNF of Example 3.1 to EBNF.
Answer:
BNF of example 3.1
<program> → begin <stmt_list> end
<stmt_list> → <stmt>
| <stmt> ; <stmt_list>
<stmt> → <var> = <expression>
<var> → A | B | C
<expression> → <var> + <var>
| <var> – <var>
| <var>
EBNF of example 3.1

<program> → begin <stmt_list> end
<stmt_list> → <stmt>
| <stmt> ; <stmt_list>
<stmt> → <var> = <expression>
<var> → A | B | C
<expression> → <var> { (+|-)<var>}
| <var>



16. Convert the BNF of Example 3.3 to EBNF.
Answer:
BNF of example 3.3
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> + <expr>
| <expr> * <expr>
| ( <expr> )
| <id>

EBNF of example 3.3
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> { (+ | * ) <expr>}
| ( <expr> )
| <id>



17. Convert the following EBNF to BNF:
S → A{bA}
A → a[b]A
Answer:
The BNF of S → A{bA}
S →A
     |bA

The BNF of A → a[b]A
A→ aA
     |abA

18. What is a fully attributed parse tree?
Answer:
A fully attributed parse tree is a condition when all the attributed values in parse tree have been computed.

Special thanks to Mr. Tri Djoko Wahjono, Ir., M.Sc.



Minggu, 10 Maret 2013

Chap 2 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta

Review Question


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

3. What does Plankalkül mean ?
Answer:
It means Program Calculus

7. Who developed the Speedcoding system for the IBM 701 ?
Answer:
John Backus developed speedcoding

9. Under what environmental consideration was the Fortran developed? What is the first version of Fortran ? 
Answer:
FORTRAN was developed under the environment of: (1) Computers had small memories and were slow and relatively unreliable; (2) the primary use of computers was for scientific computations; (3) there were no existing efficient and effective ways to program computers; and (4) because of the high cost of computers compared to the cost of programmers, speed of the generated object code was the primary goal of the first Fortran compilers. The first version of Fortran is Fortran 0.

10. What was the most significant feature added to Fortran I to get Fortran II ?
Answer:
The significant features that was added to Fortran I to be Fortran II was the independent compilation of subroutines.

14. Why were linguists interested in artificial intelligence in the late 1950s ?
Answer: 
Linguists were interested with AI in the latest of 1950 because they were concern with natural language processing.

19. What was the goal for developing C? 
Answer:
The goal of developing C is to make a suite language for a wide variety of applications.

20. What were the significant modification to ALGOL 58 to produce ALGOL 60 ?
Answer: 
The significant modification to ALGOL 58 to ALGOL 60 was:


  • The concept of block structure was introduced. This allowed the programmer to localize parts of programs by introducing new data environments, or scopes.
  • Two different means of passing parameters to subprograms were allowed: pass by value and pass by        name.
  • Procedures were allowed to be recursive. The ALGOL 58 description was unclear on this issue. Note that although this recursion was new for the imperative languages, LISP had already provided recursive functions in 1959.
  •  Stack-dynamic arrays were allowed. A stack-dynamic array is one for which the subscript range or ranges are specified by variables, so that the size of the array is set at the time storage is allocated to the array, which happens when the declaration is reached during execution.

23. In what year did the COBOL design process begin ?
Answer:
COBOL design process begin in 1959

26.Which data type does the original BASIC language support ?
Answer: 
The original data type that BASIC support is floating point

29. For what new line of computer was PL/I designed ?
Answer: PL/I was designed for IBM System/360 line of computer


30. What features of SIMULA 67 are now important parts of some object oriented languages?
Answer:
SIMULA 67 has some important part like the class construct and the concept of abstract data type that provide the foundation for object-oriented programming

37. What are two kinds of statements that populate a Prolog database ?
Answer:
Prolog has two kind of statement in its database which are facts and rules.

36. Why is prolog called non procedural language?
Answer: 
Prolog was called a nonprocedural language because it doesn’t state exactly how a result is to be computed but rather describe the necessary form and/or characteristics of the result.


39. What are the concurrent program unit of Ada called?
Answer:  The concurrent program units of Ada was called task

40. What C++ construct provides support for abstract data types ?
Answer:
C++ construct Cfront that was implemented to provides support for abstract data types


42. What three concepts are the basis for object-oriented programming? 
Answer:
Three basic concepts of Object-Oriented-Programming are inheritance, encapsulation, and polymorphism.

45. What programming language paradigm that nearly all recently designed languages support is not supported by Go?
Answer: Go doesn’t support Object-Oriented Programming design language


Problem Set

1.  What features of Fortran IV do you think would have had the greatest influence on Java if the Java designer had been familiar with Fortran?
Answer:
The feature in Fortran IV that would have had influence on Java is the logical If construct. This control statement is found in Java and it is very useful to make a selection that depends on some conditions.

2. Determine the capability of Short Code, and compare them with those of a contemporary programmable hand calculator.
Answer:
Short Code consists of coded version of mathematical expression that was to be evaluated. Short code can be used to code many equations such as power, square roots, addition, subtraction, division but there is no multiplication code. Short code was able to be implemented into UNIVAC I computer. In the other hand contemporary programmable calculator was able to do multiplication with its embedded programming language.  So with the contemporary calculator people can solve arithmetic problem easier than using the Short Code but it is more difficult to do further improvement to the programmable hand calculator than to the Sort Code.

5. Which of three original goals of the Fortran design committee, in your opinion, was most difficult to achieve at that time?
Answer:
The goal to provide an efficient of hand coded program was look like be the most difficult to achieve because at that time the computer had very small memory and were slow. It would be ineffective to make an hand coded complex program that kind of computer.

7. LISP began as a pure functional language but gradually acquired more and more imperative features. Why?
Answer:
LISP acquired more and more imperative feature because repetitive processes can be specified with recursive function calls, making iteration (loops) unnecessary. That basic concept of functional programming makes it significantly different from programming in an imperative language.

9. Why in your opinion, did Fortran allow names that began with I, J, K, L, M and N as implicitly integer type?
Answer:  
In my opinion did Fortran allow names that began with I, J, K, L, M and N as implicitly integer type because in linear algebra i j k are used to represent the vector from axis x, y, z and since the Fortran is made for most scientific purpose so they allow it.

10. Outline the major development in ALGOL 60.
Answer:


  • The concept of block structure was introduced. This allowed the programmer to localize parts of programs by introducing new data environments, or scopes.
  • Two different means of passing parameters to subprograms were allowed: pass by value and pass by name.
  •  Procedures were allowed to be recursive. The ALGOL 58 description was unclear on this issue. Note that although this recursion was new for the imperative languages, LISP had already provided recursive functions in 1959.
  •  Stack-dynamic arrays were allowed. A stack-dynamic array is one for which the subscript range or ranges are specified by variables; so that the size of the array is set at the time storage is allocated to the array, which happens when the declaration is reached during execution.

12. Describe in your own words, the incorporation of procedural and non-procedural features in programming language design.
Answer:
In my opinion there are three features from the incorporation of procedural and non-procedural. Firstly it will provide an easier way for a programmer to construct a program. The non-procedural and procedural is able to cover how a person thinks, because every programmer has their own way to solve a problem; it can be procedural or non-procedural.  Secondly, an incorporation of procedural and non-procedural will increase the number of variety problem that can be solved by using this method. Thirdly it will increase the orthogonality because there will be many possibilities of combining the structure form procedural and non-procedural programming language design.

14. What are the arguments both for and against the idea of typeless language?
Answer:
Typeless language is less powerful to solve a specific problem such as for business or for Website but in the other hand typeless language provides a simplicity in the making of a common program and by using typeless language the program that is written can be run in almost all system platform. With typeless language programmer doesn’t need to know many kind of syntax from many kind of different programming language.


15. Are there any non-procedural programming language other than prolog?

Answer: 
Yes there are, for example programming languages for data base like SQL and Visual Basic

By Moses Kurniawan
NIM : 1601235003
Class: 02PCT
Special thanks to:  Mr. Tri Djoko Wahjono, Ir., M.Sc.

Chap 1 - Review Question and Problem Set - Concepts of Programming Languages, Sebesta


Review Question


1. Why is it useful for a programmer to have some background in language design, even though he or she may never actually design a programming language?
Answer:
It is useful to have some language design background because it can increase the capability to express ideas, it will increase ability to learn new languages and help the person to choose the appropriate language

2. How can knowledge of programming language characteristics benefit the whole computing community?
Answer:
By having knowledge about programming language characteristic, the computing community can make the right decision to choose the appropriate programming language for a more efficient work to solve problems.


4. What programming language has dominated business applications over the past 50 years?
Answer:
The programming language that dominated business application over the past 50 years was COBOL


6. In what language is most of UNIX written?
Answer:
UNIX was mostly written in C language

7. What is the disadvantage of having too many features in a language?
Answer: it will decrease the simplicity and it can also decrease the readability

9. What is one example of a lack of orthogonality in the design of C?
Answer: 
A programming language supports the use of pointer variable so it should be possible to define a pointer to point any specific type defined in the language. In case, if the pointers are not allowed to point array, many potentially useful user-defined data structures cannot be defined

12. What construct of a programming language provides process abstraction?
Answer:
The degree of abstraction allowed by the programming language and the naturalness of its expression construct the programming language provide process abstraction

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 conditions.

14. Why is type checking the parameters of a subprogram important?
Answer:
It is important in order to make sure that there is no type error which can cause countless program error


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

17. Why is readability important to writability?
Answer:
Because readability affects reliability in both the writing and maintenance phases of the life cycle.

20. What is the name of the category of programming languages whose structure is dictated by the von Neumann computer architecture?
Answer:
the name of the category of programming language whose structure is dictated by the von Neumann computer architecture is imperative language

21. What two programming language deficiencies were discovered as a result of the research in software development in the 1970s?
Answer:
incomplete of type checking and inadequacy of control statement

Problem Set


2. Who is said to be the first programmer in human history? Use the Internet for help.
Answer:
According to the Wikipedia.com the first programmer was Ada Lovelace


3. What are the disadvantages of multiple programming languages?
Answer:
The disadvantages are, first, this condition makes many standard requirements to decide an appropriate programming language, second it is difficult to understand all of the programming language variety, and third there must be a conversion between one programming language and other in order to combine a different subprogram written in a different language into one simple program.


4.In what way do the languages for scientific applications differ from the languages for business applications? Support your view.  
Answer:
 languages for scientific application allows the user to make a complicated calculation with some large number of  floating point in the other hand languages for business application are design for the user to user characterized facility to elaborate reports, precise ways of describing and storing decimal numbers and character data.

6. Which characteristic of programming language do you think are the most important and why?
Answer:
In my opinion the readability is the most important characteristic in programming language. It is because readability reference to the overall simplicity, orthogonality, data types and also the design of the syntax. So the more readable programming language makes easier way to develop a program.


9. Explain how orthogonality in a programming language is closely related to simplicity
Answer: If a language has a large number of different constructs, some programmers might not be familiar with all of them. Therefore, a smaller number of primitive constructs and a consistent set of rules for combining them (that is, orthogonality) is much better than simply having a large number of primitives. So orthogonality in programming language is closely related to its simplicity.

10. Make a comparative study of the cost of software and hardware
Answer:
Nowadays generally hardware computers cost cheaper than software of computer because most of hardware computer industry uses advance technology such as robotics and advance material such as silicon for the semiconductor to increase the efficiency and reduce the cost of the making, in the other hand software industry nowadays create better and better software and it is created by human creativity, logic and all about the human resource so that makes software cost more expensive than hardware. But if we look at the pass, the hardware is more expansive than software, because to create computers hardware requires high skill employers beside using advance robot technology, in the opposite the cost of software is cheaper than hardware because in the pass computer are not able to run such a big and complex software so the software in the pass was not as complex as nowadays’ software.

13. Was the first high level programming language you learned implemented with a pure interpreter, a hybrid implementation system, or a compiler?
Answer:
yes, C was my first programming language that I studied and C is implemented with compiler implementation method.

15. Name some language which use preprocessor directive and some which don’t. What are the advantage and disadvantage of preprocessor directives?
Answer:
Languages that use prepocessor : Java, C, C++, PL/I
languages that dont use prepocessor: Ada, Modula, Clu
Advantage of using preprocessor directive
-Helps the programmer to define a symbol or value that can reduce the development time
-To specify the use of a library that contains of function(s)
Disadvantage of using preprocessor directive
-increase the whole processing time to execute the program

By Moses Kurniawan
NIM : 1601235003
Class: 02PCT
Special thanks to:  Mr. Tri Djoko Wahjono, Ir., M.Sc.