Re: Grammar for optional elements

Robert A Duff <bobduff@shell01.TheWorld.com>
Sat, 16 Jun 2007 15:16:18 -0400

          From comp.compilers

Related articles
Grammar for optional elements coolmohitz@gmail.com (Mohitz) (2007-06-12)
Re: Grammar for optional elements torbenm@app-6.diku.dk (2007-06-14)
Re: Grammar for optional elements anton@mips.complang.tuwien.ac.at (2007-06-16)
Re: Grammar for optional elements bobduff@shell01.TheWorld.com (Robert A Duff) (2007-06-16)
Re: Grammar for optional elements cfc@shell01.TheWorld.com (Chris F Clark) (2007-06-16)
Re: Grammar for optional elements 148f3wg02@sneakemail.com (Karsten Nyblad) (2007-06-17)
Re: Grammar for optional elements dot@dotat.at (Tony Finch) (2007-06-17)
Re: Grammar for optional elements torbenm@app-2.diku.dk (2007-06-18)
Re: Grammar for optional elements cfc@shell01.TheWorld.com (Chris F Clark) (2007-06-19)
Re: Grammar for optional elements dot@dotat.at (Tony Finch) (2007-06-19)
[7 later articles]
| List of all articles for this month |
From: Robert A Duff <bobduff@shell01.TheWorld.com>
Newsgroups: comp.compilers
Date: Sat, 16 Jun 2007 15:16:18 -0400
Organization: The World Public Access UNIX, Brookline, MA
References: 07-06-019 07-06-020
Keywords: parse, design
Posted-Date: 16 Jun 2007 16:44:21 EDT

torbenm@app-6.diku.dk (Torben Fgidius Mogensen) writes:


> If the order is fixed, i.e., if attribute1 must be before attribute2
> (if both appear) and so on, it takes only a grammar of size N:


Yes, but even in this case, I would advise not encoding the order
requirement, nor the no-duplicates requirement, in the grammar.
It will be easier to give good error messages if these rules
are checked in a later semantic analysis phase. And I think
it makes things simpler overall.


The user would prefer things like "duplicate attr1 (see line 123)",
or "attr1 must appear before attr3", rather than "ATTR2 or ATTR3
expected here", or "end of file expected".


In general, I think it's not wise to encode too much in the (context
free) grammar, even when it is feasible to do so.


- Bob



Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.