Kamis, 30 Oktober 2014

Chapter 5 Pak Tri Djoko

REVIEW QUESTION

11. Question : What are the advantages and disadvantages of dynamic type binding ?

Answer : 
Advantages = It is more easy to write generic code.
Disadvantages = High Cost to check type and interpretation

12. Question : Define static, stack-dynamic, explicit heap-dynamic, and implicit heapdynamic
variables. What are their advantages and disadvantages ?

Answer : 
- Static -- memory alloc'd before execution. Stays throughout.
Adv: runtime efficient, history-sensitive subprograms. Disadv: no recursion.

- Stack dynamic - memory alloc'd from system stack when decl elaborated.
Adv: recursion, conserves memory. Disadv: no history sensitive subpgms, less run-time efficient than static.
- Explicit heap-dynamic -- memory alloc'd/freed by pgmer from "heap".
Adv: flexible storage mgmt. Disadv: less effiicent than stack-dyn; Error prone in pairing new/delete stmts.
- Implicit heap-dynamic -- heap memory alloc'd/freed by assignments.
Adv: highext flexibility. Disadv: run-time cost to maintain all the dynamic attrs; Reduced compiler error detection.

13. Question: Define lifetime, scope, static scope, and dynamic scope.

Answer : 
Lifetime -- when memory is alloc'd for a variable (when in existence).
Scope -- portions of pgm variable can be referenced or set.
Static scope -- scope based on source pgm text (static ancestors).
Dynamic scope -- scope based on run-time call sequence.

14. Question : How is a reference to a nonlocal variable in a static-scoped program connected
to its definition ?

Answer : 
A reference to a non-locally variable in a static-scoped language with nested subprograms requires a two step access process:

1. Find the correct activation record instance

2. Determine the correct offset within that activation record instance
15. Question : What is the general problem with static scoping ?

Answer : 
Usually too much access. Scope structure destroyed as pgm evolves.

Problem Set

1. Question : Which of the following identifier forms is most readable? Support your
decision.
SumOfSales
sum_of_sales
SUMOFSALES

Answer : 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.

2. Question : Some programming languages are typeless. What are the obvious advantages
and disadvantages of having no types in a language?

Answer : 
Advantages:
- The only advantage is that is allows coders to write sloppy programs quickly.

Disadvantages:
- You are not in control of the data and variables, the compiler or interpreter is.
- If you mis-assign variables, there is no way for the compiler to catch any of your mistakes. It just “does what you said”, even if it is wrong.
- Supporting programs in a type-less language is much more difficult that in a strongly types one. It is often very difficult to determine what the original programmer wanted to do.

3. Question : Write a simple assignment statement with one arithmetic operator in some
language you know. For each component of the statement, list the various
bindings that are required to determine the semantics when the statement is
executed. For each binding, indicate the binding time used for the language.

Answer : 
(C++)
int count;count = count + 5;
Possible types for count: set at language design time. Type of count: bound at compile time.
Set of possible values of count: bound at compiler design time. Value of count: bound at execution time with this statement. Set of possible meanings for the operator symbol ““:*bound at language definition time.*Meaning of the operator symbol “” in this statement: bound at compile time.
Internal representation of the literal “5”: bound at compiler design time.

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

Answer : 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. Question : Describe a situation when a history-sensitive variable in a subprogram is
useful.

Answer : 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


Rabu, 29 Oktober 2014

Chapter 4 Pak Tri Djoko

REVIEW QUESTION 


11. Describe the parsing problem for a bottom-up parser.
      Answer :bottom up parser only can identifies and processes the text's lowest-level details before processes middle level structures and leaving the highest level overall structure to last


12. Explain why compilers use parsing algorithms that work on only a subset of all grammars.
      Answer :because compiler can use one parsing compiler that work on only subset of all grammars


13. Why are named constants used, rather than numbers, for token codes?
      Answer :
      - for the sake of readability of lexical and syntax analyzers.


14. Describe how a recursive-descent parsing subprogram is written for a rule with a single RHS.
      Answer :
     -A recursive-descent subprogram for a rule with a single RHS is relatively
      simple. For each terminal symbol in the RHS, that terminal symbol is compared
      with nextToken. If they do not match, it is a syntax error. If they match,
      the lexical analyzer is called to get the next input token. For each non terminal,
      the parsing subprogram for that nonterminal is called.


15. Explain the two grammar characteristics that prohibit them from being used as the basis for a      top-down parser.
      Answer : Two grammar characteristics that prohibit top-down parsing:
                      Direct or indirect Left Recursion.

Rabu, 15 Oktober 2014

Chapter 3 Pak Tri Djoko

Review Question
11. How is the order of evaluation of attributes determined for the trees of a given attribute grammar?
12. What is the primary use of attribute grammars?
-> Tujuan utama dari attribute grammars untuk menggambarkan struktur bahasa pemograman lebih dari yang dijelaskan dari konteks-bebas grammer
13. Explain the primary uses of a methodology and notation for describing the semantics of programming languages.
->Ada beberapa alasan yang mendasari perlunya metodologi dan notasi untuk menggambarkan semantik. Programmer harus mengetahui dengan jelas apa yang dilakukan statement dari bahasa sebelum mereka dapat menggunakannya secara efektif dalam program mereka. Penulis Compiler harus tahu persis maksud dari konstruksi bahasa untuk merancang maksud mereka dengan benar. Jika ada spesifikasi semantik yang tepat dari bahasa pemrograman, program ditulis dalam bahasa yang berpotensi terbukti kebenarannya walau tanpa tes. kompiler juga dapat ditunjukkan untuk menghasilkan program yang memperlihatkan perilaku persis diberikan dalam definisi bahasa; yaitu, kebenaran mereka dapat diverifikasi. spesifikasi lengkap dari sintaks dan semantik bahasa pemrograman dapat digunakan oleh alat untuk menghasilkan compiler untuk bahasa otomatis. Akhirnya, desainer bahasa, yang akan mengembangkan deskripsi semantik bahasa mereka, dalam proses dapat menemukan ambiguitas dan inkonsistensi dalam desain yang mereka buat.
14. Why can machine languages not be used to define statements in operational semantics? .
-> Karena langkah-langkah saat bahasa mesin dijalankan dan perubahan hasil dari keadaan mesin terlalu sedikit dan terlalu banyak.
15. Describe the two levels of uses of operational semantics.
->Natural operatioanl semantics, adalah tingkat tertinggi yang mengutamakan hasil akhir dari pelaksanaan program yang komplit. ->Structural operatioanl semantics, adalah tingkat terendah yang digunakan untuk menentukan arti sebenarnya dari sebuah program melalui pemeriksaan lengkap urutan perubahan keadaan yang terjadi ketika program dijalankan.
Problem Set
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. baab d. bbaab
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. abcd dan e. accc
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 ab, aaaabbbb, and aaaaaaaabbbbbbbb are in the language but a, abb, ba, and aaabb are not.
Answer: <S> => a<S>b || ab
14. Draw parse trees for the sentences aabb and aaaabbbb, as derived from
the grammar of Problem 13.
15. Convert the BNF of Example 3.1 to EBNF.
->
<program> -> begin <stmt_list> end
<stmt_list> -> stmt[stmt_list]
<stmt> -> <var> = <expressions>
<var> -> A| B | C
<expressions> -> <var> {(+|-)< var> }

Chapter 2 Pak Tri Djoko

Review Question
11. What control flow statements were added to Fortran IV to get Fortran 77?
-> Statement control flow yang ditambahkan di Fortran IV untuk menjadi Fortran 77 adalah Logical Loop (Logika pengulangan)
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?
-> Karena para ahli bahasa khawatir akan proses yang dilakukan oleh  bahasa alami
15. Where was LISP developed? By whom?
-> LISP dikembangkan oleh John McCarthy di MIT
Problem Set
11. Was IBM’s assumption, on which it based its decision to develop PL/I, correct, given the history of computers and language developments since 1964?
-> Asumsinya benar karena pada tahun 1970-an, PL / I secara luas digunakan untuk aplikasi bisnis dan ilmiah walaupun banyak kegagalan pada tahun-tahun sebelumnya dan sesudahnya.
12. Describe, in your own words, the concept of orthogonality in programming language design
->orthogonality adalah penyederhanaan dari bermacam-macam
fitur bahasa pemrograman sehingga suatu bahasa pemrograman lebih mudah untuk dipahami dan diaplikasikan
13. What is the primary reason why PL/I became more widely used than ALGOL 68?
->PL / I mempunyai ALGOL 60 yang terbaik (rekursi dan struktur blok), FORTRAN IV (kompilasi terpisah dengan komunikasi melalui data global), dan COBOL (struktur data, input / output, dan laporan fasilitas pembangkit), beberapa fitur baru
14. What are the arguments both for and against the idea of a typeless language?
-> Argumen “for” fleksibel dan mudah digunakan. Tanpa harus menentukan tipe data. programmer bebas untuk mengimprovisasikan kode yang dihasilkan dengan cepat dan tanpa banyak berpikir. Belajar bahasa jauh lebih simple karena kita tidak harus menentukan ukuran atau bagaimana compiler akan mengartikan tipe nantinya
Argumen “Against” kurang aman karena proses data, seperti penugasan tipe karakter ‘A’ yang sebenarnya dapat “diartikan” sebagai nilai HEX oleh programmer. Compiler juga akan mengalami kesulitan mengartikan nilai-nilai floating point dibandingkan dengan bilangan bulat. Aritmatika yang dihasilkan juga akan menyebabkan masalah serius; seperti menambahkan 5 + “happy” dan bagaimana mereka di terapkan berbeda dari yang dimaksud oleh programmer.
15. Are there any logic programming languages other than Prolog?
 -> FORTRAN, LISP,  dan ALGOL 60


Rabu, 01 Oktober 2014

Chapter 1

Review Questions

11. What primitive control statement is used to build more complicated control statements in languages that lack them?

Pemilihan Penggunaan "Selection" Dan  "Goto" yang dipakai dalam bahasa pemrograman  fungsinya sama seperti pengulangan ‘For’

12. What construct of a programming language provides process abstraction?

Subprograms

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

Program yang handal atau bagus adalah program yang mampu berjalan dalam kondisi apapun

14. Why is type checking the parameters of a subprogram important?   

Type checking sangat penting karena type checking bisa mendeteksi kesalahan sebelum kesalahan itu terjadi

15. What is aliasing?

Aliasing adalah meemperbolehkan dua nama atau lebih  yang berbeda untuk mengakses file yang sama





Problem Set
11. Describe some design trade-offs between efficiency and safety in some language you know

Dalam bahasa C sebuah elemen akan terus di periksa jadi walaupun tidak dibuat pengecualian, bahasa C ini akan break sendiri jadi lebih aman akan tapi prosesnya lebih lama karena mengulang-ngulang pemeriksaan berbeda dengan java yang tidak mengulangi pemeriksaan sehingga membuat java menjadi lebih efisien. Pada dasarnya tidak ada bahasa yang sempurna jadi masing-masing bahasa memiliki keunggulannya dan kelemahan.

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

Menurut saya bahasa pemrograman tidak ada yang sempurna karena memiliki kurangan kan kelebihan masing masing


13. Was the first high-level programming language you learned implemented with a pure interpreter, a hybrid implementation system, or a compiler? (You may have to research this.)


Saya pernah sedikit menggunakan Visual C++. Menurut sumber dari internet, Saya mendapati C++ merupakan compailer

14. Describe the advantages and disadvantages of some programming environment you have used.

Visual Basic merupakan Bahasa sederhana,Bahasa yang mudah untuk dipahami dan di konfigurasikan, visual basic juga merupakan bahasa pemrograman yang sangat populer di kalangan bahasa pemrograman, kekurangan dari bahasa visual basic adalah lebih lambat dari bahasa pemrograman yang lainnya dan juga tidak mempunyai database sendiri

15. How do type declaration statements for simple variables affect the readability of a language, considering that some languages do not require them?

Pendeklarasian (Penjelasan) tipe data dibutuhkan agar program mudah dibaca,dimengerti dan di aplikasikan ke dalam bahasa pemrograman. 
Contoh -> jika kita menuliskan nilai kebenaran dengan dan tanpa tipe data boolean, akan seperti ini
prime=true” (boolean) dan “prime=1″ (tanpa boolean).
Dengan contoh tersebut, kita dapat melihat jika dengan mendeklarasikan(menjelaskan) tipe data boolean, kita dapat dengan mudah mengerti maksud dan tujuan program tersebut dengan cara  membacanya.