Re: Grammar for optional elements

Tony Finch <dot@dotat.at>
17 Jun 2007 15:54:52 +0100 (BST)

          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)
Re: Grammar for optional elements lowell@coasttocoastresearch.com (Lowell Thomas) (2007-06-19)
Re: Grammar for optional elements dot@dotat.at (Tony Finch) (2007-06-20)
Re: Grammar for optional elements Meyer-Eltz@t-online.de (Detlef Meyer-Eltz) (2007-06-20)
[4 later articles]
| List of all articles for this month |

From: Tony Finch <dot@dotat.at>
Newsgroups: comp.compilers
Date: 17 Jun 2007 15:54:52 +0100 (BST)
Organization: dotat labs
References: 07-06-019
Keywords: parse, design
X-Attribution: fanf hates supercite
Originator: @chiark.greenend.org.uk ([193.201.200.170])

Mohitz <coolmohitz@gmail.com> wrote:
>
>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...


You can do this with Parsing Expression Grammars.
http://pdos.csail.mit.edu/~baford/packrat/


start = attr*
attr = attr1 / attr2 / attr3
attr1 = "attribute1" COLON value SEMICOLON !(attr* attr1 attr*)
attr2 = "attribute2" COLON value SEMICOLON !(attr* attr2 attr*)
attr3 = "attribute3" COLON value SEMICOLON !(attr* attr3 attr*)


This says that each attribute expression is not followed by a sequence
of attributes containing another of the same kind of attribute expression.


Tony.
--
f.a.n.finch <dot@dotat.at> http://dotat.at/


Post a followup to this message

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