Thread overview | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
|
October 12, 2012 BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
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 |
October 12, 2012 Re: BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Koch | 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 |
October 12, 2012 Re: BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Aziz K. Attachments:
| 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. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 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 |
October 12, 2012 Re: BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | 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
|
October 12, 2012 Re: BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Paulo Pinto Attachments:
| On Fri, 2012-10-12 at 16:59 +0200, Paulo Pinto wrote: […] > > My grammar knowledge is a bit rusty, but isn't EBNF only possible 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. -- Russel. ============================================================================= Dr Russel Winder t: +44 20 7585 2200 voip: sip:russel.winder@ekiga.net 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 |
October 12, 2012 Re: BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Russel Winder | 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:
> […]
> >
> > My grammar knowledge is a bit rusty, but isn't EBNF only possible 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.
>
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.
|
October 13, 2012 Re: BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Thomas Koch | http://www.dsource.org/projects/visuald/wiki/GrammarComparison |
October 13, 2012 Re: BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Nick Sabalausky | 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
|
October 13, 2012 Re: BNF grammar for D? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Mehrdad | 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 |
Copyright © 1999-2021 by the D Language Foundation