4.1 Backus-Naur Form (BNF) Grammars
import: scribble/bnf | package: rhombus-scribble-lib |
The scribble/bnf library provides functions for typesetting grammars in traditional BNF notation, as opposed to shrubbery grammars.
function | |||||
| |||||
| |||||
annotation | |||||
A BNFEntry for either the left-hand or right-hand of a production is either a FlowBlock or Content.
For example,
@(
@bnf.nt{expr}, close),
@bnf.nt{val}]],
[@bnf.nt{val}, [@bnf.alt(@bnf.nt{number}, @bnf.nt{primop})]],
[@bnf.nt{id}, [@elem{any name except for @litchar{lambda}}]])
)
renders as
| ‹expr› | ::= | ‹id› |
|
| | | ( ‹expr›+ ) |
|
| | | ( lambda ( ‹id›* ) ‹expr› ) |
|
| | | ‹val› |
| ‹val› | ::= | ‹number› | ‹primop› |
| ‹id› | ::= | any name except for lambda |
function | ||
| ||
function | ||
| ||
function | ||
| ||
| ||
function | ||
| ||
| ||
function | ||
| ||
| ||
function | ||
| ||
| ||
function | ||
|
sequencing typeset as juxtaposition
alternatives typeset with | separators
a group typeset with parentheses
a zero-or-one choice typeset in square brackets
a zero-or-more choice typeset with a * suffix
a one-or-more choice typeset with a + suffix
a n-to-m choice typeset with a {} suffix