On 12-03-2012 13:43, bls wrote:
On 03/10/2012 03:28 PM, Philippe Sigaud wrote:
Hello,

I created a new Github project, Pegged, a Parsing Expression Grammar
(PEG) generator in D.

https://github.com/PhilippeSigaud/Pegged

docs: https://github.com/PhilippeSigaud/Pegged/wiki

Just WOW!

Nice to have on your WIKI would be a EBNF to PEG sheet.

Wirth EBNF Pegged
A = BC. A <- B C
A = B|C. A <- C / C
A = [B]. A <- B?
A = {B}. A <- B*


Having EBNF expressed in Pegged ...

EBNF <- Procuction+
Production <- Identifier '=' Expression '.'
Expression <- Term ( '|' Term)*
Term <- Factor Factor*
Factor <- Identifier /
Literal /
'[' Expression ']'
/ '{' Expression }'/
'(' Expression ')'
lowerCase <- [a-z]
upperCase <- [A-Z]
Identifier <- (lowerCase / upperCase) (lowerCase / upperCase)*
Literal <- ("'" .+ "'" / '"' .+ '"')

Due to the fact that EBNF can be expressed in EBNF it should be possible
to parse an arbitrary EBNF file and generate PEG output.
What do you think ?

BTW.. Is my EBNF PEG description correct ? TIA Bjoern

The thing is, PEG cannot represent an ambiguous grammar. It is fully ordered, so it's just plain impossible.

That's not to say you can't turn an EBNF grammar into PEG, but it won't necessarily be useful in all cases.

--
- Alex

Reply via email to