Search code examples
dbnf

BNF form of Grammar of language D


I am not able to find the grammar of programming language D in BNF form. I can find the grammar of D online: https://github.com/dlang-community/DGrammar

However, it would be better if I am able to obtain the BNF form.


Solution

  • I'm afraid no such grammar is available. There have been a few attempts at making one before. The PEG grammar in Pegged's examples might be the closest to what you want, but it hasn't been updated for five years, and so might not be entirely accurate anymore:

    https://github.com/PhilippeSigaud/Pegged/blob/master/pegged/examples/dgrammar.d

    More up-to-date, there's D-Grammar:
    https://github.com/dlang-community/DGrammar

    There's also a few parsers you can have a look at:

    https://github.com/dlang-community/D-Scanner/

    https://github.com/aBothe/D_Parser/tree/master/DParser2/Parser

    https://github.com/SDC-Developers/SDC/tree/master/src/d/parser

    https://github.com/D-Programming-Language/dmd/blob/master/src/parse.c

    DDT also has one, though I don't know in which source file:
    https://github.com/DDT-IDE/DDT