CS 250 - Programming Languages                               Spring 2004

Assignment 1 -- Due February 2 at 2:30pm.

You may turn in the answers to these questions either in hardcopy or by e-mail to allen@bowdoin.edu

  1. Develop and run a simple Java program that finds the second-to-last word, alphabetically, in a series of words (character strings).  Your program should do this without sorting, but it should contain least one method.  For example, if the input is she saw the man with a telescope, the output should be the

    To become familiar with Linux for editing, debugging, and running programs, use the following documentation as a guide: http://academic.bowdoin.edu/computerscience/resources/html/linuxstart.shtml

    To begin running Java programs on the Linux machines, use the following documentation as a guide: http://academic.bowdoin.edu/computerscience/resources/languages/html/java.shtml

    Recall that Java input is a bit kludgy, and that the following statements enable you to establish keyboard input, read a line and assign it to the String variable s:

    import java.io.*;
    ...
    try {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    String s = r.readLine();
    }
    catch (IOException e) { }

    Alternately, there's a Keyboard class in the file  /home/allen/cs250/java/Keyboard.java, which you're welcome to copy and use. This class allows you to replace all of the above code with:

    String s = Keyboard.readString();

    Be sure to copy the file Keyboard.java into the directory where your Java program resides before compiling that program.

  1. Answer questions 1.1 and 1.5 on page 18 of your text.
  2. Answer questions 2.1, 2.2, 2.3, and 2.7 on page 46 of your text.  To answer question 2.3, go to the Web site www.bowdoin.edu/~allen/pl/syntax and select the link "Skeleton Token and TokenStream Classes" for an electronic copy of the code that appears on page 26 of your text.
  3. Using the formal syntax found in the Java Language Specification as a guide, develop a parse tree for each of the following Java expressions:
    1. x = x + 1 as an Expression
    2. int x ; as a LocalVariableDeclarationStatement
  4. Again using the formal Java syntax as a guide, and parse trees as a medium, argue convincingly that the Java string i*=2 is a legal Expression but that the string i*= is not.