|How to best implement "optional" in YACC? firstname.lastname@example.org (1994-12-14)|
|From:||email@example.com (Kent J Quirk)|
|Keywords:||yacc, question, comment|
|Organization:||The World Public Access UNIX, Brookline, MA|
|Date:||Wed, 14 Dec 1994 20:36:15 GMT|
I'm creating a YACC grammar to read a file type that has lots of optional
elements in it, but the elements have an order.
The spec looks something like this:
test: foo bar? bazz? buzz yark? yutz
where the stuff with ? may or may not be present. Sometimes I get like 5
or 6 optional items in a row. Is there a way to do this without
explicitly defining all the permutations?
Right now, I've chickened out and done something like:
test: foo optionalstuff buzz moreoptions yutz
optionalstuff: /* possibly empty */
| optionalstuff oneoption
Are there better ways to handle this?
test: foo optbar optbazz buzz optyark yutz ;
optbar: bar | /*empty*/ ;
optbazz: bazz | /*empty*/ ;
optyark: yark | /*empty*/ ;
Return to the
Search the comp.compilers archives again.