D grammar overhaul

Rainer Schuetze r.sagitario at gmx.de
Thu Mar 31 00:27:23 PDT 2011


Trass3r wrote:
> 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.

I'm not yet friend with git, but this might be a chance to get used to 
it. How can I contribute patches? I guess this would be with pull 
requests, so I'll need a github repository, too? The discussion page for 
pull requests looks like a nice feature...

I'm not sure though it is a good place to keep an overview of the 
grammar in a readable style. The grammar in the ddoc source is sometimes 
rather polluted with formatting information and links.

As a starter, here are some syntactic problems in the ddoc sources that 
cause the generation of grammar.txt to fail:

- in template.dd, $(GNAME Constraint) is not enclosed by $(GRAMMAR)
- in attribute.dd, $(GRAMMAR $(B const)), $(GRAMMAR $(B override)), etc 
are used for formatting without having to do with the grammar. The boxes 
they generate don't make much sense anyway, so they can just be removed.
- MulExpression is only in $(V1), so it does not show for D2

I've attached the patch for these.

>>> 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?

MixinDeclaration expands to declarations, while MixinStatement expands 
to statements, so the difference is not interesting during parsing, but 
might be important in the semantic pass (which restarts parsing for the 
string).

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-grammar-formatting-corrections.patch
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20110331/764eb70c/attachment.ksh>


More information about the Digitalmars-d mailing list