Cari Blog Ini

Kamis, 30 Oktober 2014

Assignment #5 Konsep Bahasa Pemrograman Pak Tri Djoko Wahjono

Reyza Pratama Komala (1801428384) - LM01
Pada kesempatan kali ini saya akan menjawab soal-soal yang ada dalam buku "CONCEPTS OF Programming Languages (TENTH EDITION)" - ROBERT W. SEBESTA. Chapter 5 Names, Bindings, and Scopes

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.

Minggu, 26 Oktober 2014

Assignment #4 Konsep Bahasa Pemrograman Pak Tri Djoko Wahjono

Reyza Pratama Komala (1801428384) - LM01
Pada kesempatan kali ini saya akan menjawab soal-soal yang ada dalam buku "CONCEPTS OF Programming Languages (TENTH EDITION)" - ROBERT W. SEBESTA. Chapter 4 Lexical and Syntax Analysis

REVIEW QUESTION

11. Question : 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. Question : 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. Question : Why are named constants used, rather than numbers, for token codes ?
Answer :
- for the sake of readability of lexical and syntax analyzers.


14. Question : 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. Question : 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

Assignment #3 Konsep Bahasa Pemrograman Pak Tri Djoko Wahjono

Reyza Pratama Komala (1801428384) - LM01
Pada kesempatan kali ini saya akan menjawab soal-soal yang ada dalam buku "CONCEPTS OF Programming Languages (TENTH EDITION)" - ROBERT W. SEBESTA. Chapter 3 Describing Syntax and Semantics
Review Question

11. Question :  How is the order of evaluation of attributes determined for the trees of a
given attribute grammar ?

Answer : Semantik statis bahasa hanya secara tidak langsung terkait dengan makna program selama eksekusi; melainkan harus dilakukan dengan bentuk hukum dari program
(sintaks bukan semantik). Banyak aturan semantik statis bahasa menyatakan kendala jenisnya. Semantik statis dinamakan demikian karena analisis yang dibutuhkan untuk
memeriksa spesifikasi ini dapat dilakukan pada waktu kompilasi.
Semantik dinamis adalah makna ekspresi, pernyataan, dan unit program bahasa pemrograman.

12. Question :  What is the primary use of attribute grammars ?

Answer : Atribut tata bahasa utama yang digunakan untuk memberikan deskripsi lengkap sintaks dan semantik statis bahasa pemrograman.

13. Question :  Explain the primary uses of a methodology and notation for describing
the semantics of programming languages ?

Answer : Jika pemutusan lingkaran dapat ditampilkan, deskripsi aksiomatik loop disebut total kebenaran. Jika kondisi lain dapat dipenuhi tetapi terminasi tidak
dijamin, hal itu disebut correctnes parsial.

14. Question : Why can machine languages not be used to define statements in operational
semantics ?

Answer : Bahasa mesin tidak dapat digunakan untuk mendefinisikan pernyataan dalam semantik operasional karena beberapa masalah. Pertama, langkah-langkah individu dalam pelaksanaan mesin
bahasa dan perubahan yang dihasilkan pada keadaan mesin terlalu kecil dan terlalu banyak. Kedua, penyimpanan komputer yang nyata terlalu besar dan kompleks.

15. Question : Describe the two levels of uses of operational semantics ?

Answer : Pada tingkat tertinggi, yang menarik adalah di hasil akhir dari pelaksanaan program yang lengkap. Hal ini kadang-kadang disebut semantik operasional alami.
Pada tingkat terendah, semantik operasional dapat digunakan untuk menentukan makna yang tepat dari sebuah program melalui pemeriksaan urutan lengkap negara
perubahan yang terjadi ketika program dijalankan. Penggunaan ini kadang-kadang disebut semantik operasional struktural.

Problem Solve

11. Consider the following grammar:
<S> → <A> a <B> b
<A> → <A> b | b
<B> → a <B> | a
Question : Which of the following sentences are in the language generated by this
grammar ?
a. baab
b. bbbab
c. bbaaaaa
d. bbaab

Answer : 
<S> → <A> <B> <C>
<A> → a <A> | a
<B> → b <B> | b
<C> → c <C> | c

12. Consider the following grammar:
<S> → a <S> c <B> | <A> | b
<A> → c <A> | c
<B> → d | <A>
Question : Which of the following sentences are in the language generated by this
grammar?
a. abcd
b. acccbd
c. acccbcc
d. acd
e. accc

Answer : LHS non-terminal S didefinisikan sebagai non-terminal A, terminal, non-terminal B dan terminal b, di mana non-terminal A dapat nol atau lebih b atau satu b, dan di mana non-terminal B dapat menjadi salah satu atau lebih adalah satu atau a;

Menghasilkan satu atau lebih b atau satu b, satu, satu atau lebih atau satu, dan satu b.

13. Question :  
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>
<A> -> a <A> b <B>

14. Question : Draw parse trees for the sentences aabb and aaaabbbb, as derived from
the grammar of Problem 13 ?

Answer :
<stmt> -> <A>
<A> -> A <A> b | ab
pohon untuk aabb
pohon untuk aaaabbbb

15. Question : Convert the BNF of Example 3.1 to EBNF ?

Answer :
<program> -> begin <stmt_list> end

<stmt_list> -> <stmt>

| <stmt> ; <stmt_list>

<stmt> -> <var> = <expression>

<var> -> A | B | C

<expression> -> <var> {(+|-) <var>}

Assignment #2 Konsep Bahasa Pemrograman Pak Tri Djoko Wahjono

Reyza Pratama Komala (1801428384) - LM01

Pada kesempatan kali ini saya akan menjawab soal-soal yang ada dalam buku "CONCEPTS OF Programming Languages (TENTH EDITION)" - ROBERT W. SEBESTA. Chapter 2 Evolution of the Major Programming Languages

Review Question

11. Question : What control flow statements were added to FORTRAN IV to get FORTRAN 77 ?

Answer : Pernyataan logika loop

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

Answer : Yang pertama memiliki segala macam variabel dinamis FORTRAN 90 karena memiliki array dinamis, catatan, pointer, yang beberapa pernyataan seleksi, dan modul.

13. Question : Which version of FORTRAN was the first to have character string handling ?

Answer : FORTRAN pertama yang memiliki karakter penanganan string adalah FORTRAN 77.

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

Answer : Ini adalah ahli bahasa yang tertarik pada kecerdasan buatan karena linguistik yang berkaitan dengan pengolahan bahasa alami.

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

Answer : Jenis data yang berbeda dan struktur di Umum LISP adalah catatan, array, bilangan kompleks, dan karakter string. Ini juga memiliki bentuk paket untuk modularizing koleksi fungsi dan data yang menyediakan kontrol akses.

Problem Solve

11. Question : 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 ?

Answer : IBM adalah, untuk sebagian besar, salah dalam pandangannya tentang masa depan penggunaan komputer, setidaknya sejauh bahasa yang bersangkutan. Aplikasi komersial hampir semua dilakukan dalam bahasa yang secara khusus dirancang untuk mereka. Demikian juga untuk aplikasi ilmiah. Di sisi lain, desain IBM dari garis 360 komputer sukses-itu besar masih mendominasi bidang komputer antara superkomputer dan minicomputer. Selain itu, 360 komputer seri dan keturunan mereka telah banyak digunakan untuk aplikasi ilmiah dan komersial. Aplikasi ini telah dilakukan, sebagian besar, di Fortran dan COBOL.


12. Question : Describe, in your own words, the concept of orthogonality in programming
language design ?

Answer : Tampaknya ortogonal berarti kesederhanaan pemrograman konstruksi, atau jumlah minimal kontrol dan struktur data dalam suatu bahasa. Setiap membangun tambahan meningkatkan kompleksitas, menghapus orthogonality.

13. Question : What is the primary reason why PL/I became more widely used than
ALGOL 68 ?

Answer : PL / I termasuk yang terbaik dari ALGOL 60 (rekursi dan struktur blok), FORTRAN IV (kompilasi terpisah dengan komunikasi melalui data global), dan COBOL (struktur data, input / output, dan laporan fasilitas pembangkit), bersama dengan konstruksi baru beberapa

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

Answer : Argumen untuk bahasa typeless adalah fleksibilitas mereka besar untuk programmer. Secara harfiah setiap lokasi penyimpanan dapat digunakan untuk menyimpan nilai tipe. Hal ini berguna untuk bahasa tingkat rendah yang digunakan untuk pemrograman sistem. Kekurangannya adalah bahwa jenis pemeriksaan tidak mungkin, sehingga sepenuhnya tanggung jawab programmer untuk memastikan bahwa ekspresi dan tugas sudah benar.

15. Question : Are there any logic programming languages other than Prolog ?

Answer : FORTRAN, LISP, ALGOL 60

Rabu, 01 Oktober 2014

Assignment #1 Konsep Bahasa Pemrograman Pak Tri Djoko Wahjono

Reyza Pratama Komala (1801428384) - LM01

Pada kesempatan kali ini saya akan menjawab soal-soal yang ada dalam buku "CONCEPTS OF Programming Languages (TENTH EDITION)" - ROBERT W. SEBESTA. Chapter 1 Preliminaries

Review Question

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

Answer : The selection statement plus GOTO is used to build more complicated control statements such as FOR loop.

12. Question : What construct of programing language provides process abstraction ?

Answer : Subprograms

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

Answer : Program is said to be reliable if it performs to its specifications under all conditions.

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

Answer : It can lead to lots of hard to debug errors. One example of how failure to type check, at either compile time or runtime, has led to countless program errors is the use of subprogram parameters in the original C language

15. Question : What is aliasing ?

Answer : Aliasing describes a situation in which a data location in memory can be accessed through different symbolic names in the program

Problem Set

11. Question : Describe some design trade-offs between efficiency and safety in some language you know ?

Answer : C today is what assembly language was 10 or 15 years ago. It's the language you use when efficiency or low level access to hardware really matters to you. You can, of course, still use assembly language today. But optimizing C/C++ compilers are so good today, that they can often trump hand coded assembly language.
So C is very fast, and very good for low level, hardware level access. Do you need those features? Let's assume you aren't writing device drivers, so you don't need hardware access. It's all about speed.

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

Answer : High-level of abstraction with low-level efficiency. Such languages already exist, but none are "perfect" in every situation. That's one of the reasons we have so many languages at our disposal. It would be impractical to combine them into a single language, you simply choose the best tool for the job at hand.

13. Question : 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.)

Answer : The programming language is C. It was implemented with a compiler.

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

Answer : C++ - Best suited for general purpose and low level programming.
Advantages: Extremely fast, works very well for GUI programming on a computer. Good language to write operating systems, drivers, and platform dependent applications with. Good language to learn to program with. Good language for engineers.
Disadvantages: Although it is platform independent, it is mostly used for platform specific applications. A library set is usually chosen that locks you into a single platform or operating system. Overly complex for very large high level programs. Overly complex and difficult to debug when used for web applications. Marketable skills are low level programming, vendor software, and video games, making it difficult to find jobs unless you have are very advanced in a target area.

VB - Used mainly to modify and complement the Microsoft product line.
Advantages: Extremely easy to use, even for people who are not computer programmers. Allows the typical computer user to modify MS Office applications to suite their needs. Works very well on a Microsoft intranet to complement the network shares and permissions. Can be used for low level programming on Microsoft computers. A marketable skill set. Excellent for writing little programs and pieces of programs.
Disadvantages: Completely locks you into using the Microsoft product line. Not a true Object oriented language although it claims to be. VB .Net is an object oriented language. Becomes overly complex and difficult to manage on very large programs.

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

Answer : The use of type declaration statements for simple scalar variables may have very little effect on the readability of programs. If a language has no type declarations at all, it may be an aid to readability, because regardless of where a variable is seen in the program text, its type can be determined without looking elsewhere. Unfortunately, most languages that allow implicitly declared variables also include explicit declarations. In a program in such a language, the declaration of a variable must be found before the reader can determine the type of that variable when it is used in the program.