Binus Alam Sutera

Binus Alam Sutera

Sunday, May 31, 2015

CB2:Kewarganegaraan Project part 4 - Mathematic Thursday shift 2 (13.00 - 13.45)

Nama : Christian Gunawan
NIM : 1801384174
Hari/Tanggal : Kamis, 28 May 2015, Shift 2 (13.00 - 13.45)

Kegiatan yang dilakukan :

Pada shift kedua hari kamis ini, kami masih melanjutkan materi dari shift sebelumnya, namun kali ini diperdalam lagi hingga dapat disesuaikan dengan materi kelas 5 SD yang akhir - akhir ini diajarkan pada pembelajaran sebelumnya. Setelah murid - murid selesai mengerjakan kertas soal yang kami berikan, lalu para murid kami tuntun dengan pembahasan dari masing - masing soal, sehingga mereka dapat mengerti soal - soal yang mereka belum terlalu pahami. Salah satu yang tersusah adalah soal yang mengenai skala jarak pada peta dan jarak sesungguhnya.

Kemudian seperti yang kami janjikan sebelumnya, 3 murid pertama yang dapat mengerjakan soal paling cepat dan seluruh jawabannya benar, akan kami berikan 3 hadiah pertama yang telah disiapkan oleh salah satu teman kami. Hal tersebut ditujukan untuk memacu pembelajaran mereka. Salah satu yang mendapatkan hadiah tersebut adalah Kareem, seorang murid cerdas yang selalu meraih salah satu peringkat tertinggi dikelasnya.

Setelah pembelajaran dan pembahasan telah usai, tidak lupa kami membantu murid - murid yang mendapatkan jadwal piket pada hari tersebut. Dan akhirnya kami semua baru selesai melakukan bersih - bersih pada jam 2 lewat. Sungguh besar semangat mereka belajar sampai rela pulang lebih lama 2 jam dari jam sekolah biasanya.

Sebelum kami pulang, kami mengucapkan terima kasih kepada pihak sekolah dan kepada Pak Wanta yang sudah mengizinkan kami untuk mengajar mereka walaupun hanya untuk sebentar saja. tidak lupa kami juga mendokumentasikan foto kami dengan beberapa murid beserta Pak Wanta. Dan akhirnya selesailah proses pengajaran project kami.
















Materi yang diajarkan :

Di shift terakhir kami, kami memberikan materi yang lebih diperdalam lagi, yaitu soal - soal tentang cara menggambar bangun ruang balok, menghitung volume balok, penjumlahan pengurangan pecahan desimal, cara menggambar lingkaran dan sifat - sifatnya, kemudian menghitung luas lingkaran tersebut. Lalu dilanjutkan dengan pembahasan dari masing - masing soal agar mereka lebih mengerti lagi, dan kami ajarkan cara yang lebih cepat dari metode biasa yang mereka pakai sebelumnya agar dikemudian hari mereka dapat mengerjakan soal dengan lebih efisien.













Pengalaman berkesan :

Pengalaman berkesan yang saya dapatkan dari seluruh kegiatan project ini adalah, meskipun mereka memiliki keterbatasan materi dan lingkungan yang kurang baik, mereka tetap ingin belajar lebih lagi. Hal tersebut merupakan contoh yang sangat baik. Kemudian saat kami mengucapkan salam terakhir kali pada murid - murid kami, mereka tetap mengharapkan kami untuk datang kembali suatu saat dikemudian hari, untuk mengajar mereka lagi. Kami pun kemudian berencana untuk kembali mengunjungi mereka suatu saat nanti.

CB2:Kewarganegaraan Project part 3 - Mathematic Thursday shift 1 (12.20 - 13.00)

Nama : Christian Gunawan
NIM : 1801384174
Hari/Tanggal : Kamis, 28 May 2015, Shift 1 (12.20 - 13.00)

Kegiatan yang dilakukan :

Pada hari kamis ini, kami mengambil shift pertama yang dimulai setelah pulang sekolah jam 12 hingga jam 1 siang. Hal ini ditujukan agar kami tidak menganggu jam pelajaran sekolah, dan memberikan pengetahuan lebih diluar jam pelajaran. Meskipun setelah jam pulang sekolah, murid - murid tetap menunggu kedatangan kami, dan mereka rela menghabiskan waktu bersama kami untuk belajar lebih dalam lagi di pelajaran matematika. Sebelum kami masuk kekelas, tidak lupa kami menyapa guru - guru dan kepala sekolah yang sedang berada di ruang guru. Dan setelah itu baru kami bertemu dengan Pak Wanta yang sedang mengajar di kelas 2 SD, untuk kemudian mengantarkan kami lagi ke kelas 5.

Kemudian kami memulai pembelajaran, kali ini kami sudah mempersiapkan kertas berisikan soal - soal. Materi perkalian dirasa perlu diberikan karena pada pembelajaran sebelumnya, masih ada beberapa anak yang masih belum dapat menguasai materi perkalian dan pembagian tersebut. Tidak hanya itu, kami memberikan sejumlah hadiah berupa Botol minum / Tempat makanan yang telah disediakan oleh salah satu teman kami, Helena. Hal ini untuk memancing niat belajar murid agar mereka cepat dan lebih terdorong untuk menyelesaikan soal - soal yang kami berikan.

Materi yang diajarkan :

5 soal pertama yang diberikan adalah tentang materi dari penjumlahan / pengubahan pecahan, lalu perkalian 2 pecahan desimal, penjumlahan pecahan desimal, soal cerita tentang perkalian dan penjumlahan, dan ukuran jarak peta dengan jarak sesungguhnya.

Sejumlah materi yang diberikan adalah materi dasar, yang dirasa diperlukan oleh murid - murid berdasarkan hasil ambil nilai pada pembelajaran sebelumnya, beberapa anak masih belum dapat menguasai materi perkalian dan pembagian. Sehingga kami memutuskan untuk mengajarkan materi dasar untuk memperkuat fondasi / dasar mereka yang akan berguna sampai nanti dewasa dikemudian hari.
















Pengalaman berkesan

Pengalaman berkesan hari ini adalah meskipun mereka sudah pulang sekolah, dan seharusnya boleh pulang cepat, ternyata tidak ada satupun dari mereka yang pulang terlebih dahulu, bahkan mereka menyisakan waktunya untuk belajar lebih lagi bersama kami. Hal seperti ini sudah jarang ditemukan bila dikota besar / di sekolah - sekolah swasta lainnya. Menurut saya hal - hal kecil seperti ini haruslah dijaga, dan pasti akan berguna di suatu hari nanti.

CB2:Kewarganegaraan Project part 2 - Mathematic shift 2 (11.25 - 12.05)

Nama : Christian Gunawan
NIM : 1801384174
Hari/Tanggal : Selasa, 26 May 2015, Shift 2 (11.25 - 12.05 [Pulang Sekolah])

Kegiatan yang dilakukan :

Pada shift kedua hari selasa ini, kami melanjutkan kegiatan belajar mengajar hingga nanti pulang sekolah. Murid - murid SDN Panunggangan 11 mulai terbiasa dengan cara mengajar kami, kami sebelumnya akan meminta murid untuk mencatat materi terlebih dahulu, lalu kami berlima akan berkeliling untuk membantu murid - murid yang kurang pandai menggambar bangun ruang, dan membantu mereka untuk mencatat agar pembelajaran lebih efisien.

Kemudian, setelah itu, kami akan memberikan beberapa soal latihan / soal materi yang sudah diberikan sebelumnya, agar mereka dapat mengingat dan mengetahui jenis - jenis soal. Dari hasil pembelajaran, kami menemukan ada beberapa murid yang pandai dan cepat mencerna materi dengan mudah, dan mereka sangat antusias dalam proses belajar mengajar dan ada juga beberapa murid yang masih dapat dibilang nakal dan jahil pada saat proses pembelajaran. Rata - rata dari mereka banyak yang masih belum menguasai teknik dasar perkalian dan pembagian sehingga proses pembelajaran tidak dapat dilakukan dengan cepat.

Setelah pembelajaran, lalu pulang sekolah, kami membantu murid - murid yang bertugas piket pada hari tersebut. Ruangan mereka sangat kotor dan kotoran dimana - mana. Mungkin ruangan tersebut sudah lama tidak dibersihkan oleh pihak sekolah, dan hanya mengandalkan piket dari murid - murid yang bertugas saja.












Materi yang diajarkan :

Pada shift kedua ini, materi yang kami ajarkan adalah sifat - sifat bangun ruang kerucut dan limas segi empat. setelah murid - murid selesai mencatat sifat - sifat materi yang kami berikan, kemudian kami melakukan beberapa tes soal dengan rumus dari bangun ruang tersebut, untuk melihat sejauh mana murid - murid sudah menangkap materi pelajaran ini. Kemudian sebelum pulang sekolah, kami berlima mengajukan 1 soal untuk diambil nilai, yaitu tentang volume bangun ruang kubus, materi kubus sangatlah mudah, karena hanya perkalian saja, tetapi meskipun begitu, masih banyak murid yang masih salah hitung, dan ada yang belum tahu rumus dari bangun ruang tersebut.


Pengalaman berkesan :

Pengalaman berkesan kali ini muncul saat selesai kegiatan sekolah, saya pribadi mengira kami akan langsung meninggalkan ruangan langsung, dan murid - murid pulang. Ternyata tidak, murid - murid diajarkan untuk selalu membersihkan kelas sebelum pulang sekolah agar kelas tidak terlalu kotor. Walaupun yang ditugaskan adalah mereka yang terdaftar pada jadwal piket saja, tetapi tentu saja hal ini adalah hal yang baik untuk menciptakan karakter murid - murid di kemudian hari, terutama saat sudah dewasa. Sungguh kebiasaan yang patut untuk ditiru bagi sekolah - sekolah lain.


Saturday, May 30, 2015

CB2:Kewarganegaraan Project part 1 - Mathematic shift 1 (10.45 - 11.25)

Nama : Christian Gunawan
NIM : 1801384174
Hari/Tanggal : Selasa, 26 May 2015, Shift 1 (10.45 - 11.25)

Pada kesempatan yang diberikan oleh program CB2:Kewarganegaraan kali ini, kami berlima melakukan kegiatan belajar-mengajar untuk Sekolah Dasar kelas 5 di SDN Panunggangan 11 yang terletak tidak jauh dari BINUS, tepatnya terletak di Jl. Kyai Maja, Kota Tangerang, Kota Tgr., Indonesia 15143.

Meskipun sekolah ini terletak tidak jauh dari Alam Sutera yang berupa daerah penuh mewah, tetapi bila kita pergi keluar wilayah Alam Sutera sedikit saja, kita sudah dapat menemukan pemukiman yang masih dapat dibilang sederhana, contohnya adalah sekolah gratis dimana kami mengajar. Sebelumnya sekolah ini adalah sekolah yang tidak gratis, namun ketika sekolah ini diubah menjadi sekolah gratis, kebersihan dan perawatan gedung pun lama - kelamaan terkikis oleh waktu.



Kegiatan yang dilakukan :

Pertama - tama kami menuju ke ruang kepala sekolah terlebih dahulu, untuk bertemu dengan salah satu guru yang mengajar di sekolah tersebut, yang sebelumnya sudah kami kontak, yaitu Pak Wanta. Kami ingin memastikan dan menyerahkan surat izin yang sudah disetujui oleh pihak Binus dan dosen mata kuliah CB2: Kewarganegaraan kami, Pak Dalmeri. Setelah itu kami semua di briefing terlebih dahulu oleh Pak Wanta, untuk bahan pelajaran pada hari tersebut, yaitu Matematika. Pak Wanta sangat menerima kami dengan baik dan tulus, sehingga beliau memperbolehkan kami mengajar tanpa adanya prosedur yang rumit.

Lalu kemudian kami diajak menuju ruang kelas 5 SD dimana kami akan mengajar. Anak - anak tampak bingung pada saat pertama kami memasuki ruangan kelas. Kemudian kamipun memperkenalkan diri kami terlebih dahulu sebelumnya, dan barulah setelah itu kami memulai kegiatan belajar - mengajar.

Materi yang diajarkan :

Pada shift kali ini, kami berlima mengajarkan salah satu materi bangun ruang, lebih spesifiknya, kami mengajarkan sifat - sifat bangun ruang tabung untuk dicatat pada buku catatan murid, setelah itu, memberikan beberapa pertanyaan tentang materi tersebut.



Pengalaman berkesan :

Pengalaman berkesan pada shift kali ini adalah pada saat kami memasuki ruangan kelas tersebut, kami mengira tadinya kami tidak akan terlalu diterima oleh murid - murid di sekolah ini, tetapi ternyata mereka sangat antusias dan menerima kami dengan baik.


Monday, March 16, 2015

Run For Leprosy Event !!

Nama : Christian Gunawan
NIM : 1801384174

Nomor Peserta Lari : 5523

Jurusan : Teknik Informatika 2nd Semester

Hari Minggu 15 Maret 2015, saya mengikuti Charity Event Run For Leprosy yang diadakan oleh Teach For Indonesia yang didukung oleh Universitas Bina Nusantara. Acara ini juga didukung oleh banyak sponsor yang akhirnya berhasil mensukseskan segala rangkaian acara yang telah disusun. Acara ini diselenggarakan untuk membantu mencari dana yang akan diserahkan pada para penderita penyakit kusta (Leprosy) dan serta memberikan pengetahuan tentang kusta. Dalam acara ini, juga diramaikan oleh banyak hiburan, mulai dari Music Performance, Stand - stand sponsor. Para peserta didominasi oleh generasi muda dan mahasiswa Binus University yang sangat antusias untuk mengikuti acara ini.

Saya sendiri mengikuti acara ini bersama dengan 13 teman saya yang lain, membuat 1 grup yang dipimpin oleh Billy Darmawan (5521). Untuk mengikuti acara ini, saya dan 4 teman saya yang lainnya juga menginap disebuah apartemen dekat Binus agar tidak terlambat hadir pada saat acara. Pagi - pagi kami sudah bangun untuk menyiapkan segala perlengkapan yang diperlukan untuk mengikuti acara Run For Leprosy ini. Sesampainya kami di Binus pada pukul setengah 6 pagi hari, sudah banyak orang berkumpul, setelah sambutan dari host panitia, kamipun mengantri di halaman parkir Binus, siap untuk memulai kegiatan lari ini. Hampir 8000 peserta memenuhi antrian dan akhirnya acara ini pun dimulai. 

Acara ini sungguh tersusun dengan rapi, sehingga tidak ada masalah yang serius terjadi pada saat acara. Dan banyak panitia juga yang siap di sepanjang jalan untuk menyemangati dan memberikan minuman untuk kami menambah energi lagi. Meskipun lelah, dan sangat ramai, tapi kami sungguh menikmati dan semangat berlari hingga garis finish. Saya hanya dapat menempuh lintasan dalam waktu 46 menit, tetapi pengalaman ini sungguh berkesan untuk saya dan teman - teman saya.












Pesan dari saya mungkin panitia harus lebih bisa meminimalisir kesalahan - kesalahan kecil pada penyusunan attribute / race pack pelari, karena beberapa dari teman saya, ada yang tidak mendapatkan baju ukuran XL sehingga harus memaksakan memakai baju ukuran L, lalu saya sendiri juga mengalami hal yang sama, Tas race pack saya hanya memiliki 1 tali sehingga tidak memungkinkan saya untuk membawa tas tersebut pada saat saya membutuhkannya. Lalu panitia juga seharusnya lebih mengenalkan sosialisasi penyakit kusta pada saat acara, sehingga para peserta pun menjadi lebih tahu lagi. Meskipun begitu, overall acara ini sudah berjalan dengan baik dan lancar, sehingga saya cukup puas akan hal tersebut.


Berikut merupakan pengetahuan tentang penyakit kusta :

Penyakit kusta atau juga dikenali sebagai penyakit Hansen dan juga Leprosy, merupakan penyakit berjangkit yang disebabkan oleh Mycobacterium Leprae. Nama penyakit Hansen datang daripada orang yang menjumpai Mycobacterium leprae, G.A.Hansen. Pengidap penyakit Hansen biasanya dipanggil pesakit kusta atau dalam bahasa Inggeris lepers, walaupun penggunaan istilah lepers semakin ditinggalkan kerana jumlah pesakit yang berkurangan dan sebagai mengelak stigma buruk yang dikaitkan dengan pesakit kusta.

Kusta merupakan penyakit menahun yang menyerang syaraf tepi, kulit dan organ tubuh manusia yang dalam jangka panjang mengakibatkan sebagian anggota tubuh penderita tidak dapat berfungsi sebagaimana mestinya. Meskipun infeksius, tetapi derajat infektivitasnya rendah. Waktu inkubasinya panjang, mungkin beberapa tahun, dan tampaknya kebanyakan pasien mendapatkan infeksi sewaktu masa kanak-kanak.



Meskipun cara penularannya yang pasti belum diketahui dengan jelas, penularan di dalam rumah tangga dan kontak/hubungan dekat dalam waktu yang lama tampaknya sangat berperan dalam penularan kusta.Cara-cara penularan penyakit kusta sampai saat ini masih merupakan tanda tanya. Yang diketahui hanya pintu keluar kuman kusta dari tubuh si penderita, yakni selaput lendir hidung. Tetapi ada yang mengatakan bahwa penularan penyakit kusta adalah melalui sekresi hidung, basil yang berasal dari sekresi hidung penderita yang sudah mengering, diluar masih dapat hidup 2–7 x 24 jam. Kontak kulit dengan kulit. Syarat-syaratnya adalah harus dibawah umur 15 tahun, keduanya harus ada lesi baik mikoskopis maupun makroskopis, dan adanya kontak yang lama dan berulang-ulang.

Tanda-tanda seseorang menderita penyakit kusta antara lain, kulit mengalami bercak putih, merah, ada bagian tubuh tidak berkeringat, rasa kesemutan pada anggota badan atau bagian raut muka, dan mati rasa karena kerusakan syaraf tepi. Gejalanya memang tidak selalu tampak. Justru sebaiknya waspada jika ada anggota keluarga yang menderita luka tak kunjung sembuh dalam jangka waktu lama. Juga bila luka ditekan dengan jari tidak terasa sakit.

Kelompok yang berisiko tinggi terkena kusta adalah yang tinggal di daerah endemik dengan kondisi yang buruk seperti tempat tidur yang tidak memadai, air yang tidak bersih, asupan gizi yang buruk, dan adanya penyertaan penyakit lain seperti HIV yang dapat menekan sistem imun. Pria memiliki tingkat terkena kusta dua kali lebih tinggi dari wanita.


Komitmen Saya terhadap Kusta :

  1. Saya akan selalu mendukung program - program yang dilakukan oleh organisasi - organisasi untuk membantu teman - teman kita yang terkena penyakit kusta.
  2. Saya akan berusaha mengurangi beban dan penderitaan penderita kusta dengan berbagai usaha dan aksi nyata.
  3. Kita tidak seharusnya membiarkan mereka yang diluar sana terjangkit penyakit kusta semakin menderita dan tidak ada yang mempedulikan mereka, kita harus memulai aksi seperti acara Run For Leprosy ini untuk membantu meringankan penderitaan mereka.
  4. Saya akan berusaha untuk mensosialisasikan penyakit ini kepada orang - orang yang belum mengetahui lebih jelas lagi tentang penyakit ini, sehingga dapat lebih mengetahui dan bisa membantu mereka yang terjangkit penyakit kusta.

Saran saya untuk sosialisasi yang baik terhadap penyakit kusta : 

Tentunya dengan menyelenggarakan lebih banyak lagi acara seperti Run For Leprosy ini, ditambah dengan ide - ide yang menarik sehingga kita dapat meringankan beban mereka yang terkena panyakit ini. Dengan memberikan mereka perhatian dan bantuan yang cukup, menurut saya itu sangatlah berarti untuk mereka.

Selain itu, dapat juga diadakan seminar pengetahuan penyakit kusta juga, baik terhadap orang - orang yang belum tahu, ataupun orang - orang yang terkena penyakit itu sendiri. Kita harus mengajarkan bagaimana mereka dapat tetap berkontribusi dalam kemasyarakatan, bukan semakin terpuruk dimakan waktu.

Tuesday, February 3, 2015

Chapter 13 Answers

Nama: Christian Gunawan
NIM: 1801384174

Kali ini saya akan menjawab Assignment #13 dari Chapter 13 Programming Language Concepts R Sebesta :


Review Questions #6-10 :

6. Describe the logical architecture of a vector processor.

Vector processor have groups of registers that store the operands of a vector operation in which the same instruction is executed on the whole group of operands simultaneously. Originally, the kinds of programs that could most benefit from this architecture were in scientific computation, an area of computing that is often the target of multiprocessor machines.


7. What is the difference between physical and logical concurrency?

Physical concurrency – Multiple independent processors (multiple threads of control)
Logical concurrency – The appearance of physical concurrency is presented by time-sharing one processor (software can be designed as if there were multiple threads of control)


8. What is a thread of control in a program?

A thread of control in a program is the sequence of program points reached as control flows through the program.


9. Why are coroutines called quasi-concurrent?
Because they have a single thread of control.


10. What is a multithreaded program?
A program designed to have more than one thread of control.


Problem Set #6-10 :

6. Suppose two tasks, A and B, must use the shared variable Buf_Size. Task A adds 2 to Buf_Size, and task B subtracts 1 from it. Assume that such arithmetic operations are done by the three-step process of fetching the current value, performing the arithmetic, and putting the new value back. In the absence of competition synchronization, what sequences of events are possible and what values result from these operations? Assume that the initial value of Buf_Size is 6.
The idea here is that the add and subtract operations are not atomic, and could be interrupted in mid-operation, when the other task could then run. If A runs to completion, then B runs to completion, Buf_Size has the value 7 (6 + 2 – 1). Similarly if B runs to completion then A runs to completion. If A or B get interrupted in the middle of adding or subtracting, then whichever task finishes last will determine the value in Buf_Size. If A runs but is interrupted after it fetches Buf_Size but before it stores the modified value (allowing B to fetch Buf_Size), or if B runs first and is interrupted after the fetch but before the store, allowing A to fetch Buf_Size, then if A finishes last Buf_Size will have value 8, and if B finishes last Buf_Size will have value 5.


7. Compare the Java competition synchronization mechanism with that of Ada.
Java methods (but not constructors) can be specified to be synchronized. A synchronized method called through a specific object must complete its execu- tion before any other synchronized method can run on that object. Competition synchronization on an object is implemented by specifying that the methods that access shared data are synchronized.
The competition synchronization mechanism of the Ada Language is intended to provide a facility for tasks to synchronize their actions. Accept and select statements are the two main features of the language that deal with the issue of synchronization This paper points out one major problem that arises in connection with these features and proposes a possible solution to it.


8. Compare the Java cooperation synchronization mechanism with that of Ada.
Cooperation synchronization in Java is implemented with the wait, notify, and notifyAll methods, all of which are defined in Object, the root class of all Java classes. All classes except Object inherit these methods. Every object has a wait list of all of the threads that have called wait on the object.
In Ada, cooperation synchronization is required between two tasks that when the second task must wait for the first task to finish executing before it may proceed.


9. What happens if a monitor procedure calls another procedure in the same monitor?
Because the access mechanisms are part of the monitor, implementation of a monitor can be made to guarantee synchro- nized access by allowing only one access at a time. Calls to monitor procedures are implicitly blocked and stored in a queue if the monitor is busy at the time of the call.


10. Explain the relative safety of cooperation synchronization using semaphores and using Ada’s when clauses in tasks.
As soon as we start using concurrent threads, we need to think about various issues that fall under the broad description of thread safety. Generally, we need to take steps to make sure that different threads don't interact in negative ways:
-if one thread is operating on some data or structure, we don't want another thread to simultaneously operate on that same data/structure and corrupt the results;
-when Thread A writes to a variable that Thread B accesses, we need to make sure that Thread B will actually see the value written by Thread A;

-we don't want one thread to hog, take or lock for too long a resource that other threads need in order to make progress.

Sunday, January 25, 2015

Chapter 12 Answers

Nama: Christian Gunawan
NIM: 1801384174

Kali ini saya akan menjawab Assignment #12 dari Chapter 12 Programming Language Concepts R Sebesta :

Review Questions #6-10 :

6. Describe a situation where dynamic binding is a great advantage over its absence.

There is a base class, A, that defines a method draw that draws some figure associated with the base class. A second class, B, is defined as a subclass of A. Objects of this new class also need a draw method that is like that provided by A but a bit different. With overriding, we can directly modify B’s draw function. But without it, we either make a specific function in A for B and inherit it.


7. What is a virtual method?

A virtual method is a declared class method that allows overriding by a method with the same derived class signature. Virtual methods are tools used to implement the polymorphism feature of an object-oriented language, such as C#. When a virtual object instance method is invoked, the method to be called is determined based on the object's runtime type, which is usually that of the most derived class.


8. What is an abstract method? What is an abstract class?

An abstract method is a method which all descendant classes should have. An abstract class is a class which has abstract method.


9. Describe briefly the eight design issues used in this chapter for object-oriented languages.
-What non-objects are in the language?
-Are Subclasses Subtypes? If so, derived objects can be legally used wherever a parent object could be used.
-Type Checking and Polymorphism
-Single and Multiple Inheritance. Inherit from 1 (or more than 1) parent.
-Object Allocation and Deallocation. Are objects allocated from heap or stack.
-Dynamic and Static Binding. When are messages bound to methods, before or during run-time?
-Nested Classes. Can a class be nested inside another class?
-Initialization of Objects. Are objs init'd when created? Implicit or explicit?


10. What is a nesting class?

A nesting class is a class defined inside another class.


Problem Set #6-10 :

6. Compare the multiple inheritance of C++ with that provided by interfaces in Java.

C++ inheritance is implementation inheritance. That is, a class inheriting from two of more superclasses actually inherits the code from those classes. Java’s interface mechanism is an interface inheritance. That is, a class implementing two or more interfaces simply inherits (and must provide its own implementations for) the methods of the interface.


7. What is one programming situation where multiple inheritance has a significant advantage over interfaces?

When two or more parent classes are derived from one grandparent class and has one child (diamond problem).


8. Explain the two problems with abstract data types that are ameliorated by inheritance.
The problems solved are reusability of code and "extensibility". Reusability because one won't have to copy/paste his code from one data type to another, allowing for a greater readability. Extensibility because a method can accept a certain class as an argument, and get a child class of this one. This will allow the user to have a wider set of functionality, but the method will still be able to know that the entities it relies on are present.


9. Describe the categories of changes that a subclass can make to its parent class.
Subclasses can add things (variables, methods). Subclass in C++ can effectively remove a method using "private" inheritance. Inherited methods can be overridden.


10. Explain one disadvantage of inheritance.

Language & implementation complexity. The shared inheritance problem of multiple inheritance. Subclass is dependent upon its base class (which might change over time).

Chapter 11 Answers


Nama: Christian Gunawan
NIM: 1801384174

Kali ini saya akan menjawab Assignment #11 dari Chapter 11 Programming Language Concepts R Sebesta :

Review Questions #6-10 :

6. Explain how information hiding is provided in an Ada package.

There are two approaches to hiding the representation from clients in the package specification. The first one is to include two sections in the package specification, the second one is in which entities are visible to clients and one that hides its contents.

7. To what is the private part of an Ada package specification visible?

The private part of an Ada package specification is visible to the compiler but not to the client programs.


8. What is the difference between private and limited private types in Ada?

Private types have built-in operations for assignment and comparison. Limited private types don’t have built-in operations.


9. What is in an Ada package specification? What about a body package?

Package specification, is an Ada package which provides the interface of the encapsulation (and perhaps more). Body package, is an Ada package which provides the implementation of most, if not all, of the entities named in the associated package specification.


10. What is the use of the Ada with clause?

The use of Ada with clause is to make the names defined in external packages visible.


Problem Set #6-10 :

6. Discuss the advantages of C# properties, relative to writing accessor methods in C++ or Java.
One of the advantage of C# properties relative writing accessor methods in C++ or Java is it can control access to the fields.


7. Explain the dangers of C’s approach to encapsulation.

The main problem is that the biggest part of encapsulation is done via hidding, rather than protection. This hidding is achieved through definition hidding: a header file is preprocessed (which is a synonym for copy-pasted) into the implementation file. Anyone with this header file will be able to access any method or public variable of a the client related to the header, left appart any "static" method / variable. Static is actually the only rue level of protection here, as it's the only one that another unit (file) would not be able to access even if it's aware of it's existence. This whole "protection-is-name-hiding" approach leads to a load of problems: you can access a symbol using the wrong datatype and your compiler will happily do so. To protect critical parts, you should rely on text being hidden from the compiler while it's processing certain units (via #ifdef / #define).


8. Why didn’t C++ eliminate the problems discussed in Problem 7?

It didn't eliminate the problem because it evolved from C. Hence, it kept a lot of backward compatibility, and the same way of doing basic things. While some problems where solved (like the protected access, which is in-between normal and static in C), some stay, as the symbol access using wrong datatype (inherent to the linker, which doesn't do type-checking).


9. What are the advantages and disadvantages of the Objective-C approach to syntactically distinguishing class methods from instance methods?

Instance methods use an instance of a class, whereas a class method can be used with just the class name. A class is like the blueprint of a house: You only have one blueprint and (usually) you can't do that much with the blueprint alone. An instance (or an object) is the actual house that you build based on the blueprint: You can build lots of houses from the same blueprint. You can then paint the walls a different color in each of the houses, just as you can independently change the properties of each instance of a class without affecting the other instances.


10. In what ways are the method calls in C++ more or less readable than those of Objective-C?

In Objective C, all method calls are essentially virtual. This makes it a bit easier on the programmer, but it comes at a possible performance decrease. So sometimes methods call in C++ can be more or less readable than those of Objective-C.

Saturday, January 10, 2015

Chapter 10 Answers

Nama: Christian Gunawan
NIM: 1801384174

Kali ini saya akan menjawab Assignment #10 dari Chapter 10 Programming Language Concepts R Sebesta :

Review Questions#6-10 :

6. What is the difference between an activation record and an activation record instance?

*An activation record is the format, or layout, of the moncode part of a subprogram. An activation record instance is a concrete example of an activation record, a collection of data in the form of an activation record.


7. Why are the return address, dynamic link, and parameters placed in the bottom of the activation record?

*It's because the entry must appear first.


8. What kind of machines often use registers to pass parameters?

*RISC Machines often use registers to pass parameters.


9. What are the two steps in locating a nonlocal variable in a static-scoped language with stack-dynamic local variables and nested subprograms?

*First step, find correct activation record (the harder part) and then the second step is determine the offset within that activation record (easy part).


10. Define static chain, static_depth, nesting_depth, and chain_offset.

*Static chain is chain of static links connecting an activation record to all of it's static ancestors (it's enclosing subprograms).
Static depth is depth of the nesting for each enclosing static scope.
Nesting depth is the difference between the static depth of the reference and that of the scope where it was declared.
Chain offset is same as nesting depth.


Problem Set #6-10 :

6. Although local variables in Java methods are dynamically allocated at the beginning of each activation, under what circumstances could the value of a local variable in a particular activation retain the value of the previous activation?

*Each activation allocates variables in exactly the same order. Variables are not initialized to any value unless the program contains an initialization statement for the variable – they simply have whatever value is stored in the location they are allocated. If a procedure finishes executing, returns, and is immediately reinvoked, a variable would be assigned the same stack location it had on the previous invocation, and would have the last value from that previous invocation.


7. It is stated in this chapter that when nonlocal variables are accessed in a dynamic-scoped language using the dynamic chain, variable names must be stored in the activation records with the values. If this were actually done, every nonlocal access would require a sequence of costly string comparisons on names. Design an alternative to these string comparisons that would be faster.

*Using approach that uses an auxiliary data structure called a display. Or, to write variable names as integers. These integers act like an array. So when the activation happens, the comparisons will be faster.


8. Pascal allows gotos with nonlocal targets. How could such statements be handled if static chains were used for nonlocal variable access? Hint: Consider the way the correct activation record instance of the static parent of a newly enacted procedure is found (see Section 10.4.2).

*Based on the hint statement, the target of every goto in a program could be represented as an address and a nesting depth, where the nesting depth is the difference between the nesting level of the procedure that contains the goto and that of the procedure containing the target. Then, when a goto is executed, the static chain is followed by the number of links indicated in the nesting depth of the goto target. The stack top pointer is reset to the top of the activation record at the end of the chain.


9. The static-chain method could be expanded slightly by using two static links in each activation record instance where the second points to the static grandparent activation record instance. How would this approach affect the time required for subprogram linkage and nonlocal references?

*Including two static links would reduce the access time to nonlocals that are defined in scopes two steps away to be equal to that for nonlocals that are one step away. Overall, because most nonlocal references are relatively close, this could significantly increase the execution efficiency of many programs.


10. Design a skeletal program and a calling sequence that results in an activation record instance in which the static and dynamic links point to different activation-recorded instances in the run-time stack.

*\\
\emph{Answer}:\\
procedure Main\_2 is\\
\verb+ + X : Integer;\\
\verb+ +procedure Bigsub is\\
\verb+ +\verb+ + A, B, C : Integer;\\
\verb+ +\verb+ + procedure Sub1 is\\
\verb+ +\verb+ +\verb+ + A, D : Integer;\\
\verb+ +\verb+ +\verb+ + begin -- of Sub1\\
\verb+ +\verb+ +\verb+ + A := B + C; $\longleftarrow$ 1\\
\verb+ +\verb+ +\verb+ + ...\\
\verb+ + end; -- of Sub1\\
\verb+ + procedure Sub2(X : Integer) is\\
\verb+ +\verb+ + B, E : Integer;\\
\verb+ +\verb+ + procedure Sub3 is\\
\verb+ +\verb+ +\verb+ + C, E : Integer;\\
\verb+ +\verb+ +\verb+ + begin -- of Sub3\\
\verb+ +\verb+ +\verb+ + ...\\
\verb+ +\verb+ +\verb+ + Sub1;\\
\verb+ +\verb+ +\verb+ + ...\\
\verb+ +\verb+ +\verb+ + E := B + A; $\longleftarrow$ 2\\
\verb+ +\verb+ + end; -- of Sub3\\
\verb+ +\verb+ + begin -- of Sub2\\
\verb+ +\verb+ + ...\\
\verb+ +\verb+ + Sub3;\\
\verb+ +\verb+ + ...\\
\verb+ +\verb+ + A := D + E; $\longleftarrow$ 3\\
\verb+ + end; -- of Sub2\\
\verb+ + begin -- of Bigsub\\
\verb+ +\verb+ + ...\\
\verb+ +\verb+ + Sub2(7);\\
\verb+ +\verb+ + ...\\
\verb+ + end; -- of Bigsub\\
begin -- of Main\_2\\
\verb+ + ...\\
\verb+ + Bigsub;\\
\verb+ + ...\\
end; -- of Main\_2\\
\\
The sequence of procedure calls is:\\
Main\_2 calls Bigsub\\
Bigsub calls Sub2\\
Sub2 calls Sub3\\
Sub3 calls Sub1\\
\\
The activation records with static and dynamic links is as follows:\\
\begin{figure}
\centering
\includegraphics[scale=0.5]{ari}
\end{figure}


At position 1 in procedure Sub1, the reference is to the local variable,
A, not to the nonlocal variable A from Bigsub. This reference to A has the
chain\_offset/local\_offset pair (0, 3). The reference to B is to the nonlocal B
from Bigsub. It can be represented by the pair (1, 4). The local\_offset is 4,
because a 3 offset would be the first local variable (Bigsub has no parameters). Notice that if the dynamic link were used to do a simple search for
an activation record instance with a declaration for the variable B, it would
find the variable B declared in Sub2, which would be incorrect. If the (1, 4)
pair were used with the dynamic chain, the variable E from Sub3 would be
used. The static link, however, points to the activation record for Bigsub,
which has the correct version of B . The variable B in Sub2 is not in the
referencing environment at this point and is (correctly) not accessible. The
reference to C at point 1 is to the C defined in Bigsub, which is represented
by the pair (1, 5).\\
\\

\noindent

Chapter 9 Answers

Nama : Christian Gunawan
NIM : 1801384174

Kali ini saya akan menjawab assigntment #9 dari chapter 9 Programming Language Concepts R Sebesta E-book :

Review Questions #6-10 :

6.What is a Ruby array formal parameter?

Ruby supports a complicated but highly flexible actual parameter configuration. The initial parameters are expressions, whose value objects are passed to the corresponding formal parameters. The initial parameters can be following by a list of key => value pairs, which are placed in an anonymous hash and a reference to that hash is passed to the next formal parameter. These are used as a substitute for keyword parameters, which Ruby does not support. 

7.What is a parameter profile? What is a subprogram protocol?

The parameter profile of a subprogram contains the number, order, and types of its formal parameters. The protocol of a subprogram is its parameter profile plus, if it is a function, its return type. In languages in which subprograms have types, those types are defined by the subprogram’s protocol.

8.What are formal parameters? What are actual parameters?

The parameters in the subprogram header are called formal parameters. They are sometimes thought of as dummy variables because they are not variables in the usual sense: In most cases, they are bound to storage only when the subprogram is called, and that binding is often through some other program variables. While actual parameters is a parameter that bound to the formal parameters of the subprogram. Subprogram call statements must include the name of the subprogram and a list of parameters to be bound to the formal parameters of the subprogram.


9.What are the advantages and disadvantages of keyword parameters?

The advantage of keyword parameters is that they can appear in any order in the actual parameter list. The disadvantage to keyword parameters is that the user of the subprogram must know the names of formal parameters.

10.What are the differences between a function and a procedure?

There are two distinct categories of subprograms—procedures and functions— both of which can be viewed as approaches to extending the language. All sub- programs are collections of statements that define parameterized computations. Functions return values and procedures do not. Procedures can produce results in the calling program unit by two methods: (1) If there are variables that are not formal parameters but are still visible in both the procedure and the calling program unit, the procedure can change them; and (2) if the procedure has formal parameters that allow the transfer of data to the caller, those parameters can be changed. However Functions are called by appearances of their names in expressions, along with the required actual parameters. And functions define new user-defined operators.

Problem Sets #6-10 :
6.Present one argument against providing both static and dynamic local variables in subprograms.

In subprograms local variables can be static or dynamic; If local variable treated statically: This allows for compile-time allocation/ deallocation and ensures proper type checking but does not allow for recursion. And if local variables treated dynamically: This allows for recursion at the cost of run-time allocation/ deallocation and initialization because these are stored on a stack, referencing is indirect based on stack position and possibly timeconsuming

7. Consider the following program written in C syntax:

void fun (int first, int second) {

first += first;

second += second;

}

void main() {

int list[2] = {1, 3};

fun(list[0], list[1]);

}

For each of the following parameter-passing methods, what are the values of the list array after execution?
Passed by value
Passed by reference
Passed by value-result
Passed by value : list[2] = { 3 , 5 }
Passed by reference : list[2] = { 6 , 10 }
Passed by value-result : list[2] = { 6 , 10 }


8.Argue against the C design of providing only function subprograms.

If a language provides only functions, then either programmers must live with the restriction of returning only a single result from any subprogram, or functions must allow side effects, which is generally considered bad. Since having subprograms that can only modify a single value is too restrictive, C’s choice is not good.

9.From a textbook on Fortran, learn the syntax and semantics of statement functions. Justify their existence in Fortran.

The Fortran 1966 standard provided a reference syntax and semantics, but vendors continued to provide incompatible extensions. These standards have improved portability.

10.Study the methods of user-defined operator overloading in C++ and Ada, and write a report comparing the two using our criteria for evaluating languages.

One of the nice features of C++ is that you can give special meanings to operators, when they are used with user-defined classes. This is called operator overloading. You can implement C++ operator overloads by providing special member-functions on your classes that follow a particular naming convention. For example, to overload the + operator for your class, you would provide a member-function named operator+ on your class. Meanwhile for Ada, since much of the power of the language comes from its extensibility, and since proper use of that extensibility requires that we make as little distinction as possible between predefined and user-defined types, it is natural that Ada also permits new operations to be defined, by declaring new overloading of the operator symbols.

Tuesday, December 2, 2014

Chapter 8 Answers

Nama : Christian Gunawan
NIM : 1801384174

Kali ini saya akan menjawab assigntment #8 dari chapter 8 Programming Language Concepts R Sebesta E-book :


Review Questions #6-10 :
6. What is unusual about Python’s design of compound statements?

Ada, Python, and Ruby, the then and else clauses are statement sequences, rather than compound statements. The complete selection statement is terminated in these languages with a reserved word.1
Python uses indentation to specify compound statements. For example,

If x > y :
x = y
print "case 1"

All statements equally indented are included in the compound statement.2 Notice that rather than then, a colon is used to introduce the then clause in Python.


7. Under what circumstances must an F# selector have an else clause?

An F# if need not return a value, for example if its clause or clauses create side effects, perhaps with output statements. However, if the if expression does return a value, as in the example above, it must have an else clause.


8. What are the common solutions to the nesting problem for two-way selectors?

The else clause would be paired with the second then clause. The disadvantage of using a rule rather than some syntactic entity is that although the programmer may have meant the else clause to be the
alternative to the first then clause and the compiler found the structure syntactically correct, its semantics is the opposite.

Another way to avoid the issue of nested selection statements is to use an alternative means of forming compound statements.


9. What are the design issues for multiple-selection statements?

• What is the form and type of the expression that controls the selection?
• How are the selectable segments specified?
• Is execution flow through the structure restricted to include just a single selectable segment?
• How are the case values specified?
• How should unrepresented selector expression values be handled, if at all?


10. Between what two language characteristics is a trade-off made when deciding whether more than one selectable segment is executed in one execution of a multiple selection statement?

The C# switch statement differs from that of its C-based predecessors in two ways. First, C# has a static semantics rule that disallows the implicit execution of more than one segment. The rule is that every selectable segment must end with an explicit unconditional branch statement: either a break,
which transfers control out of the switch statement, or a goto, which can transfer control to one of the selectable segments (or virtually anywhere else).

As with C, if there is no break at the end of the selected segment, execution continues into the next segment.


Problem Set #6-10 :
6. Analyze the potential readability problems with using closure reserved words for control statements that are the reverse of the corresponding initial reserved words, such as the case-esac reserved words of ALGOL 68. For example, consider common typing errors such as transposing
characters.


7. Use the Science Citation Index to find an article that refers to Knuth (1974). Read the article and Knuth’s paper and write a paper that summarizes both sides of the goto issue.


8. In his paper on the goto issue, Knuth (1974) suggests a loop control statement that allows multiple exits. Read the paper and write an operational semantics description of the statement.


9. What are the arguments both for and against the exclusive use of Boolean expressions in the control statements in Java (as opposed to also allowing arithmetic expressions, as in C++)?

The primary argument for using Boolean expressions exclusively as control expressions is the reliability that results from disallowing a wide range of types for this use. In C, for example, an expression of any type can appear as a control expression, so typing errors that result in references to variables of incorrect types are not detected by the compiler as errors.No , it would not be a good idea. Although this custom precedence sounds like increasing flexibility, requiring parentheses to show a custom precedence would impact in readability and writability of a program.

10. In Ada, the choice lists of the case statement must be exhaustive, so that there can be no unrepresented values in the control expression. In C++, unrepresented values can be caught at run time with the default selector. If there is no default, an unrepresented value causes the whole
statement to be skipped. What are the pros and cons of these two designs (Ada and C++)?

Ada was designed for military grade software development.
The idea is that whenever you modify code in such a way that a new case emerges (for example adding a new value for an enumeration type), you are forced to manually revisit (and therefore re-validate) all the case statements that analyze it. Having a "default" is risky: you may forget that there is a case somewhere where the new case should not have been handled by the default

Chapter 7 Answers

Nama : Christian Gunawan
NIM : 1801384174

Kali ini saya akan menjawab assigntment #7 dari chapter 7 Programming Language Concepts R Sebesta E-book :


Review Questions #6-10 :
6. What associativity rules are used by APL?

In APL, all operators have the same level of precedence. Thus, the order of evaluation of operators in APL expressions is determined entirely by the associativity rule, which is right to left for all operators.

For example, in the expression : A × B + C
the addition operator is evaluated first, followed by the multiplication operator (* is the APL multiplication operator). If A were 3, B were 4, and C were 5, then the value of this APL expression would be 27.


7. What is the difference between the way operators are implemented in C++ and Ruby?

What sets Ruby apart from the C-based languages in the area of expressions is that all of the arithmetic, relational, and assignment operators, as well as array indexing, shifts, and bitwise logic operators, are implemented as methods. For example, the expression a + b is a call to the + method of the object referenced by a, passing the object referenced by b as a parameter.


8. Define functional side effect.

A side effect of a function, naturally called a functional side effect, occurs when the function changes either one of its parameters or a global variable. (A global variable is declared outside the function but is accessible in the function.)


9. What is a coercion?

Coercion was defined as an implicit type conversion that is initiated by the compiler. 
Type conversions explicitly requested by the programmer are referred to as explicit conversions, or casts, not coercions.


10. What is a conditional expression?

If-then-else statements can be used to perform a conditional expression assignment. For example, consider :

if (count == 0)
       average = 0;
else
       average = sum / count;

In the C-based languages, this code can be specified more conveniently in an assignment statement using a conditional expression, which has the form

expression_1 ? expression_2 : expression_3.




Problem Set #6-10 :
6. Should C’s single-operand assignment forms (for example, ++count) be included in other languages (that do not already have them)? Why or why not?

Yes C should, because it will ease the increment or even decrement while we use in looping rather than manually by the assigning, and also by using that we can easily know that it is not operation, instead it is an increment or decrement which is usually used in repetition.


7. Describe a situation in which the add operator in a programming language would not be
commutative.

It wouldn’t be commutative when it deals with the negative integers. Recall that we can consider subtraction as addition in which one of two operator is a negative integer.


8. Describe a situation in which the add operator in a programming language would not be associative.

It is not associative when it includes the other operator with higher precedence like the multiplication and division.


9. Assume the following rules of associativity and precedence for expressions:

Precedence Highest *, /, not
+, –, &, mod
– (unary)
=, /=, < , <=, >=, >

Lowest or, xor

Associativity Left to right
Show the order of evaluation of the following expressions by parenthesizing all sub expressions and placing a superscript on the right parenthesis to indicate order. For example, for the expression
a + b * c + d
the order of evaluation would be represented as
((a + (b * c)1)2 + d)3

a. a * b - 1 + c                  ((( a * b )1 - 1)2 + c )3
b. a*(b-1)/c mod d           ((( a * ( b - 1 )1 )2 / c )3 mod d )4
c. (a-b)/c&(d*e/a-3)         (((a - b)1 / c)2 & ((d * e)3 / a)4 - 3)5)6
d. -a or c = d and e           (( -a )1 or ( ( c = d )2 and e )3 )4
e. a>b xor c or d<=17      (((a > b)1 xor c)3 or (d <= 17)2 )4
f. –a + b                            (–( a + b )1 )2


10. Show the order of evaluation of the expressions of Problem 9, assuming that there are no precedence rules and all operators associate right to left.

(a) ( a * ( b – ( 1 + c )1 )2 )3
(b) ( a * ( ( b – 1 )2 / ( c mod d )1 )3 )4
(c) ( ( a – b )5 / ( c & ( d * ( e / ( a – 3 )1 )2 )3 )4 )6
(d) ( – ( a or ( c = ( d and e )1 )2 )3 )4
(e) ( a > ( xor ( c or ( d <= 17 )1 )2 )3 )4
(f) ( – ( a + b )1 )2

Tuesday, October 28, 2014

Chapter 6 Answers

Nama : Christian Gunawan
NIM : 1801384174

Kali ini saya akan menjawab assigntment #6 dari chapter 6 Programming Language Concepts R Sebesta E-book :


Review Questions #6-10 :
6. What are the advantages of user-defined enumeration types?

Enumeration types provide a way of defining and grouping collections of named constants,
which are called enumeration constants.

7. In what ways are the user-defined enumeration types of C# more reliable than those of C++?

enum days {Mon, Tue, Wed, Thu, Fri, Sat, Sun};

8. What are the design issues for arrays?

• What types are legal for subscripts?
• Are subscripting expressions in element references range checked?
• When are subscript ranges bound?
• When does array allocation take place?
• Are ragged or rectangular multidimensioned arrays allowed, or both?
• Can arrays be initialized when they have their storage allocated?
• What kinds of slices are allowed, if any?


9. Define static, fixed stack-dynamic, stack-dynamic, fixed heap-dynamic, and heap-dynamic arrays. What are the advantages of each?

A static array is one in which the subscript ranges are statically bound and storage allocation is static (done before run time). The advantage of static arrays is efficiency: No dynamic allocation or deallocation is required. The disadvantage is that the storage for the array is fixed for the entire execution time of the program.

A fixed stack-dynamic array is one in which the subscript ranges are staticallybound, but the allocation is done at declaration elaboration time during execution. The advantage of fixed stack-dynamic arrays over static arrays is space efficiency.

A stack-dynamic array is one in which both the subscript ranges and the storage allocation are dynamically bound at elaboration time. Once the subscript ranges are bound and the storage is allocated, however, they remain fixed during the lifetime of the variable. The advantage of stack-dynamic arrays over static and fixed stack-dynamic arrays is flexibility. The size of an array need not
be known until the array is about to be used.

A fixed heap-dynamic array is similar to a fixed stack-dynamic array, in that the subscript ranges and the storage binding are both fixed after storage is allocated. The differences are that both the subscript ranges and storage bindings are done when the user program requests them during execution, and the storage is allocated from the heap, rather than the stack. The advantage of fixed heap-dynamic arrays is flexibility—the array’s size always fits the problem.

A heap-dynamic array is one in which the binding of subscript ranges and storage allocation is dynamic and can change any number of times during the array’s lifetime. The advantage of heap-dynamic arrays over the others is flexibility: Arrays can grow and shrink during program execution as the need for space changes.


10. What happens when a nonexistent element of an array is referenced in Perl?

A reference to a nonexistent element in Perl yields undef, but no error is reported.



Problem Set#6-10 :
6. Explain all of the differences between Ada’s subtypes and derived types.

A subtype is compatible with its base type, so you can mix operands of the base type with operands of the base type. For example:

subtype Week_Days is Integer range 1..7;
Since this is a subtype, you can (for example) add 1 to a weekday to get the next weekday.


A derived type is a completely separate type that has the same characteristics as its base type. You cannot mix operands of a derived type with operands of the base type. If, for example, you used:

type Week_Day is new Integer range 1..7;

Then you would not be able to add an integer to a weekday to get another weekday. To do manipulations on a derived type, you'd normally define those manipulations yourself (e.g., create a package). At the same time, a derived type does "inherit" all the operations of its base type (even some that may not make sense) so you do still get addition.

7. What significant justification is there for the -> operator in C and C++?

The only justification for the -> operator in C and C++ is writability. It is slightly easier to write p -> q than (*p).q.

8. What are all of the differences between the enumeration types of C++ and those of Java?

In C/C++, enums are more or less integers (that's the way they are handled under the hood). You can't give your enum methods or anything like that, basically you only capable of making variables of the type and giving them the values you list.

In Java, your enums can have methods attached.


9. The unions in C and C++ are separate from the records of those languages, rather than combined as they are in Ada. What are the advantages and disadvantages to these two choices?

Ada advantage:
Unconstrained variant records in Ada allow the values of their variants to change types during execution.

disadvantage:
The type of the variant can be changed only by assigning the entire record, including the discriminant. This disallows inconsistent records because if the newly assigned record is a constant data aggregate, the value of the tag and the type of the variant can be statically checked for consistency.

10. Multidimensional arrays can be stored in row major order, as in C++, or in column major order, as in Fortran. Develop the access functions for both of these arrangements for three-dimensional arrays.

Let the subscript ranges of the three dimensions be named min(1), min(2), min(3), max(1), max(2), and max(3). Let the sizes of the subscript ranges be size(1), size(2), and size(3). Assume the element size is 1.

Row Major Order:

location(a[i,j,k]) = (address of a[min(1),min(2),min(3)])  + ((i-min(1))*size(3) + (j-min(2)))*size(2) + (k-min(3))

Column Major Order:

location(a[i,j,k]) = (address of a[min(1),min(2),min(3)])  + ((k-min(3))*size(1) + (j-min(2)))*size(2) + (i-min(1))

Chapter 5 Answers


Nama : Christian Gunawan
NIM : 1801384174

Kali ini saya akan menjawab assigntment #5 dari chapter 5 Programming Language Concepts R Sebesta E-book :

Review Questions#6-10 :
6. What is the l-value of a variable? What is the r-value?

L-value is the address of a variable , because the address is what is required when the name of a variable appears in the left side of an assignment.

R-value is a name for a variable's value because it is what is required when the name of the variable appears in the right side of an assignment statement

7. Define binding and binding time.

A binding is an association between an attribute and an entity, such as between a variable and its type or value, or between an operation and a symbol.

Whilst the time at which a binding takes place is called binding time.

8. After language design and implementation [what are the four times bindings can take place in a program?]

Language design time — bind operator symbols to operations
Language implementation time– bind floating point type to a representation
Compile time — bind a variable to a type in C or Java
Load time — bind a C or C++ static variable to a memory cell)
Runtime — bind a non-static local variable to a memory cell

9. Define static binding and dynamic binding.

A static binding is if it first occurs before run time and remains unchanged throughout program execution. A dynamic binding is if it first occurs during execution or can change during execution of the program.

10. What are the advantages and disadvantages of implicit declarations?

Disadvantage : A static binding is if it first occurs before run time and remains unchanged throughout program execution. A dynamic binding is if it first occurs during execution or can change during execution of the program.

Advantage : There are several different bases for implicit variable type bindings. The simplest of these is naming conventions. In this case, the compiler or interpreter binds a variable to a type based on the syntactic form of the variable’s name.



Problem Set #6-10 : 
6. Consider the following JavaScript skeletal program:
// The main program
var x;
function sub1() {
var x;
function sub2() {
. . .
}
}
function sub3() {
. . .
}
Assume that the execution of this program is in the following unit order:
main calls sub1
sub1 calls sub2
sub2 calls sub3
a. Assuming static scoping, in the following, which declaration
of x is the correct one for a reference to x?
i. sub1
ii. sub2
iii. sub3
b. Repeat part a, but assume dynamic scoping.

a. In sub1: sub1
    In sub2: sub1
    In sub3: main

b.In sub1: sub1
   In sub2: sub1
   In sub3: sub1.

7. Assume the following JavaScript program was interpreted using
static-scoping rules. What value of x is displayed in function sub1?
Under dynamic-scoping rules, what value of x is displayed in function
sub1?
var x;
function sub1() {
document.write("x = " + x + "<br />");
}
function sub2() {
var x;
x = 10;
sub1();
}
x = 5;
sub2();

Static scoping: x=5;
Dynamic scoping: x=10;


8. Consider the following JavaScript program:
var x, y, z;
function sub1() {
var a, y, z;
function sub2() {
var a, b, z;
. . .
}
. . .
}
function sub3() {
var a, x, w;
. . .
}
List all the variables, along with the program units where they are
declared, that are visible in the bodies of sub1, sub2, and sub3, assuming
static scoping is used.

Sub1: a(sub1), y(sub1), z(sub1), x(main).
Sub2: a(sub2), b(sub2), z(sub2), y(sub1), x(main)
Sub3: a(sub3), x(sub3), w(sub3), y(main), z(main)
  


9. Consider the following Python program:
x = 1;
y = 3;
z = 5;
def sub1():
a = 7;
y = 9;
z = 11;
. . .
def sub2():
global x;
a = 13;
x = 15;
w = 17;
. . .
def sub3():
nonlocal a;
a = 19;
b = 21;
z = 23;
. . .
. . .
List all the variables, along with the program units where they are
declared, that are visible in the bodies of sub1, sub2, and sub3, assuming
static scoping is used.

Variable             Where Declared

In sub1:
     a                            sub1
     y                            sub1
     z                            sub1
     x                            main


In sub2:
     a                            sub2
     x                            sub2
     w                           sub2
     y                            main
     z                            main

In sub3:
     a                            sub3
     b                            sub3
     z                            sub3
     w                           sub2
     x                            sub2
     y                            main




10. Consider the following C program:
void fun(void) {
int a, b, c; /* definition 1 */
. . .
while (. . .) {
int b, c, d; /*definition 2 */
. . . 1
while (. . .) {
int c, d, e; /* definition 3 */
. . . 2
}
. . . 3
}
. . . 4
}
For each of the four marked points in this function, list each visible variable,
along with the number of the definition statement that defines it.

Point 1: a:1, b:2, c:2, d:2
Point 2: a:1, b:2, c:3, d:3, e:3
Point 3: a:1, b:2, c:2, d:2
Point 4: a:1, b:1, c:1

Tuesday, October 14, 2014

Chapter 4 Answers

Nama : Christian Gunawan
NIM : 1801384174

Kali ini saya akan menjawab assigntment #4 dari chapter 4 Programming Language Concepts R Sebesta E-book :

Review Questions#6-10 :

6. What is a state transition diagram?

A state transition diagram, or just state diagram, is a directed graph. The
nodes of a state diagram are labeled with state names.

7. Why are character classes used, rather than individual characters, for the letter and digit transitions of a state diagram for a lexical analyzer?

Lexical analyzer is interested only in determining that it is a name and is not concerned with which specific name it happens to be. Therefore, we define a character class named LETTER for all 52 letters and use a single transition on the first letter of any name.

8. What are the two distinct goals of syntax analysis?

There are two distinct goals of syntax analysis: First, the syntax analyzer must check the input program to determine whether it is syntactically correct. When an error is found, the analyzer must produce a diagnostic message and recover.

The second goal of syntax analysis is to produce a complete parse tree, or at least trace the structure of the complete parse tree, for syntactically correct input. The parse tree (or its trace) is used as the basis for translation.

9. Describe the differences between top-down and bottom-up parsers.

The two broad classes of parsers are top-down, in which the tree is built from the root downward to the leaves, and bottom-up, in which the parse tree is built from the leaves upward to the root.

10. Describe the parsing problem for a top-down parser.

if the current sentential form is
xA α
and the A-rules are A → bB, A → cBb, and A → a, a top-down parser must choose among these three rules to get the next sentential form, which could be xbBα , xcBbα, or xaα . This is the parsing decision problem for top-down parsers.



Problem Set#6-10 :

6. Given the following grammar and the right sentential form, draw a parse
tree and show the phrases and simple phrases, as well as the handle.
S → AbB bAc A → Ab aBB B → Ac cBb c



a. aAcccbbc

Phrases:
      aAcccbbcaAcccb, Ac, ccb, c_1, c_2

Simple phrases:


      Ac, c_1, c_2

Handle:
      Ac






b. AbcaBccb

Phrases:
            AbcaBccbcaBccbaBccaBc, c_1

Simple Phrases:
            c_1

Handle:
            c_1







c. baBcBbbc

Phrases:
      baBcBbbcaBcBbbaBcBbcBb

Simple Phrases:
      cBb

Handle:
      cBb








7. Show a complete parse, including the parse stack contents, input string,and action for the string id  * (id + id), using the grammar and parse table in Section 4.5.3.

Stack
Input
Action
0
id * (id + id) $
Shift 5
0id5
* (id + id) $
Reduce 6 (Use GOTO[0, F])
0F3
* (id + id) $
Reduce 4 (Use GOTO[0, T])
0T2
* (id + id) $
Reduce 2 (Use GOTO[0, E])
0T2*7
(id + id) $
Shift 7
0T2*7(4
id + id ) $
Shift 4
0T2*7(4id5
+ id ) $
Shift 5
0T2*7(4F3
+ id ) $
Reduce 6 (Use GOTO[4, F])
0T2*7(4T2
+ id ) $
Reduce 4 (Use GOTO[4, T])
0T2*7(4E8
+ id ) $
Reduce 2 (Use GOTO[4, E])
0T2*7(4E8+6
id ) $
Shift 6
0T2*7(4E8+6id5
) $
Shift 5
0T2*7(4E8+6F3
) $
Reduce 6 (Use GOTO[6, F])
0T2*7(4E8+6T9
) $
Reduce 4 (Use GOTO[6, T])
0T2*7(4E8
) $
Reduce 1 (Use GOTO[4, E])
0T2*7(4E8)11
$
Shift 11
0T2*7F10
$
Reduce 5 (Use GOTO[7, F])
0T2
$
Reduce 5 (Use GOTO[0, T])
0E1
$
Reduce 2 (Use GOTO[0, E])

8. Show a complete parse, including the parse stack contents, input string, and action for the string (id + id) * id, using the grammar and parse table in Section 4.5.3.


Stack
Input
Action
0
(id+id)*id $
Shift 5
0id5
* (id + id) $
Reduce 6 (Use GOTO[0, F])
0F3
* (id + id) $
Reduce 4 (Use GOTO[0, T])
0T2
* (id + id) $
Reduce 2 (Use GOTO[0, E])
0T2*7
(id + id) $
Shift 7
0T2*7(4
id + id ) $
Shift 4
0T2*7(4id5
+ id ) $
Shift 5
0T2*7(4F3
+ id ) $
Reduce 6 (Use GOTO[4, F])
0T2*7(4T2
+ id ) $
Reduce 4 (Use GOTO[4, T])
0T2*7(4E8
+ id ) $
Reduce 2 (Use GOTO[4, E])
0T2*7(4E8+6
id ) $
Shift 6
0T2*7(4E8+6id5
) $
Shift 5
0T2*7(4E8+6F3
) $
Reduce 6 (Use GOTO[6, F])
0T2*7(4E8+6T9
) $
Reduce 4 (Use GOTO[6, T])
0T2*7(4E8
) $
Reduce 1 (Use GOTO[4, E])
0T2*7(4E8)11
$
Shift 11
0T2*7F10
$
Reduce 5 (Use GOTO[7, F])
0T2
$
Reduce 5 (Use GOTO[0, T])
0E1
$
Reduce 2 (Use GOTO[0, E])


9. Write an EBNF rule that describes the while statement of Java or C++.
Write the recursive-descent subprogram in Java or C++ for this rule.

<while_stmt> -> WHILE '(' (<arith_expr> | <logic_expr>) ')'  <block>
  <block> -> <stmt> | '{' <stmt> {<stmt>} '}'


10. Write an EBNF rule that describes the for statement of Java or C++.
Write the recursive-descent subprogram in Java or C++ for this rule.

<for_stmt> -> FOR '(' (<arith_expr>; <logic_expr>; <arith_expr>) ')'  <block>
  <block> -> <stmt> | '{' <stmt> {<stmt>} '}'