4.6 BNF Grammars
(require scribble/bnf) | package: scribble-lib |
For example,
@(let ([open @litchar{(}] |
[close @litchar{)}]) |
@BNF[(list @nonterm{expr} |
@nonterm{id} |
@BNF-seq[open @kleeneplus[@nonterm{expr}] close] |
@BNF-seq[open @litchar{lambda} |
open @kleenestar[@nonterm{id}] close |
@nonterm{expr} close] |
@nonterm{val}) |
(list @nonterm{val} |
@BNF-alt[@nonterm{number} @nonterm{primop}]) |
(list @nonterm{id} |
@elem{any name except for @litchar{lambda}})]) |
produces the output
| ‹expr› | ::= | ‹id› |
|
| | | ( ‹expr›+ ) |
|
| | | ( lambda ( ‹id›* ) ‹expr› ) |
|
| | | ‹val› |
| ‹val› | ::= | ‹number› | ‹primop› |
| ‹id› | ::= | any name except for lambda |
See also racketgrammar.
procedure
pre-content : pre-content?
procedure
(BNF-seq-lines elems ...) → block?
elems : (listof content?)
procedure
pre-content : pre-content?
procedure
pre-content : pre-content?
procedure
(kleenestar pre-content ...) → element?
pre-content : pre-content?
procedure
(kleeneplus pre-content ...) → element?
pre-content : pre-content?
procedure
(kleenerange n m pre-content ...) → element?
n : any/c m : any/c pre-content : pre-content?