See the assignment turn-in page (last modified on 14 January 2006) for instructions on turning in your assignment.
nonterminal : ( nonterminal | terminal )*Nonterminals are distinguished from terminals by appearing to the left of the colon in a rule; terminals do not appear to the left of a colon in any rule in a grammar. Here is a small portion of a grammar:
if-statement : if guard then statementGiven a grammar, there are (at least) two ways to print it out. One way is by alphabetical order on the nonterminal to the left of the colon in each rule. Ordering the rules alphabetically makes it easy to locate any particular rule, but makes it inconvenient to find the rules used by a particular rule because they may be widely separated by other rules.guard : expression rel-op expression
statement : if-statement
The second way of organizing rules is group the rules using a nonterminal (appearing to the right of a colon) are near the rules defining the nonterminals (appearing the the left of a colon). This makes it hard to locate any particular rule, but easy to find the rules related to a particular rule.
The nearness of two rules in a list can be characterized by the distance between the rules, which is measured by the number of rules between the two rules. In the example above, the if-statement and statement rules are at distance 1; the guard and statement rules are at distance 0.
Given a list of rules, the list distance is the sum of the distances between every (unordered) pair of rules on the list. A pair of rules that are not related to one another (that is, neither rule uses a nonterminal defined by another) have distance 0.
Input not in the proper format should result in an informative error message followed by an immeidate end of the program with no futher output.
Error message should be printed to std-err preceeded by a "!
"
(that's a bang-space).
gen-grammar
in the assignment directory /export/home/class/cs-503/a7
writes to std-out a randomly-generated set of grammar rules. Because
gen-grammar
creates new input each time it's run, you might find it more
convenient to save the input in a file to provide your program with consistent
input:
My solution$ ./gen-grammar > input $ ./order-rules < input
order-rules
is also available in the class assignment
directory. Remember the purpose of this assignment is to implement a correct
solution, not to copy the behavior of my solution. If my solution's wrong and
you copy the incorrect behavior, you're going to lose points.
This page last modified on 27 April 2006. |