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.
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⟩ | |
| | |
| ||
| | |
| ||
| | |
| ||
|
| |||
| = |
| ⟨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: