bugs/errors in the D BNF

Kirk McDonald kirklin.mcdonald at gmail.com
Fri Jan 12 19:55:00 PST 2007


Kirk McDonald wrote:
> I've been working on a D parser written in Python. It has become 
> abundantly clear during this process that the grammar as defined in the 
> spec is to be found wanting in quite a number of ways. I've been 
> compiling a list of errors in the grammar. It is not in front of me at 
> the moment, but I do plan on posting it at some point.
> 

Here it is:

TemplateDeclaration and a few other things are defined but never used 
anywhere. Therefore:

DeclDef is missing:
     TemplateDeclaration
     ClassTemplateDeclaration
     FunctionTemplateDeclaration
     TemplateMixin
     ConditionalDeclaration
     StaticAssert

TemplateValueParameter is wrong. It should be something like:
     BasicType Declarator
     BasicType Declarator TemplateValueParameterSpecialization
     BasicType Declarator TemplateValueParameterDefault
     BasicType Declarator TemplateValueParameterSpecialization 
TemplateValueParameterDefault

Declarator is missing:
     BasicType2

Declarator2 is missing:
     BasicType2

The current definition of Parameter is just plain broken.

Parameter should be something like:
     BasicType
     BasicType Declarator = AssignExpression
     InOut BasicType
     InOut BasicType Declarator = AssignExpression

D's syntax allows template instances to be used as expressions. Therefore:

PrimaryExpression is missing:
     TemplateInstance

ImportBind should be:
     Identifier
     Identifier = Identifier

ConditionalDeclaration should be:
     Condition DeclarationBlock
     Condition DeclarationBlock else DeclarationBlock
     Condition : DeclDefs

DeclarationBlock should be:
     DeclDef
     { DeclDefs }
     { }

Therefore, version.html's definition of Declarations is no longer needed.

The definition of DeclarationStatement in the spec does not allow for 
nested classes, structs, and so forth. Therefore it should be:

DeclarationStatement:
     Declaration
     AggregateStatement
     MixinStatement

MixinStatement:
     TemplateMixin

AggregateStatement:
     AggregateDeclaration
     ClassDeclaration
     InterfaceDeclaration
     EnumDeclaration

-- 
Kirk McDonald
Pyd: Wrapping Python with D
http://pyd.dsource.org


More information about the Digitalmars-d-bugs mailing list