You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

请求获取编程语言D的BNF形式语法

Finding a BNF Grammar for the D Programming Language

I totally get the frustration of trying to track down a pure BNF grammar for D—they’re surprisingly hard to find in that exact format, even with the resources you’ve already located.

The grammar repository you referenced holds the official, authoritative syntax definitions for D, but they’re written in a custom EBNF-style format rather than strict BNF. Here’s how you can get a BNF version from it:

  • Manual conversion: The existing rules use common EBNF shorthands (like ? for optional elements, * for zero-or-more repetitions). You can expand these into pure BNF by splitting rules. For example, a rule like Module: ModuleDeclaration ImportDeclaration* would become:
    Module → ModuleDeclaration ImportDeclarationSequence
    Module → ModuleDeclaration
    ImportDeclarationSequence → ImportDeclaration ImportDeclarationSequence
    ImportDeclarationSequence → ImportDeclaration
    
  • Tool-assisted conversion: Some parser generators or grammar conversion scripts can take the repository’s grammar files and output BNF. If you’re comfortable with scripting, writing a small tool to process the files and expand the EBNF notations into BNF rules would save time.

You can also turn to the official D Language Specification, which presents the language’s syntax in an EBNF-like structure that’s straightforward to convert to BNF. Every syntax rule is laid out clearly there, so you can map each one directly by replacing shorthand notations with explicit BNF alternatives.

Right now, there’s no widely distributed pure BNF grammar for D, so converting the existing EBNF-style rules (either from the repo or the spec) is the most practical way to get the exact format you need.


内容的提问来源于stack exchange,提问作者Divyat

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.15 08:38:00