I just started reading "Parsing Techniques, A Practical Guide", Second Edition, by Dick Grune and Ceriel J.H. Jacobs.
On page 12, the authors start describing a set of rules that can be used to generate the set of all enumerations of names of the type "tom, dick and harry": the rules allow single names (e.g. "tom") as well as repetitions ("tom, harry, dick, dick and harry"); multiple names in an enumeration are separated by commas except the last two names which are separated by "and", so the following aren't valid: ("tom, harry, dick") or ("harry and tom and dick").
A few pages later, and after having defined some more terms and formalisms, the authors come up with the following replacement rules (parse structure grammar) to generate the sentences of the desired type:
0. Name -> tom | dick | harry 1. Sentence-> Name | List End 2. List -> Name | Name, List 3. , Name End -> and Name
In the above, Sentence is the start symbol.
However it seems to me that these rules can generate incorrect sentences: if we replace Sentence by List End and List by Name we end up with Name End for which no replacement rule is defined.
It seems to me that the 2nd line in the rules above, if replaced by
Sentence -> Name | Name, List End
would fix this problem.
Am I correct that the authors have made an oversight, and is my modification correct? Or have I misunderstood something?
I don't have a CS background and this is the first time I'm reading about parsing, so please keep that in consideration in your replies. Thanks!