Selasa, 26 Maret 2013

Chapter 3

Review Questions

1. Define syntax and semantics!
Syntax 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 ?
Potential users and Programming Language Implementors


3. Describe the operation of a general language generator.
A general language generator is a device that can be used to generate the sentences of the language. It generates unpredictable sentences which makes a generator seems to be a device of limited usefulness as language descriptor.



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

7. What three extensions are common to most EBNFs ?
Three extensions are commonly included in the various versions of EBNF. The first extension denotes an optional part of an RHS, which is delimited by brackets. The second extension is the use of the brackets in an RHS to indicate that the enclosed part can be repeated indefinitely or left out altogether. And the third extension deals with multiple-choice options.


9. What purpose do predicates serve in an attribute grammar ?
Predicates in attribute grammar states the static semantic rules a language needs to follow. A false value in predicates indicates that there is an invalid syntax or static semantics and determines whether an action is allowed or not.


10. What is the diference between a synthesized and an inherited atribute ?
The attributes are divided into two groups: synthesizedattributes and inherited attributes. 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.


12. What is the primary use of attribute grammar?
Attribute grammar is primary used to provide complete descriptions of the syntax and static semantics of programming languages.


22. Give an example of an ambiguous grammar.
<assign> -> <id> = <expr>

<id> -> A | B | C

<expr> -> <expr> + <expr>

| <expr> * <expr>

|  (  <expr>  )

| <id>



24. Give an unambiguous grammar for if-then-else.
<if_stmt> -> if <logic_expr> then <stmt>
if <logic_expr> then <stmt> else <stmt>


25. What is the problem with using a software pure interpreter for operational semantics?
The detailed characteristics of the particular computer would make actions difficult to understand. Such a semantic definition would be machine-dependent.

27. What is loop invariant? Explain with an example.
A loop invariant is a condition that is necessarily true immediately before and immediately after each iteration of a loop. Example:
int j = 9;
for(int i=0; i<10; i++)
j–;
In this example it is true (for every iteration) that i + j == 9. A weaker invariant that is also true is that
i >= 0 && i < 10 (because this is the termination condition) or that j <= 9 && j >= 0.




Problem Set

3. Rewrite the BNF of Example 3.4 to represent operator – and operator / instead of operator + and operator *.
<assign> → <id> = <expr>
<id> → A | B | C
<expr> → <expr> – <term>
| <term>
<term> → <term> / <factor>
| <factor>
<factor> → ( <expr> )
| <id>

4. Rewrite the BNF of Example 3.4 to add the ++ and — unary operators of Java.
<assign>
→ <id> = <expr>
<id>
→ A | B | C
<expr>
→ <expr> + <term> class  <Unary – condition- statement>
| (++/–) <term>
<term>
→ <factor> + <term>
| <factor>
<factor>
→ ( <expr> )
| (++/–) <id>


9. Modify the grammar of Example 3.4 to add a unary minus operator that has higher precedence than either + or *.
<assign> -> <id> = <expr>
<id>  ->  A | B | C
<expr> -> <expr> + <term>
| <term>
<term> -> <term> * <factor>
| <factor>
<factor> -> ( <expr> )
| +<id> | -<id>


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


a. bbaabb and c.bbaaaabb

15.   Convert the BNF of Example 3.1 to EBNF.
<program>  ->  begin <stmt_list> end
<stmt_list> -> <stmt>
| <stmt> ; <stmt_list>
<stmt> -> <var> = <expression>
<var> -> A | B | C
<expression> -> <var> {(+|-) <var>}


16. Convert the BNF of Example 3.3 to EBNF.
<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
S → A | A B
B → b A | b A B
A → a A | a b A

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


23. Compute the weakest precondition for each of the following assignment statements and postconditions:
a. a = 2 * (b – 1) – 1 (a > 0)
b. b = ( c + 10)  / 3 (b > 6)
c. a = a + 2 * b – 1 ( a > 1)
d. x = 2 * y + x – 1 (x > 11)

(a) ->   a = 2 * (b – 1) – 1 {a > 0}
2 * (b – 1) – 1 > 0
2 * b – 2 – 1 > 0
2 * b > 3
b > 3 / 2
(b) ->   b = (c + 10) / 3 {b > 6}
(c + 10) / 3 > 6
c + 10 > 18
c > 8
(c) ->   a = a + 2 * b – 1 {a > 1}
a + 2 * b – 1 > 1
2 * b > 2 – a
b > 1 – a / 2
(d) ->   x = 2 * y + x – 1 {x > 11}
2 * y + x – 1 > 11
2 * y + x > 12

Concepts of Programming Language - Chapter 2

Review Questions

1.In what year was Plankalkul designed? In what year was that design published?Designed by Konrad Zuse in 1945. Published in 1972.


2.Mention an interesting feature of Zuse's programs.An interesting feature of Zuse’s programs was the inclusion of mathematical expressions showing the current relationships between program variables. These expressions stated what would be true during execution at the points in the code where they appeared.


3.What does Plankalkul mean?
Plankalkul means program calculus.


5.What is the number of bits in a single word of the UNIVAC I's memory? How are the bits grouped?
The words of the UNIVAC I’s memory had 72 bits, grouped as 12 six-bit bytes. 


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


10.What was the most significant feature added to Fortran I to get Fortran II?
 Independent compilation of subroutines


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


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


16.In what way are Scheme and Common LISP opposites of each other?
  Scheme lacks on portability but LISP doesn’t. That’s why they are different.


18.What two preofessional organizations together designed ALGOL 60?
 Association for Computing Machinery (ACM) and GAMM


19. What was the goal for developing for developing C?
  to provide a language in which programs could be organized as they could be organized in SIMULA 67—that is, with classes and inheritance.


21. What language was designed to describe the syntax of ALGOL 60?
   BNF (Backus-Naur form).


22. On what language was COBOL based?
FLOW-MATIC language.


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


26. Which data type does the original BASIC language support?
Floating-point


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


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




Problem Sets


3.Write a short history of the Fortran 0, Fortran I, Fortran II, and Fortran IV systems.

Fortran 0 was modified during the implementation period, which
began in January 1955 and continued until the release of the compiler in April
1957. The implemented language, which we call Fortran I, is described in the
first Fortran Programmer’s Reference Manual.

FORTRAN I: The first FORTRAN compiler was a milestone in the history of computing, at that time computers had very small memories (on the order of 15KB, it was common then to count memory capacities in bits), they were slow and had very primitive operating systems (if they had them at all). At those days it seemed that the only practical way is to program in assembly language.
FORTRAN II: FORTRAN II (1958) was a significant improvement, it added the capability for separate compilation of program modules, assembly language modules could also be ‘linked loaded’ with FORTRAN modules 


6. Make an educated guess as to the most common syntax error in C programs.

-using instead of ==
-scanf() errors (Forgetting to put an ampersand (&) on arguments, Using the wrong format for operand)
-Loop errors
-forget to put semicolon(;) in the end of a statement


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

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.

13.What is the primary reason why C became more widely used than Fortran? 

The primary reason why C became more widely used than Fortran because Fortran will never be much faster than C, moreover C is much more readable.

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

 Typeless language allowing more flexibility but it also can create an ambiguity as to the contents of a variable

15.Describe the two levels of uses of operational semantics!

 There are. Some of them include database manipulation languages, such as SQL and perhaps some other kind of language like Visual Basic.

24.Why, in your opinion, do new scripting languages appear more frequently than new compiled languages?

 Because scripting languages usually are simpler and focused on specific applications.

25. Give a brief general description of the Java Scarlet.

Java servlet is server-side Java program modules that process and answer client requests and implement the servlet interface

Senin, 04 Maret 2013

Review Question and Problem Set - Chapter 1

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

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

COBOL

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

LISP

6. In what language is most of UNIX written?

C

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

A reliable program will detect input errors and bad or missing data, and recover from it. In other words, it won't crash on bad input or if a file is missing or corrupt.

15. What is aliasing?

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

16. What is exception handling?

Exception handling is the ability of a program to intercept run-time errors, take corrective measures and continue, which makes program more reliable. Found in some languages such as Ada, C++, C#, and Java.


26. Which produces faster program execution, a compiler or a pure interpreter?
A compiler.


28. What is the utility of byte code?
Byte code provides portability to any machine that has byte code interpreter and an associated run-time system.


29. What is a hybrid implementation system?
Hybrid implementation systems are a compromise between compilers and pure interpreters.


Problem Set

1. Do you believe that solving a problem in a particular algorithmic step requires programming language skills? 
No, I think the most important think in solving a problem is logic. Mastering programming language is not really necessary. 

2. Who is said to be the first programmer in human history?

Augusta Ada King, Countess of Lovelace (10 December 1815 – 27 November 1852), born Augusta Ada Byron and now commonly known asAda Lovelace, was an English mathematician and writer chiefly known for her work on Charles Babbage's early mechanical general-purposecomputer, the Analytical Engine. Her notes on the engine include what is recognized as the first algorithm intended to be processed by a machine. Because of this, she is often considered the world's first computer programmer.

3.What are the disadvantages of multiple programming languages?

There's too many programming language to learn and you can't perfectly master the languages.  It'll tire your brain too if you force it to master all of the languages. 

7. Java uses a semicolon to mark the end of all statements. What are the advantages for and against this design?
Semicolon is used to mark the end of the statements, if I somehow use it wrong, the statement will turn into error. 
10.  Make a comparative study of the cost of software and hardware.
The more complicated and sophisticated the software is,the higher the price. As for hardware, the price subsequently changes according to the development of technology. The same hardware would cost differently back then and now. 

12. Can we call any programming language complete, in your opinion? Why or why not?

No, because each languages have its own special use. They have their disadvantages and advantages , that's why neither of them is complete. 










Dosenku

Tri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko Wahjono
Tri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko WahjonoTri Djoko Wahjono

Or you can say..

Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono Tri Djoko WahyonoTri Joko WahyonoTri D. Wahjono