CSE 130: Principles of Programming Languages
Homework Assignments


  1. Due 11 January:
    1. Briefly compare Java with at least three other languages, such as FORTRAN, COBOL, BASIC, Algol, C, Lisp, ML, Ada, C++, etc; the languages that you choose for comparison should be very different from each other; write one paragraph for each comparison; please try to hit the main points and avoid the trivial points.
    2. Say what is your own favorite programming language, and explain why you like it, without falling into merely subjective considerations; i.e., you should base your argument on real historical, cultural, and pragmatic considerations, such as those described in the Essay on Comparative Programming Linguistics.
    3. Exercise 1.10 of Sethi (p. 22). First show how to translate the two new RAM instructions into code using only the original instructions.

  2. Due 18 January:
    1. Given the grammar E ::= E + E | E * E E ::= X | Y | Z E ::= 1 | 2 | 3 say how many distinct parses there are for X + Y * 2 + Z and give a proof that your answer is right.
    2. Give an unambiguous grammar that generates exactly the same expressions as the above grammar, and explain why it is unambiguous.
    3. Give a BNF grammar (do not use extended BNF) for the language of expressions consisting of an even number of a followed by an odd number of b. For example, aaaabbb and b are in the language, but ab and bb are not. Draw a syntax chart for your grammar.
    4. Exercise 2.8 of Sethi (p. 49). Include drawings of stack states in your evaluation of the given expression.

  3. Due 25 January:
    1. Exercise 3.3 of Sethi (p. 95).
    2. Give a pre- and post- conditions for code to compute both the remainder and the quotient for x divided by y. Expand the while-do code on page 81 to compute these, and add the loop invariant.
    3. Do Bentley's problem in Example 3.4 on page 81; give informal invariants to develop your code and improve its chances of being correct.

  4. Due 1 February:
    1. Write complete (pseudo) Pascal code (including declarations) to produce the list (1 2 3 4) using the linked list structure in Figure 4.10, page 128.
    2. Write complete (pseudo) Pascal code (including declarations) to produce the structures in Figure 4.13(a), page 130, and then swap them, as in Figure 4.13(b).
    3. Exercise 4.2 of Sethi (p. 143).
  5. Due 8 February, but you may hand in up to 15 February:
    1. Exercise 5.1 of Sethi (p. 198), with "animations" showing how values in cells change in each case.
    2. Exercise 5.3 of Sethi (p. 199); use "animations" of values in cells in your explanations.
    3. Exercise 5.4 of Sethi (p. 199).
  6. Due 21 February:
    1. Exercise 6.1 of Sethi (p. 248). Write the code in pseudo-C, and include some animations of its execution.
    2. Exercise 6.3 of Sethi (p. 248); hand in source code and output showing that the compiled code executes correctly on some not totally trivial examples. You may use Java or C++ as you prefer.
    3. Exercise 6.5 of Sethi (p. 248-9). Include informal arguments that the invariants hold.
  7. Due 1 March:
    1. Exercise 8.1 of Sethi (p. 335).
    2. Exercise 8.5 of Sethi (p. 336).
    3. Exercise 8.13 of Sethi (p. 338).
  8. Due 8 March: You should run your code and hand in the output for two test cases for each part of each question where applicable.
    1. Exercise 9.6 of Sethi (p. 381).
    2. Exercise 9.7 of Sethi (p. 381).
    3. Exercise 9.11 of Sethi (p. 381).
    If you were unable to access ML you may hand in problems on 10 March instead.
  9. Optionally due 15 March: These problems will not be graded but will help you prepare for the final; you can take solutions to the TAs office hours to get feedback if you wish. The code should be executable and each answer should include output for two test cases for each part of each question.
    1. Exercise 11.2 of Sethi (p. 470).
    2. Exercise 11.4 of Sethi (p. 471).
    3. Exercise 11.5 of Sethi (p. 471).
    4. Exercise 11.7 of Sethi (p.471).
    Note: You may use a different Prolog than BinProlog if you prefer.

Standard ML of New Jersey is available on ACS machines such as ieng9.ucsd.edu; to update your environment to access sml, type prep smlnj, and then to actually run it, just type sml. For graduate students, version 110.0.6 of sml is available on CSE Unix machines at /net/cs/class/development/elkan/cse230/sml-110/bin/sml, which you can either define as an alias for sml, or else you can add the path for its directory to the PATH variable of your environment; however, this may not work from all machines, and may not work for undergraduates. If none of this works for you, you can download the latest version of ML (version 110.0.7) over the web from www.smlnj.org/software.html or cm.bell-labs.com/cm/cs/what/smlnj; another alternative is the OCAML variant of ML.

Binary for BinProlog 4.00 for Solaris machines (such as the CSE instructional machines beowulf, bintijua, kongo, or the machines in the APE lab) can be found at /net/cs/class/wi99/cse230/prolog/bp, and also as a backup, at /net/cat/disk1/prolog/bp; the latter directory also contains other files, some of which may be relevant to exercises, so that you don't have to do all the typing yourself. Some basic notes on using BinProlog 4.00 are at binpro.html.

To CSE 130 homepage
Maintained by Joseph Goguen
© 2000 - 2005 Joseph Goguen
Last modified: Thu Mar 10 15:00:57 PST 2005