www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - BNF grammar for D?

reply Thomas Koch <thomas koch.ro> writes:
Hi,

cedet is a collection of emacs dev tools. I understand that it should be 
relatively easy to enhance the emacs support of D if one just provides cedet 
with a BNF grammar in a Bison like format, I cite:

"
You should choose to use the Semantic lexer/grammer format for your language 
if it has a deterministic grammar. Often times you can download a pre-
existing BNF grammar for a language. These BNF grammars can be converted to 
Wisent grammar format fairly easily.
"

Is there anything that could be easily translated?

Regards, Thomas Koch
Oct 12 2012
next sibling parent reply "Aziz K." <aziz.koeksal gmail.com> writes:
Hi,

I can give you three options to choose from.

There's the official grammar (don't know what the form is called):

http://dlang.org/declaration.html

A Parser Expression Grammar (PEG):

https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/examples/dparser.d

The source code comments in my project using a pseudo-BNF format. They  
shouldn't be too hard to decipher, but keep in mind that they're not 100%  
complete and exact:

http://dl.dropbox.com/u/17101773/next/2/dil/doc/dil.parser.Parser.html#Parser.parseModuleDecl

-- 
My D Compiler: http://code.google.com/p/dil
Oct 12 2012
parent reply Russel Winder <russel winder.org.uk> writes:
On Fri, 2012-10-12 at 15:11 +0200, Aziz K. wrote:
 Hi,
=20
 I can give you three options to choose from.
=20
 There's the official grammar (don't know what the form is called):
=20
 http://dlang.org/declaration.html
=20
 A Parser Expression Grammar (PEG):
=20
 https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/examples/dpar=
ser.d
=20
 The source code comments in my project using a pseudo-BNF format. They =
=20
 shouldn't be too hard to decipher, but keep in mind that they're not 100%=
=20
 complete and exact:
=20
 http://dl.dropbox.com/u/17101773/next/2/dil/doc/dil.parser.Parser.html#Pa=
rser.parseModuleDecl I think the official grammar rules in, let's call it K&R grammar, is the only choice here. Rather than scrape from the website is there a file in the Git repository with this grammar rule set? If so then a small program in say, Python ;-), would give a EBNF grammar representation fairly straightforwardly =E2=80=93 read grammar ruleset, construct tree representing the ruleset, run visitor over tree to generate EBNF. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Oct 12 2012
parent reply "Paulo Pinto" <pjmlp progtools.org> writes:
On Friday, 12 October 2012 at 14:41:12 UTC, Russel Winder wrote:
 On Fri, 2012-10-12 at 15:11 +0200, Aziz K. wrote:
 Hi,
 
 I can give you three options to choose from.
 
 There's the official grammar (don't know what the form is 
 called):
 
 http://dlang.org/declaration.html
 
 A Parser Expression Grammar (PEG):
 
 https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/examples/dparser.d
 
 The source code comments in my project using a pseudo-BNF 
 format. They  shouldn't be too hard to decipher, but keep in 
 mind that they're not 100%  complete and exact:
 
 http://dl.dropbox.com/u/17101773/next/2/dil/doc/dil.parser.Parser.html#Parser.parseModuleDecl
I think the official grammar rules in, let's call it K&R grammar, is the only choice here. Rather than scrape from the website is there a file in the Git repository with this grammar rule set? If so then a small program in say, Python ;-), would give a EBNF grammar representation fairly straightforwardly – read grammar ruleset, construct tree representing the ruleset, run visitor over tree to generate EBNF.
My grammar knowledge is a bit rusty, but isn't EBNF only possible for LR(K) languages? Is is possible for D? -- Paulo
Oct 12 2012
parent reply Russel Winder <russel winder.org.uk> writes:
On Fri, 2012-10-12 at 16:59 +0200, Paulo Pinto wrote:
[=E2=80=A6]
=20
 My grammar knowledge is a bit rusty, but isn't EBNF only possible=20
 for LR(K) languages?
Mentioning EBNF turns out to be a red herring. Indeed mention of BNF is a red herring also. What is actually needed is a Wisent grammar file. Wisent is Bison. Bison is YACC. So we are looking for an LALR(1) grammar.
 Is is possible for D?
Pass. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder ekiga.n= et 41 Buckmaster Road m: +44 7770 465 077 xmpp: russel winder.org.uk London SW11 1EN, UK w: www.russel.org.uk skype: russel_winder
Oct 12 2012
parent reply Nick Sabalausky <SeeWebsiteToContactMe semitwist.com> writes:
On Fri, 12 Oct 2012 16:16:10 +0100
Russel Winder <russel winder.org.uk> wrote:

 On Fri, 2012-10-12 at 16:59 +0200, Paulo Pinto wrote:
 [=E2=80=A6]
=20
 My grammar knowledge is a bit rusty, but isn't EBNF only possible=20
 for LR(K) languages?
=20 Mentioning EBNF turns out to be a red herring. Indeed mention of BNF is a red herring also. What is actually needed is a Wisent grammar file. Wisent is Bison. Bison is YACC. So we are looking for an LALR(1) grammar. =20
 Is is possible for D?
=20 Pass. =20
I'm pretty sure a correct D grammar is impossible in LALR(1), unless maybe there's a way to manually resolve shift-reduce/reduce-reduce conflicts. You might be able to get close, though. LALR(k) or GLR might be possible.
Oct 12 2012
parent Manfred Nowak <svv1999 hotmail.com> writes:
Nick Sabalausky wrote:

 I'm pretty sure a correct D grammar is impossible in LALR(1)
"a^n b^n c^n" is not LALR(1). But "a^n b^n c^m" is---if n and m are not dependent. I.e.: without specifying the restrictions for the allowed semantic checks there is no sureness for impossibilities. -manfred
Oct 13 2012
prev sibling parent reply "Mehrdad" <wfunction hotmail.com> writes:
http://www.dsource.org/projects/visuald/wiki/GrammarComparison
Oct 12 2012
parent Rainer Schuetze <r.sagitario gmx.de> writes:
On 10/13/2012 8:02 AM, Mehrdad wrote:
 http://www.dsource.org/projects/visuald/wiki/GrammarComparison
I haven't tried it for some time, but you can generate the text files from the current documentation with the script in http://www.dsource.org/projects/visuald/browser/grammar
Oct 13 2012