1 Formal grammar
The DSSL2 language has a number of statement and expression forms, which are described in more depth below. Here they are summarized in Extended Backus-Naur Form. You can also find a simplified version of this grammar that omits contracts in the next section.
Non-terminal symbols are written in ⟨italic_with_pointies⟩, whereas terminal symbols are in colored typewriter. Conventions include:
- { x }* for repetition 0 or more times 
- { x }+ for repetition 1 or more times 
- { x },* for repetition 0 or more times with commas in between 
- [ x ] for optional 
The grammar begins by saying that a program is a sequence of zero or more statements, where a statement is either a simple statement followed by a newline, or a compound statement.
| 
 | = | 
 | { ⟨statement⟩ }* | |
| 
 | 
 | |||
| 
 | = | 
 | ⟨simple⟩ NEWLINE | |
| 
 | | | 
 | ⟨compound⟩ | |
| 
 | 
 | |||
| 
 | = | 
 | number | |
| 
 | | | 
 | string | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ⟨lvalue⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | λ { name },* : ⟨simple⟩ | |
| 
 | | | 
 | struct_name { { name : ⟨expr⟩ },* } | |
| 
 | | | 
 | [ { ⟨expr⟩ },* ] | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | unop ⟨expr⟩ | |
| 
 | 
 | |||
| 
 | = | 
 | assert ⟨expr⟩ ⟨opt_timeout⟩ | |
| 
 | | | 
 | assert_error ⟨expr⟩ [ , ⟨expr⟩ ] ⟨opt_timeout⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ⟨expr⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | 
 | |||
| 
 | = | 
 | name | |
| 
 | | | 
 | ⟨expr⟩ . name | |
| 
 | | | 
 | ||
| 
 | 
 | |||
| 
 | = | 
 | class name ⟨opt_cvars⟩ ⟨opt_implements⟩ : ⟨class_block⟩ | |
| 
 | | | 
 | def name ⟨opt_cvars⟩ ( { name ⟨opt_ctc⟩ },* ) ⟨opt_res_ctc⟩ : ⟨block⟩ | |
| 
 | | | 
 | if ⟨expr⟩ : ⟨block⟩ { elif ⟨expr⟩ : ⟨block⟩ }* [ else : ⟨block⟩ ] | |
| 
 | | | 
 | interface name ⟨opt_cvars⟩ : ⟨interface_block⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | struct name : ⟨struct_block⟩ | |
| 
 | | | 
 | test [ ⟨expr⟩ ] ⟨opt_timeout⟩ : ⟨block⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | 
 | |||
| 
 | = | 
 | ⟨simple⟩ NEWLINE | |
| 
 | | | 
 | NEWLINE INDENT { ⟨statement⟩ }+ DEDENT | |
| 
 | 
 | |||
| 
 | = | 
 | NEWLINE INDENT { ⟨field_def⟩ }* { ⟨meth_proto⟩ : ⟨block⟩ }+ DEDENT | |
| 
 | 
 | |||
| 
 | = | 
 | ||
| 
 | | | 
 | NEWLINE INDENT { ⟨meth_proto⟩ NEWLINE }+ DEDENT | |
| 
 | 
 | |||
| 
 | = | 
 | ||
| 
 | | | 
 | NEWLINE INDENT { ⟨field_def⟩ }+ DEDENT | |
| 
 | 
 | |||
| 
 | = | 
 | def name ⟨opt_cvars⟩ ( name { , name ⟨opt_ctc⟩ }* ) ⟨opt_res_ctc⟩ | |
| 
 | 
 | |||
| 
 | = | 
 | ||
| 
 | 
 | |||
| 
 | = | 
 | [ , time < ⟨expr⟩ ] | |
| 
 | 
 | |||
| 
 | = | 
 | [ ( { name },* ) ] | |
| 
 | 
 | |||
| 
 | = | 
 | [ : ⟨ctc⟩ ] | |
| 
 | 
 | |||
| 
 | = | 
 | [ -> ⟨ctc⟩ ] | |
| 
 | 
 | |||
| 
 | = | 
 | [ [ { name },* ] ] | |
| 
 | 
 | |||
| 
 | = | 
 | ⟨expr⟩ | |
| 
 | 
 | |||
| 
 | = | 
 | mod_name | |
| 
 | | | 
 | mod_string | |
| 
 | 
 | 
binops are, from tightest to loosest precedence:
- **, 
- &, 
- ^, 
- \| (not written with the backslash), 
- ==, <, >, <=, >=, !=, is, and |is not| (not written with the vertical bars), 
- and, and 
- or. 
1.1 Simplified grammar
This section presents a version of the DSSL2 grammar that is simplified by omitting contracts:
| 
 | = | 
 | ⟨simple⟩ NEWLINE | |
| 
 | | | 
 | ⟨compound⟩ | |
| 
 | 
 | |||
| 
 | = | 
 | number | |
| 
 | | | 
 | string | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ⟨lvalue⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | λ { name },* : ⟨simple⟩ | |
| 
 | | | 
 | struct_name { { name : ⟨expr⟩ },* } | |
| 
 | | | 
 | [ { ⟨expr⟩ },* ] | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | unop ⟨expr⟩ | |
| 
 | 
 | |||
| 
 | = | 
 | ||
| 
 | | | 
 | assert_error ⟨expr⟩ [ , ⟨expr⟩ ] [ , time < ⟨expr⟩ ] | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ⟨expr⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | 
 | |||
| 
 | = | 
 | name | |
| 
 | | | 
 | ⟨expr⟩ . name | |
| 
 | | | 
 | ||
| 
 | 
 | |||
| 
 | = | 
 | class name [ ( { interface_name },* ) ] : ⟨class_block⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | if ⟨expr⟩ : ⟨block⟩ { elif ⟨expr⟩ : ⟨block⟩ }* [ else : ⟨block⟩ ] | |
| 
 | | | 
 | interface name : ⟨interface_block⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | struct name : ⟨struct_block⟩ | |
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | | | 
 | ||
| 
 | 
 | |||
| 
 | = | 
 | ⟨simple⟩ NEWLINE | |
| 
 | | | 
 | NEWLINE INDENT { ⟨statement⟩ }+ DEDENT | |
| 
 | 
 | |||
| 
 | = | 
 | NEWLINE INDENT { ⟨field_def⟩ }* { ⟨meth_proto⟩ : ⟨block⟩ }+ DEDENT | |
| 
 | 
 | |||
| 
 | = | 
 | ||
| 
 | | | 
 | NEWLINE INDENT { ⟨meth_proto⟩ NEWLINE }+ DEDENT | |
| 
 | 
 | |||
| 
 | = | 
 | ||
| 
 | | | 
 | NEWLINE INDENT { ⟨field_def⟩ }+ DEDENT | |
| 
 | 
 | |||
| 
 | = | 
 | def name ( name { , name }* ) | |
| 
 | 
 | |||
| 
 | = | 
 | let name NEWLINE | |
| 
 | 
 | |||
| 
 | = | 
 | mod_name | |
| 
 | | | 
 | mod_string | |
| 
 | 
 |