Docs / Specification

16. Formal Grammar (BNF)

Below is the simplified BNF grammar defining Dryad's syntax. This is a subset covering the core language — some advanced features (guards in match, computed properties, decorators) are omitted for brevity. The grammar is context-free and serves as the reference for parser implementations.

Core BNF Grammar
 1        ::= *
 2      ::= 
 3                   | <const-decl>
 4                   | <function-decl>
 5                   | <class-decl>
 6                   | 
 7                   | 
 8                   | 
 9                   | <return-stmt>
10                   | <throw-stmt>
11                   | <try-catch-stmt>
12                   | 
13                   | <import-stmt>
14                   | <export-stmt>
15                   | 
16 
17       ::= "let"  [":" ] ["=" ] ";"
18 <const-decl>    ::= "const"  [":" ] "="  ";"
19 
20 <function-decl> ::= ["async"] "function" 
21                     "("  ")" [":" ]
22                     "{" * "}"
23 
24 <class-decl>    ::= "class"  ["extends" ]
25                     "{" <class-member>* "}"
26 
27     ::= 
28                   | 
29                   | 
30                   | 
31                   | 
32                   | 
33                   | 
34                   | 
35                   | 
36                   | <match-expr>
37 
38    ::=   
39     ::=  
40      ::=  "("  ")"
41    ::=  "." 
42                   |  "["  "]"
43                   |  "::" 
44    ::= "("  ")" "=>" 
45                   | "("  ")" "=>" "{" * "}"
46 
47           ::= "number" | "string" | "bool" | "any"
48                   |  "[]"
49                   | "("  ")"
50                   | "fn" "("  ")" "->" 

The grammar is designed to be unambiguous and LL(1) parsable for most constructs. The full reference is maintained in the theoretical foundation document.

Found an error in the spec? Open a PR.
Official Version: 1.0 · May 2026