D grammar overhaul
Trass3r
un at known.com
Wed Mar 30 05:18:36 PDT 2011
Original discussion forked in the D grammar thread, so I'm opening a new one for this specific issue.
The D grammar is in dire need of an overhaul.
I suggest we discuss changes here and then put everything into github to issue a pull request once everything's done.
I already forked the d-programming-language.org repo to get started by fixing some mistakes. Hereafter I list some issues that come to my mind.
Alongside missing things (like @attributes I think) and smaller mistakes parts of it like the whole declarations subgrammar are overly complex
and allow strange constructs, partly cause C style arrays and function pointers are still in there even though considered harmful and thus deprecated.
(see http://www.digitalmars.com/d/2.0/declaration.html)
Furthermore function declarations are obscurely woven into all those productions.
So, correct me if I'm wrong but the current grammar even allows monsters like
auto ubyte[] ([] bar []) (T)(int i) const if(someCodition) = 2 , foo = 5 ;
Also, like Rainer proposed, BasicType2 should be somehow pulled out of Declarator to get rid of the DeclaratorInitializer-DeclaratorIdentifierList-DeclaratorIdentifier construct which CMIIW only exists to disallow multiple types: int a, *b;
>> isn't AutoDeclaration already covered by Decl -> StorageClasses Decl and so on?
Ok it's just an misleading name. It covers not only declarations with 'auto' but all Declarations where no type but only a StorageClass is given: shared a = 5;
>> Also there are 3 different instances of mixin: MixinExpression, MixinStatement and MixinDeclaration. Even though they all come down to the same thing.
> I think, the different mixin variants are ok, because you might want to
> generate different AST for these.
Well I can imagine that MixinStatement is necessary because if you have an ExpStatement with a MixinExpression the result is probably discarded (just like 'a' is discarded in a = 5;).
But why do you need another MixinDeclaration?
>> Modifiers like shared are repeated, e.g. in BasicType, Attribute, TypeSpecialization.
> Yes the confusion of const/shared/immutable etc in Attribute,StorageClass,Types,etc causes a lot of headaches.
More information about the Digitalmars-d
mailing list