Homework # 2
due Tuesday, February 10, 4:00 PM

Ambiguous Grammars

Some programming languages have ``if'' expressions:


<expr> ::= <expr> + <expr> | <expr> = <expr> | <expr> / <expr>
        |  if <expr> then <expr> else <expr> 
        |  <INTEGER> | <ID> | ( <expr> )
Thus one can write:

(if x = 0 then 1 else 10 / x ) + y
However the grammar above is ambiguous.

Turn this part in on paper at the beginning of lecture.

Classical Sequence

Write a C++ main program square.cc that reads in an integer and then prints its square, and then exits. This program should be 10 lines long at most. Compile it using g++ on Unix in the following ways: (Hint: Compile from the source each time.)

For each of the four artifacts produced in the previous stage, answer the following questions in a text file README:

Submitting Your Work

You submit your program work by putting the files (square.cc and friends, as well as README) in the homework2 directory in your AFS class volume. You may do all your work in this directory, or you may wish to do your work in a different directory and copy things when correct into this directory. In any case, you will lose permission to write things in this directory after the deadline, which is 4:00pm on Tuesday, February 10th. In other words, you must be done before lecture starts.

The homework2 directory should include the following:


About this document



John Tang Boyland
2004-02-03