CSE 130: Principles of Programming Languages
Homework Assignments

NOTES:


  1. Due 17 January:
    1. An acyclic graph is a graph with no cycles, where a cycle is a (non-void) path from a node to itself. Write a formal definition for acyclic graph, based on one of the two definitions of graph given in class (using the formal notation of set theory and logic). Give an example of an acyclic graph that is not a tree.
    2. Say what is your 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. Give sample code illustrating your main points.
    3. Exercise 1.9 of Sethi (p. 22). Justify your answer.

  2. Due 24 January:
    1. Given the grammar E ::= E + E | E * E E ::= X | Y E ::= 0 | 1 | 2 say how many distinct parses there are for X + Y * 2 + 0 and give a proof that your answer is right. How many distinct values are there (under the standard interpretation of the operations) for these parses?
    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 odd number of a's followed by an even number of b's. For example, aaabb and abb are in the language, but ab and aa 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. Can the same be done for prefix?

  3. Due 31 January:
    1. Exercise 3.7 of Sethi (p. 96).
    2. Give pre- and post- conditions for code to compute the Nth prime number. Write Pascal while-do code with loop invariants; pseudo code is OK. Hints: You may find the predicate P(K) = "A[I] is the Ith prime for 1 <= I <= K" useful in your assertions; you may also want to treat N=1 and N=2 as special cases; only two loops are needed, one nested in the other. The Seive of Eratosthenes algorithm may be useful (and the applet at this link is cool).
    3. Do Bentley's problem in Example 3.4 on page 81; give informal invariants and show how they help develop your code and improve its chances of being correct.

  4. Due 7 February:
    1. Write complete (pseudo) Pascal code (including declarations) to produce linked list structures as in Figure 4.10, page 128, from a sequence of user intput integers.
    2. Write complete Pascal (pseudo) code (including declarations) to test for equality of linked list structures as in Figure 4.10, page 128.
    3. Write complete Pascal (pseudo) code (including declarations) to produce structures like those in Figure 4.13(a), page 131, and then swap them, as in Figure 4.13(b).
    4. Exercise 4.3 of Sethi (p. 143).
    5. Give examples showing that the three kinds of type equivalence (on page 140) are pairwise different.
     
  5. Due 14 February:
    1. Write a paragraph or two on the most significant differences between Pascal and C, and explain which differences are well motivated by the different main uses of these languages.
    2. The mathematical definition of Fibonacci numbers is: f(0) = 0, f(1) = 1, f(n) = f(n-1) + f(n-2) for n>= 2. Write Pascal pseudo code for this function, and show the activation tree and activation records for the computation of f(3).
    3. Exercise 5.1 of Sethi (p. 198), with "snapshots" showing how the values in cells change in each case.
    4. Exercise 5.2 of Sethi (p. 198-99).
    5. Exercise 5.3 of Sethi (p. 199), with "snapshots" showing how the values in cells change in each case.
     
  6. Due 28 February: Warning: this is tentative.
    1. Exercise 6.4 of Sethi (p. 248); use pseudo code.
    2. Exercise 6.6 of Sethi (p. 249); include some snapshots of its execution.
    3. Exercise 6.11 of Sethi (p. 250); hand in source code and output showing that the compiled code executes correctly on some not totally trivial examples, and give an invariant for the loop.
    4. Something for Chapter 8 here.
    5. Something for Chapter 8 here.
    6. Something for Chapter 8 here.
     


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 - 2006 Joseph Goguen
Last modified: Sat Feb 18 13:10:59 PST 2006