www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - [spec] Looking for a write-up on the grammar notation

reply Dibyendu Majumdar <d.majumdar gmail.com> writes:
Hi,

I want to add a section that describes the notations used in the 
document.

As part of this I would like to add something about the grammar 
notation. Is there any write up available that describes how to 
read the notation?

Thanks and Regards
Dibyendu
May 15 2019
next sibling parent Dibyendu Majumdar <d.majumdar gmail.com> writes:
On Wednesday, 15 May 2019 at 23:57:55 UTC, Dibyendu Majumdar 
wrote:
 As part of this I would like to add something about the grammar 
 notation. Is there any write up available that describes how to 
 read the notation?
Something like this: https://golang.org/ref/spec#Notation
May 15 2019
prev sibling next sibling parent reply Dibyendu Majumdar <d.majumdar gmail.com> writes:
On Wednesday, 15 May 2019 at 23:57:55 UTC, Dibyendu Majumdar 
wrote:
 As part of this I would like to add something about the grammar 
 notation. Is there any write up available that describes how to 
 read the notation?
From lack of response I take it there isn't anything. So would this be correct for the grammar describing D syntax: 1. The grammar is context-free. 2. Non-terminals are in italics. 3. The right hand side of each production gives available alternatives, i.e. there is an implicit OR. 4. Terminals are shown in bold, non-italic text. 5. Optional non-terminals are suffixed by an 'opt'. Some questions: 1. Is the grammar complete? 2. Is it unambiguous? 3. Can it be directly converted to a parser? Sorry I am not an expert in this so apologies if above is stupid. Regards
May 16 2019
parent reply Max Haughton <maxhaton gmail.com> writes:
On Thursday, 16 May 2019 at 18:48:15 UTC, Dibyendu Majumdar wrote:
 Some questions:

 1. Is the grammar complete?
 2. Is it unambiguous?
 3. Can it be directly converted to a parser?

 Sorry I am not an expert in this so apologies if above is 
 stupid.

 Regards
I'm very rusty with the theory behind grammars: the grammar is complete for the core language (There are some DIPs that change things, but AFAIK they're either within the existing grammar or require no modification). The D's *grammar* is almost context free generators (https://github.com/PhilippeSigaud/Pegged/blob/master/pegged examples/dgrammar.d is close(?) to a D grammar for pegged). The Source for the actual parser in dmd is recursive descent and therefore basically follows the grammar rules (In the source)
May 16 2019
parent Dibyendu Majumdar <d.majumdar gmail.com> writes:
On Thursday, 16 May 2019 at 20:23:39 UTC, Max Haughton wrote:
 The D's *grammar* is almost context free
Hi, Could you explain this further?

 parser generators 
 (https://github.com/PhilippeSigaud/Pegged/blob/master/pegged
examples/dgrammar.d is close(?) to a D grammar for pegged).  The Source for the
actual parser in dmd is recursive descent and therefore basically follows the
grammar rules (In the source)
Thank you for the link. I meant where one could use the D Grammar and literally translate it to a system like yacc or ANTLR and get a working parser. For instance in C, you can't do that I believe because you need a symbol table to resolve typedefs. Regards
May 17 2019
prev sibling parent Dibyendu Majumdar <d.majumdar gmail.com> writes:
On Wednesday, 15 May 2019 at 23:57:55 UTC, Dibyendu Majumdar 
wrote:
 As part of this I would like to add something about the grammar 
 notation. Is there any write up available that describes how to 
 read the notation?
Interestingly I could probably just use the words by Dennis Ritchie back in 1975: https://www.bell-labs.com/usr/dmr/www/cman.pdf Looks like even the latest C and C++ standards essentially follow that.
May 17 2019