On Sat, 2011-02-26 at 10:24 +0800, James wrote:
> Sections :
> | Section Sections
> | Lines
The problem is two-fold. First, it is the convention to write iteration
left recursively, as in
Sections
: /* empty */
| Sections Section
;
This results in less depth in the parse stack, and in some cases (where
rules are attached) results in a more-expected side-effect order (L2R
rather than R2L).
The second problem is that both Lines and Sections can be empty.
This make the initial parse state ambiguous. Should it immediately
reduce by the "Sections: /* empty */" rule, or by the "Lines: /* empty
*/" rule?
Try this instead
Sections
: Lines
| Sections section
;
Now there is no empty Sections rule, and all ambiguity goes away... the
file always starts with a (possibly empty) non-section set of lines.
When it doubt, always read the y.output file, it will document how and
where ambiguities occur in your grammar.
HTH
--
Regards
Peter Miller <[email protected]>
/\/\* http://miller.emu.id.au/pmiller/
PGP public key ID: 1024D/D0EDB64D
fingerprint = AD0A C5DF C426 4F03 5D53 2BDB 18D8 A4E2 D0ED B64D
See http://www.keyserver.net or any PGP keyserver for public key.
"Of all the strange crimes that humanity has legislated out of nothing,
blasphemy is the most amazing - with obscenity and indecent exposure
fighting it out for second and third place." -- Robert Heinlein,
Notebooks of Lazarus Long
--
SLUG - Sydney Linux User's Group Mailing List - http://slug.org.au/
Subscription info and FAQs: http://slug.org.au/faq/mailinglists.html