Assignment 3, CS 152
due October 27, 2003

Redo Assignment 1, but in Scheme, with the changes described below.

You are to define functions make-rule and make-grammar that are the equivalent of constructors in Java. More precisely, make-rule is to take a symbol and a list of symbols, and return a representation of a grammar rule with the given symbol as the left-hand side and the list of symbols, in the given order, on the right-hand side. The make-grammar function is to take a symbol, a list of symbols, and a list of rules, and return a representation of a grammar with the given symbol as start symbol, the given list of symbols as (other) nonterminals, and the given list of rules as its set of rules. These two functions need not check for errors or inconsistencies in their input.

You may represent grammar symbols simply as Scheme symbols.

The get-yields function should take a symbol, a grammar, and a nonnegative integer, and return a list of yields as specified for Assignment 1. This function should display an error message and return the empty list in case of errors in the input.

It is recommended that you use define-struct for your representations of rules and grammars, but this is not required. Feel free to define any auxiliary functions that you find useful. You may or may not want to nest these functions inside other definitions.

For ease in grading, please define all of your functions in a single file grammar.scm. Test with the test file provided on the class web site, and turn in a hard copy of your grammar.scm file, a hard copy of the results of your tests, and a diskette containing your file and the results of your test.