NCTU CIS: Undergraduate Programming Languages (Fall 2005)


SPECIAL ANNOUNCEMENTS:

  1. 6th homework is Project 10 (differentiation in Scheme) below, due December 23, Friday, 2005. You should pack your source code and the output in a single file (ZIP or something similar) named isyyyyyHW06, where isyyyyy is your student identity number. Submit the whole file to ftp://140.113.166.31 port 332, name is pl-fall2005 and password is ED117.
  2. 7th homework is Project 15 (貓貓狗狗過河去 in Prolog) below, due January 3, Tuesday, 2006. You should pack your source code and the output in a single file (ZIP or something similar) named isyyyyyHW07, where isyyyyy is your student identity number. Submit the whole file to ftp://140.113.166.31 port 332, name is pl-fall2005 and password is ED117.
  3. Here is a sample run of sml on PC
  4. chap 14

Course Information

Instructor

Wuu Yang, <wuuyang@cis.nctu.edu.tw>, EC332B, 03-5712121 ext. 56614. Office Hours: Tu 1:30-2:30.

If you want to talk to me at other time, please make an appointment.

Teaching Assistants

黃信達、劉宸瑋、張志誠 、陳冠志、陳癸夫、黃柏翰、謝文均 at phone 56649.

Lectures

ED 117, 2CD and 5E.

Course URL

http://www.cis.nctu.edu.tw/~wuuyang/Lecture/lecture.upl.html

Pre-Requisites

Experiences in writing programs in a high-level language (such as Pascal, C, or C++).

Textbook

R. Sethi, Programming Languages: Concepts and Constructs, 2nd ed., Addison-Wesley, 1996. (You are advised to buy this book if you take this course.)

(reference only) R.W. Sebesta, Concepts of Programming Languages, 4th ed., Addison-Wesley, 1999.

(reference only) R. Stansifer, The Study of Programming Languages, 1995, Prentice-Hall.

(reference only) D.P. Friedman, M. Wand, and C.T. Haynes, Essentials of Programming Languages, 1992, MIT Press.

(reference only) R. Bird and P. Wadler, Introduction to Functional Programming, 1988, Prentice-Hall.

(reference only) W.F. Clocksin and C.S. Mellish, Programming in Prolog, 1981, Springer-Verlag.

(reference only) J.W. Lloyd, Foundations of Logic Programming, 1984, Springer-Verlag.

(reference only) D. Gries, The Science of Programming, 1981, Springer-Verlag.

(reference only) Models of Programming Languages and Computation, ACM Computing Surveys, 28(2), June 1996, whole issue. Check the table of contents.

(reference only) David H. D. Warren, Logic Programming and Compiler Writing, Software Practice and Experience, Vol. 10, pp. 97-125, 1980.

Course Description

This course is an introduction to programming languages. Programming languages are a basic tool in computer science. We hope that the students can establish a firm background in languages and programming for further study.

We will study various programming paradigms and associated language constructs. Imperative languages will be our starting point. We will study types, variables, expressions, statements, control structures, subprograms, and modules. The principles of data encapsulation and inheritance will also be covered. After imperative languages, we will study functional languages and logic languages. Since parallel machines are becoming more and more practical and important, we will briefly study concurrent programming languages. A brief introduction to syntax and semantics will also be provided.

Exams

IT IS RECOMMENDED THAT YOU USE CHINESE TO ANSWER QUESTIONS IN THE EXAMS. YOU MAY ALSO USE ENGLISH IF NECESSARY. DO NOT USE ANY OTHER LANGUAGES.

Midterm: November 8, Tuesday, 10-12 am, 2005. Chapters 1 through 6, close book.

Final: January 10, Tuesday, 10-12 am, 2006. Chapters 7-12, close book.

Projects

These programming projects are all small projects. You need to do them all by yourself (not yourselves). You may discuss the projects with friends but never look at others' code. And never let others look at your programs.

The emphasis in these projects is to express your solutions as clearly as possible. Never worry about the amount of running time nor the amount of memory space required. A clear solution is better than a fast or small one in this introductory course.

ML, Scheme, and Prolog are available on the course page. See below.

  1. (assembly programming) Due March 3, Monday, beginning of class. Use Intel assembly language to write a program that computes all primes less than 100.
  2. (imperative programming) Write a C/Pascal/C++/Java program that prints itself twice. You cannot use "open file" instructions or any other equivalent mechanisms. All you can use is to print character stings to files. Due date: October 3, Tuesday, 10:10 before class. You need to turn in a printed copy of your program. No comments are needed.
  3. (context-free grammars) Consult the example in Figure 2.6 on page 42. Please write a context-free grammar for the BNF specification. Due date: October 12, 2000, Thursday, before class.
  4. (pass parameter by value) Consider the following C program:
        void swap(x, y)
        int *x, *y;
        { int z;
          z = *x;
          *x = *y;
          *y = z;
        }
        
    The swap procedure exchanges the values stored in its two arguments. Can you write another procedure that does the same thing but does not make use of pointers and addresses? Why or why not?
  5. (Passing parameters, due November 7, Tuesday, 10 am) Consider the three methods for passing parameters:
            call by value
            call by reference
            call by name
        
    Find five programs so that (1) in the first program, the results based on the three methods are identical; (2) in the second program, the results based on the first two methods are identical but are different fromt that based on the third method; (3) in the third prorgram, the result based on the first and third methods are identical but are different from that based on the second method; (4) in the fourth program, the results based on the last two methods are identical but are different from that based on the first method; (5) in the fifth program, the results based on the three methods are different.
  6. (Java programming) Solve the Apocalyptic Magic Square problem.
  7. (Java programming) Solve the Klingon Path problem.
  8. (security of language features)Study the security features of the Java language. Java was designed to be a network programming language. Due to this role, there are several features of Java (and the Java run-time system) that are specifically designed to protect the security of users' data and privacy. In this project, you need to write a report (5 pages, 12-point character size), written in Word or a similar word processor. In the report, you have to detail the security features of Java, the motivation of the features, the usage of the features, and the weaknesses of the Java language or the Java run-time system. You may refer to the web page http://www.javasoft.com/security. Due date: January 9, 20018.
  9. (functional programming, DUE December 5, 2005) In this project, you need to code in a functional language and we recommend the sml language, which is available on the workstations in our departmental laboratory.

    Consider a game of evolution. A lifeform is represented as a sequence of genes. There are four kinds of genes: alpha, beta, gamma, and delta. Initially, there are only two kinds of lifeforms, called M = [alpha], and F = [beta], respectively. To generate new lifeforms, a lifeform may undergo a mutation process or two lifeforms may fuse or mate. Sometimes, lifeforms will compete for survival.

    When a lifeform mutates, its odd-numbered genes are converted as follows: an alpha gene is converted to a beta gene, a beta gene is converted to a gamma gene, a gamma gene is converted to a delta gene and a delta gene to an alpha gene. For instance, the result of mutating [gamma, alpha, beta, alpha, delta] is [delta, alpha, gamma, alpha, alpha]. The length of the gene chain of the resultant lifeform is always the same as that of the original lifeform.

    Two lifeforms with equal-length gene chains may be fused together into a new lifeform. To fuse two lifeforms, the first lifeform loses its first half genes and the second loses its last one-third genes. Then the resulting two gene chains are concatenated together into a single gene chain. For instance, the fusion of the two lifeforms [alpha, beta, gamma, alpha] and [delta, gamma, delta, beta] is [gamma, alpha, delta, gamma, delta]. When two lifeforms with different-length gene chains try to fuse, an exception should be raised. In response to the exception, the first lifeform is returned as the result of fusion.

    When two lifeforms of equal-length gene chains mate, the first lifeform replaces its odd-numbered genes with the matching odd-numbered genes of the second lifeform. When two lifeforms with different-length gene chains try to mate, an exception should be raised. In response to the exception, the first lifeform is returned as the result of mating. For instance, when [alpha, alpha, beta, beta] and [gamma, beta, alpha, delta] mate, the child is [gamma, alpha, alpha, beta]. As another example, when [alpha, alpha, delta, delta] and [gamma, beta] mate, the child is [alpha, alpha, delta, delta].

    Two lifeforms may also compete in this cruel evolution process. When two lifeforms compete, the one with the longer chain of genes wins, but the winner loses the first half of its genes. For instance, when [alpha, beta, gamma, delta, alpha] and [beta, beta, alpha, delta] compete, the resultant lifeform is [gamma, delta, alpha]. When two lifeforms with gene chains of the same length compete, the one with earlier lexical order of the gene chain win; in this case, the surviver loses its first one-third and last one-third genes in order to respect this harsh competition. For instance, when [alpha, beta, gamma, delta, alpha] and [beta, beta, alpha, delta, alpha] compete, the resultant lifeform is [beta, gamma, delta]. When two identical lifeforms compete, the resultant lifeform consists of a single gene which is the last gene of the original lifeform. For instance, when [alpha, beta, gamma, delta, alpha] and [alpha, beta, gamma, delta, alpha] compete, the resultant lifeform is [alpha].

    The computation of "one-third" and "half" in the above description is taken with respect to integers. Note the resultant lifeform of a competition contains at least one gene.

    You are expected to hand in an ML (or scheme) program in printed form and two test cases. In each test case, the two lifeforms have chains of at least 20 genes. You may either implement the fusion operation or you may make up two lifeforms with gene chains of length at least 20 and perform mutation, mating, and competition. Two sample lifeforms are [gamma, alpha, beta, gamma, alpha, alpha, beta, delta, delta, gamma, beta, alpha, beta, alpha, alpha, gamma, delta, alpha, delta, gamma] and [alpha, gamma, beta, alpha, delta, beta, gamma, beta, alpha, alpha, gamma, delta, delta, alpha, gamma, delta, beta, beta, alpha, gamma].

  10. (functional programming, DUE 12/23, Friday, 2005) In this project, you are asked to write a program to differentiate polynomials, similar to the one in the textbook. However, this time, we will assume a different data structure. A polynomial, in its standard form, is a sum of terms. Hence, a polynomial is represented as a list of terms. A term is a product of factors, which is represented as a list of factors. A factor is either a constant (assuming integer constants only) or a variable raised to a certain power. For instance, the polynomial 2 + 3*x^3*y^5 - 3*z*u^7 is represented as ((2) (3 ('x 3) ('y 5)) (-3 ('z 1) ('u 7))). You are asked to write a differentiation program.
    You need to write in the scheme language.
  11. (functional programming) Continuation style programming of the Hanoi-Tower Problem. There are three pegs and five disks. The five disks are of different sizes. Initially, all five disks are put on the first peg, arranged according to their sizes, with the smallest on top. The goal is to move all five disks to the second peg, using the third peg as a temporary storing place. During the move, smaller disks must always be put on top of larger disks.
  12. (functional programming, applicable to emacs) Parentheses are very cumbsome in writing functional programs, for instance, (f (g x (h z (f z x y) g(q u)))). There are four right parentheses at the end of the expression. Some invent the square brakets such as [f (g x) y]. Right brackets serve the same purpose as parentheses. However, it may also add approprite number of right parentheses. For example, in (f [g x y (h (g y x (g (h z)]), there should be four right parentheses, one right bracket and one right parentheses. That is, it should be (f [g x y (h (g y x (g (h z))))]). The right bracket tells the functional-programming system to automatically the missing three right parentheses after z. Now your job is to write a program that supplies the right number of missing right parentheses. In other words, write a program that translate expressions such as (f [g x y (h (g y x (g (h z)]) to a correctly balanced expressions such as (f [g x y (h (g y x (g (h z))))]).
  13. (logic programming) Solve the 8-queen problem in prolog.
  14. (logic programming) Solve the following problem in prolog. Due January 4, 2001, Tuesday. Before class. Subject: 愚人節之謎......
    有五位小姐排成一列
    所有的小姐穿的衣服顏色都不一樣
    所有的小姐姓也不同
    所有的小姐都養不同的寵物,喝不同的飲料,吃不同的水果
    
    錢小姐穿紅色的衣服
    翁小姐養了一隻狗
    陳小姐喝茶
    穿綠衣服的站在穿白衣服的左邊
    穿綠衣服的小姐喝咖啡
    吃西瓜的小姐養鳥
    
    穿黃衣服的小姐吃柳丁
    站在中間的小姐喝牛奶
    趙小姐站在最左邊
    吃橘子的小姐站在養貓的隔壁
    養魚的小姐隔壁吃柳丁
    
    吃蘋果的小姐喝香檳
    江小姐吃香蕉
    趙小姐站在穿藍衣服的隔壁
    只喝開水的小姐站在吃橘子的隔壁
    
    請問那位小姐養蛇?
  15. (logic programming) 貓貓狗狗過河去. Two cats and two dogs want to cross a river. The animals uses a ship to cross the river. At any moment, dogs cannot outnumber cats on either bank of the river nor on the ship. It is allowed that there are only dogs (but no cats) on the banks of the river or on the ship.  It is also allowed that there are only cats on a bank or on the ship. There must be one or two animals on the ship when the ship is crossing the river, either from left bank to the right bank or the other around. After the ship reaches the destination, some animals may stay on the ship. Please write a prolog program that produces a correct order of shipping the animals. Can you generalize the program to the situation of n cats and m dogs?
  16. (parallel programming) Write a parallel program. In this third project, we will take a superficial look at parallel programming, which might be new to most of us. We will use PVM (parallel virtual machine) as our experimental "multiprocessor." Check the file /home2/is-proj/pl/pvm3/readme first. There is an example sorting program running on PVM. You are asked to try that example first and then modify the sorting part. All the required files are in the /home2/is-proj/pl/pvm3 directory. There is a pile of documents and other examples residing in the /home2/is-proj/pl/pvm3/private directory. Though these files are not required for the project, you may, as you wish, spy into the mysterious depths of the Private directory. But, remember to tamper with absolutely no creatures in that ancient cave. Dangerous are their names. You are required to submit your program and two test cases by the due date.

Grading (tentative)

There will be two exams (25% each), paper homework (20%), and programming assignments (25%). Classroom discussion counts as 5% toward the final score.


Homework

  1. Due September 27, Tuesday, 2005, beginning of class. Use Intel assembly language to write a program that computes all the first 100 primes. MASM is available below. You should pack your source code, assembled machine code, and the output in a single file (ZIP or something similar) named isyyyyyHW01, where isyyyyy is your student identity number. Submit the whole file to ftp://140.113.166.31 port 332, name is pl-fall2005 and password is ED117.
  2. 2nd homework is here, due October 4, Tuesday, 2005. You need to hand in your written homework before the class begins.
  3. 3rd homework (C++) due October 28, Friday, 2005. Discuss a feature of C++ that you think is bad. You may follow the style given in A critic of Java, by Harold Thimbleby, Software Practice and Experience, 29, 5, 457-478, 1999. You have to hand in the written homework before the class begins.
  4. 4th homework (OOP) is here, due November 4, Friday, 2005. You should pack your source code, assembled machine code, and the output in a single file (ZIP or something similar) named isyyyyyHW01, where isyyyyy is your student identity number. Submit the whole file to ftp://140.113.166.31 port 332, name is pl-fall2005 and password is ED117.

Past Homework

  1. Homework 4 due April 28, beginning of class. Solve the Apocalyptic Magic Square problem and the Klingon Path problems with the Java language. Can you think of a solution in the object-oriented style?
  2. Homework 3 due March 20, Monday, beginning of class. Prove the correctness of the GCD program with axiomatic semantics.

Local On-Line Information

Information on the Net


Wuu Yang, <wuuyang@cis.nctu.edu.tw>, EC332B, 03-5712121 ext. 56614.