Re: Grammar for optional elements
- From: Tony Finch <dot@xxxxxxxx>
- Date: 17 Jun 2007 15:54:52 +0100 (BST)
Mohitz <coolmohitz@xxxxxxxxx> 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@xxxxxxxx> http://dotat.at/
.
- Follow-Ups:
- Re: Grammar for optional elements
- From: Lowell Thomas
- Re: Grammar for optional elements
- From: Chris F Clark
- Re: Grammar for optional elements
- Prev by Date: Re: Grammar for optional elements
- Next by Date: ELF archive string table
- Previous by thread: Re: Grammar for optional elements
- Next by thread: Re: Grammar for optional elements
- Index(es):