Assignment 1, CS 152
due September 22, 2003

Do the assignment specified in the "Basic Programming Assignment" handout, using Java.

You should have an explicit Symbol class, with methods toString and equals in addition to a constructor that takes a String as argument. The equals method should determine whether two symbols print the same.

Grammars are to be represented by instances of a Grammar class. This class is to have a constructor that takes as its single argument a Symbol that is to be the start symbol of the grammar. The class is to have a void method addNonterminal that takes a symbol and adds it to the collection of nonterminal symbols for the grammar. The class is to have three void methods addRule, taking respectively 2, 3, and 4 Symbols as arguments, that add rules to the grammar. In each case, the first symbol is to be interpreted as the left-hand side, and the other symbols as the symbols of the right-hand side, in order. Finally, the class is to have a method getYields that takes a Symbol and an int n, and returns a List of all strings of length n that can be generated from the given symbol.

You will probably find it convenient to have a separate Rule class to represent grammar rules.

Test your class definitions with the code in the file A1.java, which is available on the class web site.