Grammar for optional elements

Mohitz <coolmohitz@gmail.com>
Tue, 12 Jun 2007 02:21:31 -0700

          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)
[10 later articles]
| List of all articles for this month |

From: Mohitz <coolmohitz@gmail.com>
Newsgroups: comp.compilers
Date: Tue, 12 Jun 2007 02:21:31 -0700
Organization: Compilers Central
Keywords: parse, question, comment
Posted-Date: 13 Jun 2007 22:13:12 EDT

Hi,


I need to create a parser for a language something like this.


attribute1: value;
attribute2: value;
attribute3: value;


All the attributes are optional but can occur only once...


One way is to specify the grammar as follows: This doesn't do the
'SINGLE occurence check'
Can a grammar be designed which ensures that each attribute can be
entered only once.


attribute_list : attribute_list attribute | attribute
attribute : ATTRIBUTE1 ':' IDENTIFIER | ATTRIBUTE2 ':' IDENTIFIER |
ATTRIBUTE3 ':' IDENTIFIER


[You can do it but you'll have a huge ugly grammar. You're much
better off with a grammar that accepts any list of attributes, and
reject duplicates in your semantic code. -John]


Post a followup to this message

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