Selasa, 26 Maret 2013

Concepts of Programming Languages Assignment - Chapter 3

Review Questions

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

2. Who are language descriptions for?
The language descriptions is important for the programming language implementers to determine how the expressions, statements, and program units of a language are formed, and also their intended effect when executed

3. Describe the operation of a general language generator.
Language generator is a device that can be used to generate the sentences of languages. People prefer certain forms of generators over recognizers because they can more easily read and understand them. Language generator operates by generating a sentence of language, however language generators is unpredictable

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

6. Define a left-recursive grammar rule.
A grammar is left-recursive if we can find some non-terminal A which will eventually derive a sentential form with itself as the left-symbol

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

18. Which semantics approach is most widely known?
Denotational semantics

23. On what branch of mathematics is axiomatic semantics based?
mathematics logic

24. On what branch of mathematics is denotational semantics based?
mathematical objects

29. Give the difference between total correctness and partial correctness.
Total correctness requires that the algorithm terminates while partial correctness requires that if an answer is returned it will be correct

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 is a code error and semantic error is a logical error. Example of syntax error is forget to put a semicolon, bracket, etc. Example of semantic error is,

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>

8. Prove that the following grammar is ambiguous:
<S> -> <A>
<S> -> <A> * <A> | <id>
<id> -> x | y | z

The grammar generates a different parse tree, so the grammar is ambiguous.

9. Modify the grammar of Example 3.4 to add a unary minus operator that has higher precedence than either + or *.
<factor> → <id>
with
<factor> → + <id>
| - <id>

13. Write a grammar for the language consisting of strings that have n copies of the letter a followed by the same number of copies of the letter b, where n > 0. For example, the strings abb, aabbbb, and aaaabbbbbbbb are in the language but a, aabb, ba, and aaabb are not.
S -> ab
b ->bb

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>}
| <id>

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

answer :
S -> A | AX
X -> bA | bAX
A -> aA | abA

18. What is a fully attributed parse tree?
If all of the attribute values in a parse tree have been computed, the tree is said to be fully attributed

Senin, 11 Maret 2013

Concepts of Programming Languages Assignment - Chapter 2

Name : Ryanto Salim
Class : 02PCT
NIM : 1601231415

Review Questions

1. In what year was Plankalkul designed? In what year was that design publishes?
Designed in 1943 and Published in 1972

3. What does Plankalkul mean?
Program Calculus

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

8. Who developed Short Code? Why is Short Code called automatic programming?
John Mauchly. Because, it clearly simplified the programming process, but at the expense of execution time.

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

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

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

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?
Because, Linguists were concerned with natural language processing

15. What are the different data types and structures in Common LISP?
Records, arrays, complex numbers and character strings

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

18. What two professional organizations together designed ALGOL 60?
GAMM and ACM

22. On what language was COBOL based?
English

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)

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

36. Why is Prolog called a nonprocedural language?
Because, programming in logic programming languages is nonprocedural

Problem Set

2. Determine the capabilities of Short Code, and compare them with those of a contemporary programmable hand calculator.
Short Code clearly simplified the programming process, but at the expense of execution time. Short Code interpretation was approximately 50 times slower than machine code (hand calculator).

6. Make an educated guess as to the most common syntax error in C programs.
The most common syntax error in C i think is forget to end a statement with semicolon (;)

8. Describe in detail the two most important reasons, in your opinion, why Speedcoding did not become a very widely used language.
Because, Speedcoding fills up a lot of space on the disk so it's ineffective

13. What is the primary reason why C became more widely used than Fortran?
Because,  C is flexible and well suited for various applications and also a compiler for C was part of the widely used UNIX operating system in 1980s

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. Are there any nonprocedural programming languages other than Prolog?
Yes there are, like Visual Basic and SQL

25. Give a brief general description of the Java servlet.
Java servlet is a Java programming language class used to extend the capabilities of a server. Although servlets can respond to any types of requests, they are commonly used to extend the applications hosted by web servers, so they can be thought of as Java Apllets that run on servers instead of in web browsers


Senin, 04 Maret 2013

Concepts of Programming Language Assignment - Chapter 1

Name : Ryanto Salim
Class : 02PCT
NIM : 1601231415

Review Questions

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 pas 50 years?
LISP

6. In what language is most of UNIX written?
C

7. What is the disadvantage of having too many features in a language?
Having too many features in a language will make it more difficult to learn and it may cause feature multiplicity.

8. How can user-defined operator overloading harm and the readability of a program?
Because, sometimes the user make the user-defined operator without being sensible which can reduce the readability.

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

13. What does it mean for a program to be reliable?
A program is said to be reliable if it performs to its specifications under all conditions.

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 then continue is an obvious aid to reliability.

Problem Set

1. Do you believe that solving a problem in a particular algorithmic step requires programming language skills?
No, because people who can solve their problem properly(step by step) like an algorithm steps doesn't guarantee that those people have programming language skills.

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

3. What are the disadvantages of multiple programming language?
I think the main disadvantage of using multiple programming language is it can make you confuse, especially for beginner programmer and if people using multiple programming language usually they didn't really skilled in those programming languages but only good or average.

4. In what way do the languages for scientific applications differ from the languages for business applications?
Language for scientific applications is more complex i think, because it must support many different calculations that related to scientific uses and language for business application maybe simpler. But, of course the main difference between both of them is the functions itself.

6. Which characteristics of programming languages do you think are the most important and why?
Readability, because it's one of the most important criteria for judging a programming language whether it's easily read and understood or not. Also, if a programming language have a high readability it will make the user more easier to learn how to use that programming language.

7. Java uses a semicolon to mark the end of all statements. What are the advantages for and against this design?
The advantage is that you can easily identify which is the end of one statement from your code, and the disadvantage is sometimes it can cause an error if you forget to put it.

Special Post

This post dedicated to :
Mr. Tri Djoko Wahjono, Ir., M.Sc.
Mr. Tri Djoko Wahyono, Ir., M.Sc.
Mr. Tri Djoko Wahjono, Ir., M.Sc.
Mr. Tri Djoko Wahyono, Ir., M.Sc.
Mr. Tri Djoko Wahjono, Ir., M.Sc.
Mr. Tri Djoko Wahyono, Ir., M.Sc.
Mr. Tri Djoko Wahjono, Ir., M.Sc.
Mr. Tri Djoko Wahyono, Ir., M.Sc.
Mr. Tri Djoko Wahjono, Ir., M.Sc.
Mr. Tri Djoko Wahyono, Ir., M.Sc.


From : Ryanto Salim / 02PCT / 1601231415