
COP5621 - Fall 2008
Assignment 3
cparse
Your assignment is to read in a start symbol of a set of productions followed by the set of productions
from stdin and produce the collection of sets of LR(0) items to stdout. An example input file is givenon
the next page and is in the ˜whalley/cop5621exec/cparse.in file. The program makes the following assump-
tions about the input.
(1) The start symbol is the first character on the first line.
(2) Productions start at the beginning of each of the following lines and are of the form N->rhs,where
Nis a nonterminal and rhs is a string of nonterminals and terminals. A"|" representing alternative
rhs’s isnot allowed.
(3) A nonterminal is a single uppercase letter.
(4) A terminal is a single character that is not an uppercase letter,"@", or a "’".
The output consists of twoparts. First, the augmented grammar should be printed. Next, the sets of
LR(0) items will be printed. An example output file is givenonthe next page and is in the
˜whalley/cop5621exec/cparse.out file. The form of your output should match my output exactly,which will
facilitate grading. The program makes the following assumptions about the output.
(1) The position is represented with a "@".
(2) The augmented grammar start symbol is represented by a "’".
(3) A set of items is represented by the form I#, where # is a number.Sets are numbered starting from
zero.
(4) The size of an item is no more than 20 characters (including a NULL character).
If you decide to use C or C++, then you can use the following strings to format your output:
"I%d:\n" - set of items number
"%-20s goto(%c)=I%d\n" - item with a goto
"%-20s\n" - item without a goto
Youmay not assume anylimit to the number of productions, items in a set, or the number of sets. In
other words, use dynamically allocated linked lists.
E-mail your source file to
[email protected] before the beginning of class on October 2.