www.digitalmars.com         C & C++   DMDScript  

D - Grammar documentation

reply "Martin M. Pedersen" <mmp www.moeller-pedersen.dk> writes:
Hi,

I have noted that the expression grammar is documented like this:

    AddExpression:
        MulExpression
        MulExpression + MulExpression
        MulExpression - MulExpression
        MulExpression ~ MulExpression

However, I would expect it to be:

    AddExpression:
        MulExpression
        AddExpression + MulExpression
        AddExpression - MulExpression
        AddExpression ~ MulExpression

as the former does not allow multiple additions to appear in sequence (e.g.
a+b+c). This goes for all the expressions.

Can we agree that this is a documentation error?

Other languages I have studied have a very formal definition, either as a
YACC source, or something close to it. What I would like to see, is a
complete formal grammar of the language. I acknowledge that Walter does not
necessarily want to make the sources of his compiler public, but e.g. a YACC
grammar - without productions and lexical analyzer - would make the language
specification more useful for others implementing the language. If, for
example, someone other than Walter wanted to start a dfront project, this
could be a good starting point.

But perhaps I'm to early out?

Regards,
Martin M. Pedersen
Feb 05 2002
parent reply "Walter" <walter digitalmars.com> writes:
"Martin M. Pedersen" <mmp www.moeller-pedersen.dk> wrote in message
news:a3psna$1oao$1 digitaldaemon.com...
 Hi,

 I have noted that the expression grammar is documented like this:

     AddExpression:
         MulExpression
         MulExpression + MulExpression
         MulExpression - MulExpression
         MulExpression ~ MulExpression

 However, I would expect it to be:

     AddExpression:
         MulExpression
         AddExpression + MulExpression
         AddExpression - MulExpression
         AddExpression ~ MulExpression

 as the former does not allow multiple additions to appear in sequence
(e.g.
 a+b+c). This goes for all the expressions.

 Can we agree that this is a documentation error?
Yes.
 Other languages I have studied have a very formal definition, either as a
 YACC source, or something close to it. What I would like to see, is a
 complete formal grammar of the language. I acknowledge that Walter does
not
 necessarily want to make the sources of his compiler public, but e.g. a
YACC
 grammar - without productions and lexical analyzer - would make the
language
 specification more useful for others implementing the language. If, for
 example, someone other than Walter wanted to start a dfront project, this
 could be a good starting point.

 But perhaps I'm to early out?
I'm going to do a formal grammar. I work on it in parallel with the language implementation.
Feb 05 2002
parent "Robert W. Cunningham" <rwc_2001 yahoo.com> writes:
Walter wrote:

 "Martin M. Pedersen" <mmp www.moeller-pedersen.dk> wrote in message
 news:a3psna$1oao$1 digitaldaemon.com...
 Other languages I have studied have a very formal definition, either as a
 YACC source, or something close to it. What I would like to see, is a
 complete formal grammar of the language. I acknowledge that Walter does
not
 necessarily want to make the sources of his compiler public, but e.g. a
YACC
 grammar - without productions and lexical analyzer - would make the
language
 specification more useful for others implementing the language. If, for
 example, someone other than Walter wanted to start a dfront project, this
 could be a good starting point.

 But perhaps I'm to early out?
I'm going to do a formal grammar. I work on it in parallel with the language implementation.
May I recommend good old BNF? (Backus-Naur Form, a notation for Context-Free Grammars, http://cui.unige.ch/db-research/Enseignement/analyseinfo/BNFweb.html) YACC/BISON draw heavily on BNF for their own notation, but it isn't the same, and fails to capture the full richness of BNF (which leads to the limitations of the kinds of languages YACC/BISON can handle, and the frequent need for "explosions" of semantic actions to implement BNF rules YACC can't support directly). However, I doubt D has any need of "full" BNF, so perhaps a YACC grammar would be the expedient way to go, especially if the goal is to get D everywhere ASAP. There are also several "Extended-BNFs" that seek to bridge the gap between BNF and YACC language descriptions. I don't recommend them. A disadvantage of using YACC as the "definition" of a language is that it makes it more difficult to leave the World of YACC. BNF is more abstract, and thus more portable. -BobC
Feb 05 2002