r7rs-small-texinfo

R7RS-small Scheme converted to Texinfo.
git clone https://kaka.farm/~git/r7rs-small-texinfo
Log | Files | Refs | README | LICENSE

formal-syntax.texinfo (24669B)


      1 @node Formal syntax
      2 @section Formal syntax
      3 
      4 This section provides a formal syntax for Scheme written in an
      5 extended BNF.
      6 
      7 All spaces in the grammar are for legibility.  Case is not significant
      8 except in the definitions of @svar{letter}, @svar{character name}
      9 and @svar{mnemonic escape}; for example, @code{#x1A} and @code{#X1a}
     10 are equivalent, but @code{foo} and @code{Foo} and @code{#\space} and
     11 @code{#\Space} are distinct.  @svar{empty} stands for the empty string.
     12 
     13 The following extensions to BNF are used to make the description
     14 more concise: @arbno{@svar{thing}} means zero or more occurrences
     15 of @svar{thing}; and @atleastone{@svar{thing}} means at least one
     16 @svar{thing}.
     17 
     18 @menu
     19 * Lexical structure::
     20 * External representations formal::
     21 * Expressions formal::
     22 * Quasiquotations::
     23 * Transformers::
     24 * Programs and definitions::
     25 * Libraries formal::
     26 @end menu
     27 
     28 @node Lexical structure
     29 @subsection Lexical structure
     30 
     31 @cindex token
     32 
     33 This section describes how individual tokens (identifiers, numbers,
     34 etc.) are formed from sequences of characters.  The following sections
     35 describe how expressions and programs are formed from sequences
     36 of tokens.
     37 
     38 @svar{Intertoken space} can occur on either side of any token, but
     39 not within a token.
     40 
     41 Identifiers that do not begin with a vertical line are terminated by
     42 a @svar{delimiter} or by the end of the input.  So are dot, numbers,
     43 characters, and booleans.  Identifiers that begin with a vertical
     44 line are terminated by another vertical line.
     45 
     46 The following four characters from the ASCII repertoire are reserved
     47 for future extensions to the language: @code{[ ] @{ @}}
     48 
     49 In addition to the identifier characters of the ASCII repertoire
     50 specified below, Scheme implementations may permit any additional
     51 repertoire of Unicode characters to be employed in identifiers,
     52 provided that each such character has a Unicode general category of Lu,
     53 Ll, Lt, Lm, Lo, Mn, Mc, Me, Nd, Nl, No, Pd, Pc, Po, Sc, Sm, Sk, So,
     54 or Co, or is U+200C or U+200D (the zero-width non-joiner and joiner,
     55 respectively, which are needed for correct spelling in Persian, Hindi,
     56 and other languages).  However, it is an error for the first character
     57 to have a general category of Nd, Mc, or Me.  It is also an error to
     58 use a non-Unicode character in symbols or identifiers.
     59 
     60 All Scheme implementations must permit the escape sequence
     61 @code{\x}@svar{hexdigits}@code{;} to appear in Scheme identifiers
     62 that are enclosed in vertical lines. If the character with the given
     63 Unicode scalar value is supported by the implementation, identifiers
     64 containing such a sequence are equivalent to identifiers containing
     65 the corresponding character.
     66 
     67 @cindex identifier
     68 @cindex comment
     69 
     70 @c TODO: Better alignment in output.
     71 @indentedblock
     72 
     73 @svar{token} @expansion{} @svar{identifier} | @svar{boolean}
     74     | @svar{number} | @svar{character} | @svar{string}
     75     | @code{(} | @code{)} | @code{@hashchar{}(} | @code{@hashchar{}u8}
     76     | @code{'}
     77     | @code{`} | @code{,} | @code{,@@} | @code{.}
     78 
     79 @svar{delimiter} @expansion{} @svar{whitespace} | @svar{vertical line}
     80     | @code{(} | @code{)} | @code{"} | @code{;}
     81 
     82 @svar{intraline whitespace} @expansion{} @svar{space or tab}
     83 
     84 @svar{whitespace} @expansion{} @svar{intraline whitespace}
     85     | @svar{line ending}
     86 
     87 @svar{vertical line} @expansion{} @code{|}
     88 
     89 @svar{line ending} @expansion{} @svar{newline}
     90     | @svar{return} @svar{newline} | @svar{return}
     91 
     92 @svar{comment} @expansion{} @code{;}
     93       @pseudoprod{all subsequent characters up to a line ending}
     94     | @svar{nested comment}
     95     | @code{@hashchar{};} @svar{intertoken space} @svar{datum}
     96 
     97 @svar{nested comment} @expansion{}
     98       @code{@hashchar{}|} @svar{comment text}
     99         @arbno{@svar{comment cont}} @code{|@hashchar{}}
    100 
    101 @svar{comment text} @expansion{}
    102   @pseudoprod{character sequence not containing @code{@hashchar{}|}
    103               or @code{|@hashchar{}}}
    104 
    105 @svar{comment cont} @expansion{} @svar{nested comment}
    106     @svar{comment text}
    107 
    108 @svar{directive} @expansion{} @code{@hashchar{}!fold-case}
    109     | @code{@hashchar{}!no-fold-case}
    110 
    111 @end indentedblock
    112 
    113 Note that it is ungrammatical to follow a @svar{directive} with
    114 anything but a @svar{delimiter} or the end of file.
    115 
    116 @indentedblock
    117 
    118 @svar{atmosphere} @expansion{} @svar{whitespace} ∣ @svar{comment}
    119     ∣ @svar{directive}
    120 
    121 @svar{intertoken space} @expansion{} @arbno{@svar{atmosphere}}
    122 
    123 @end indentedblock
    124 
    125 Note that @code{+i}, @code{-i} and @svar{infnan} below are exceptions
    126 to the @svar{peculiar identifier} rule; they are parsed as numbers, not
    127 identifiers.
    128 
    129 @indentedblock
    130 
    131 @svar{identifier} @expansion{} @svar{initial} @arbno{@svar{subsequent}}
    132     | @svar{vertical line} @arbno{@svar{symbol element}}
    133         @svar{vertical line}
    134     | @svar{peculiar identifier}
    135 
    136 @svar{initial} @expansion{} @svar{letter} | @svar{special initial}
    137 
    138 @svar{letter} @expansion{} @code{a} | @code{b} | @code{c}
    139     | @dots{} | @code{z}
    140     | @code{A} | @code{B} | @code{C} | @dots{} | @code{Z}
    141 
    142 @svar{special initial} @expansion{} @code{!} | @code{$} | @code{%}
    143     | @code{&} | @code{*} | @code{/} | @code{:} | @code{<} | @code{=}
    144     | @code{>} | @code{?} | @code{^} | @code{_} | @code{~}
    145 
    146 @svar{subsequent} @expansion{} @svar{initial} | @svar{digit}
    147     | @svar{special subsequent}
    148 
    149 @svar{digit} @expansion{} @code{0} | @code{1} | @code{2} | @code{3}
    150     | @code{4} | @code{5} | @code{6} | @code{7} | @code{8} | @code{9}
    151 
    152 @svar{hex digit} @expansion{} @svar{digit} | @code{a} | @code{b}
    153     | @code{c} | @code{d} | @code{e} | @code{f}
    154 
    155 @svar{explicit sign} @expansion{} @code{+} | @code{-}
    156 
    157 @svar{special subsequent} @expansion{} @svar{explicit sign} | @code{.}
    158     | @code{@@}
    159 
    160 @svar{inline hex escape} @expansion{}
    161       @code{\x}@svar{hex scalar value}@code{;}
    162 
    163 @svar{hex scalar value} @expansion{} @atleastone{@svar{hex digit}}
    164 
    165 @svar{mnemonic escape} @expansion{} @code{\a} | @code{\b} | @code{\t}
    166     | @code{\n} | @code{\r}
    167 
    168 @svar{peculiar identifier} @expansion{} @svar{explicit sign}
    169     | @svar{explicit sign} @svar{sign subsequent}
    170         @arbno{@svar{subsequent}}
    171     | @svar{explicit sign} @code{.} @svar{dot subsequent}
    172       @arbno{@svar{subsequent}}
    173     | @code{.} @svar{dot subsequent} @arbno{@svar{subsequent}}
    174 
    175 @svar{dot subsequent} @expansion{} @svar{sign subsequent} | @code{.}
    176 
    177 @svar{sign subsequent} @expansion{} @svar{initial} | @svar{explicit sign}
    178     | @code{@@}
    179 
    180 @svar{symbol element} @expansion{}
    181     @pseudoprod{any character other than @svar{vertical line} or
    182                 @code{@backslashchar{}}}
    183     | @svar{inline hex escape} | @svar{mnemonic escape} | @code{|}
    184 
    185 @svar{boolean} @expansion{} @code{@hashchar{}t} | @code{@hashchar{}f}
    186     | @code{@hashchar{}true}
    187     | @code{@hashchar{}false}
    188 
    189 @svar{character} @expansion{} @hashchar{}\ @svar{any character}
    190     | @hashchar{}\ @svar{character name}
    191     | @hashchar{}\x@svar{hex scalar value}
    192 
    193 @svar{character name} @expansion{} @code{alarm} | @code{backspace}
    194    | @code{delete} | @code{escape} | @code{newline} | @code{null}
    195    | @code{return} | @code{space} | @code{tab}
    196 
    197 @svar{string} @expansion{} @code{"} @arbno{@svar{string element}} @code{"}
    198 
    199 @svar{string element} @expansion{}
    200       @pseudoprod{any character other than @code{"} or
    201                   @code{@backslashchar{}}}
    202     | @svar{mnemonic escape} | @code{\"} | @code{\\}
    203     | \@arbno{@svar{intraline whitespace}}@svar{line ending}
    204       @arbno{@svar{intraline whitespace}}
    205     | @svar{inline hex escape}
    206 
    207 @svar{bytevector} @expansion{} \@hashchar{}u8(@arbno{@svar{byte}})
    208 
    209 @svar{byte} @expansion{} @pseudoprod{any exact integer between 0 and 255}
    210 
    211 @end indentedblock
    212 
    213 The following rules for @svar{num R}, @svar{complex R}, @svar{real R},
    214 @svar{ureal R}, @svar{uinteger R}, and @svar{prefix R} are implicitly
    215 replicated for R = 2, 8, 10, and 16. There are no rules for
    216 @svar{decimal 2}, @svar{decimal 8}, and @svar{decimal 16}, which means
    217 that numbers containing decimal points or exponents are always in
    218 decimal radix. Although not shown below, all alphabetic characters used
    219 in the grammar of numbers can appear in either upper or lower case.
    220 
    221 @indentedblock
    222 
    223 @svar{num @var{R}} @expansion{} @svar{prefix @var{R}}
    224     @svar{complex @var{R}}
    225 
    226 @svar{complex @var{R}} @expansion{} @svar{real @var{R}}
    227     | @svar{real @var{R}} @code{@@} @svar{real @var{R}}
    228     | @svar{real @var{R}} @code{+} @svar{ureal @var{R}} @code{i}
    229     | @svar{real @var{R}} @code{-} @svar{ureal @var{R}} @code{i}
    230     | @svar{real @var{R}} @code{+ i}
    231     | @svar{real @var{R}} @code{- i}
    232     | @svar{real @var{R}} @svar{infnan} @code{i}
    233     | @code{+} @svar{ureal @var{R}} @code{i}
    234     | @code{-} @svar{ureal @var{R}} @code{i}
    235     | @svar{infnan} @code{i}
    236     | @code{+ i}
    237     | @code{- i}
    238 
    239 @svar{real @var{R}} @expansion{} @svar{sign} @svar{ureal @var{R}}
    240     | @svar{infnan}
    241 
    242 @svar{ureal @var{R}} @expansion{} @svar{uinteger @var{R}}
    243     | @svar{uinteger @var{R}} @code{/} @svar{uinteger @var{R}}
    244     | @svar{decimal @var{R}}
    245 
    246 @svar{decimal 10} @expansion{} @svar{uinteger 10} @svar{suffix}
    247     | @code{.} @atleastone{@svar{digit 10}} @svar{suffix}
    248     | @atleastone{@svar{digit 10}} @code{.} @arbno{@svar{digit 10}}
    249       @svar{suffix}
    250 
    251 @svar{uinteger @var{R}} @expansion{} @atleastone{@svar{digit @var{R}}}
    252 
    253 @svar{prefix @var{R}} @expansion{} @svar{radix @var{R}} @svar{exactness}
    254     | @svar{exactness} @svar{radix @var{R}}
    255 
    256 @svar{infnan} @expansion{} @code{+inf.0} | @code{-inf.0}
    257     | @code{+nan.0} | @code{-nan.0}
    258 
    259 @end indentedblock
    260 
    261 @sharpindex{b}
    262 @sharpindex{o}
    263 @sharpindex{x}
    264 @sharpindex{e}
    265 @sharpindex{i}
    266 
    267 @indentedblock
    268 
    269 @svar{suffix} @expansion{} @svar{empty}
    270     | @svar{exponent marker} @svar{sign} @atleastone{@svar{digit 10}}
    271 
    272 @svar{exponent marker} @expansion{} @code{e}
    273 
    274 @svar{sign} @expansion{} @svar{empty} | @code{+} | @code{-}
    275 
    276 @svar{exactness} @expansion{} @svar{empty} | @code{@hashchar{}i}
    277     | @code{@hashchar{}e}
    278 
    279 @svar{radix 2} @expansion{} @code{@hashchar{}b}
    280 
    281 @svar{radix 8} @expansion{} @code{@hashchar{}o}
    282 
    283 @svar{radix 10} @expansion{} @svar{empty} | @code{@hashchar{}d}
    284 
    285 @svar{radix 16} @expansion{} @code{@hashchar{}x}
    286 
    287 @svar{digit 2} @expansion{} @code{0} | @code{1}
    288 
    289 @svar{digit 8} @expansion{} @code{0} | @code{1} | @code{2} | @code{3}
    290     | @code{4} | @code{5} | @code{6} | @code{7}
    291 
    292 @svar{digit 10} @expansion{} @svar{digit}
    293 
    294 @svar{digit 16} @expansion{} @svar{digit 10} | @code{a} | @code{b}
    295     | @code{c} | @code{d} | @code{e} | @code{f}
    296 
    297 @end indentedblock
    298 
    299 @node External representations formal
    300 @subsection External representations
    301 
    302 @svar{Datum} is what the read procedure (@ref{Input}) successfully
    303 parses. Note that any string that parses as an @svar{expression} will
    304 also parse as a @svar{datum}.
    305 
    306 @indentedblock
    307 
    308 @svar{datum} @expansion{} @svar{simple datum} ∣ @svar{compound datum}
    309     ∣ @svar{label} @code{=} @svar{datum} ∣ @svar{label} @code{@hashchar{}}
    310 
    311 @svar{simple datum} @expansion{} @svar{boolean} ∣ @svar{number}
    312     ∣ @svar{character} ∣ @svar{string} ∣ @svar{symbol}
    313     ∣ @svar{bytevector}
    314 
    315 @svar{symbol} @expansion{} @svar{identifier}
    316 
    317 @svar{compound datum} @expansion{} @svar{list} ∣ @svar{vector}
    318     ∣ @svar{abbreviation}
    319 
    320 @svar{list} @expansion{} @code{(}@arbno{@svar{datum}}@code{)}
    321     ∣ @code{(}@atleastone{@svar{datum}} @code{.} @svar{datum}@code{)}
    322 
    323 @svar{abbreviation} @expansion{} @svar{abbrev prefix} @svar{datum}
    324 
    325 @svar{abbrev prefix} @expansion{} @code{'} ∣ @code{`} ∣ @code{,}
    326     ∣ @code{,@@}
    327 
    328 @svar{vector} @expansion{} @code{@hashchar{}(}@arbno{@svar{datum}}@code{)}
    329 
    330 @svar{label} @expansion{} @code{@hashchar{}} @svar{uinteger 10}
    331 
    332 @end indentedblock
    333 
    334 @node Expressions formal
    335 @subsection Expressions
    336 
    337 The definitions in this and the following subsections assume that all
    338 the syntax keywords defined in this report have been properly imported
    339 from their libraries, and that none of them have been redefined or
    340 shadowed.
    341 
    342 @indentedblock
    343 
    344 @svar{expression} @expansion{} @svar{identifier}@*
    345 @ @ | @svar{literal}@*
    346 @ @ | @svar{procedure call}@*
    347 @ @ | @svar{lambda expression}@*
    348 @ @ | @svar{conditional}@*
    349 @ @ | @svar{assignment}@*
    350 @ @ | @svar{derived expression}@*
    351 @ @ | @svar{macro use}@*
    352 @ @ | @svar{macro block}@*
    353 @ @ | @svar{includer}
    354 
    355 @sp 1
    356 
    357 @svar{literal} @expansion{} @svar{quotation} | @svar{self-evaluating}
    358 
    359 @svar{self-evaluating} @expansion{} @svar{boolean} | @svar{number}
    360     | @svar{vector} | @svar{character} | @svar{string} | @svar{bytevector}
    361 
    362 @svar{quotation} @expansion{} @code{'}@svar{datum}
    363     | @code{(quote} @svar{datum}@code{)}
    364 
    365 @svar{procedure call} @expansion{}
    366     @code{(}@svar{operator} @arbno{@svar{operand}}@code{)}
    367 
    368 @svar{operator} @expansion{} @svar{expression}
    369 
    370 @svar{operand} @expansion{} @svar{expression}
    371 
    372 @sp 1
    373 
    374 @svar{lambda expression} @expansion{}
    375     @code{(lambda} @svar{formals} @svar{body}@code{)}
    376 
    377 @svar{formals} @expansion{} @code{(}@arbno{@svar{identifier}}@code{)}
    378     | @svar{identifier}
    379     | @code{(}@atleastone{@svar{identifier}} @code{.}
    380         @svar{identifier}@code{)}
    381 
    382 @svar{body} @expansion{} @arbno{@svar{definition}} @svar{sequence}
    383 
    384 @svar{sequence} @expansion{} @arbno{@svar{command}} @svar{expression}
    385 
    386 @svar{command} @expansion{} @svar{expression}
    387 
    388 @sp 1
    389 
    390 @svar{conditional} @expansion{}
    391     @code{(if} @svar{test} @svar{consequent} @svar{alternate}@code{)}
    392 
    393 @svar{test} @expansion{} @svar{expression}
    394 
    395 @svar{consequent} @expansion{} @svar{expression}
    396 
    397 @svar{alternate} @expansion{} @svar{expression} | @svar{empty}
    398 
    399 @sp 1
    400 
    401 @svar{assignment} @expansion{}
    402     @code{(set!} @svar{identifier} @svar{expression}@code{)}
    403 
    404 @sp 1
    405 
    406 @c This is going to need some serious line-breaking.
    407 @svar{derived expression} @expansion{}
    408       @code{(cond }@atleastone{@svar{cond clause}}@code{)}@*
    409 @ @ | @code{(cond }@arbno{@svar{cond clause}} @code{(else}
    410         @svar{sequence})@code{)}@*
    411 @ @ | @code{(case }@svar{expression}
    412            @atleastone{@svar{case clause}}@code{)}@*
    413 @ @ | @code{(case }@svar{expression}
    414            @arbno{@svar{case clause}}
    415            @code{(else }@svar{sequence})@code{)}@*
    416 @ @ | @code{(case }@svar{expression}
    417            @arbno{@svar{case clause}}
    418            @code{(else =>} @svar{recipient})@code{)}@*
    419 @ @ | @code{(and }@arbno{@svar{test}}@code{)}@*
    420 @ @ | @code{(or }@arbno{@svar{test}}@code{)}@*
    421 @ @ | @code{(when }@svar{test} @svar{sequence}@code{)}@*
    422 @ @ | @code{(unless }@svar{test} @svar{sequence}@code{)}@*
    423 @ @ | @code{(let }(@arbno{@svar{binding spec}}) @svar{body}@code{)}@*
    424 @ @ | @code{(let }@svar{identifier} (@arbno{@svar{binding spec}})
    425         @svar{body}@code{)}@*
    426 @ @ | @code{(let* }(@arbno{@svar{binding spec}}) @svar{body}@code{)}@*
    427 @ @ | @code{(letrec }(@arbno{@svar{binding spec}}) @svar{body}@code{)}@*
    428 @ @ | @code{(letrec* }(@arbno{@svar{binding spec}}) @svar{body}@code{)}@*
    429 @ @ | @code{(let-values }(@arbno{@svar{mv binding spec}})
    430         @svar{body}@code{)}@*
    431 @ @ | @code{(let*-values }(@arbno{@svar{mv binding spec}})
    432         @svar{body}@code{)}@*
    433 @ @ | @code{(begin }@svar{sequence}@code{)}@*
    434 @ @ | @code{(do }(@arbno{@svar{iteration spec}}@code{)}
    435                (@svar{test} @svar{do result}@code{)}
    436            @arbno{@svar{command}}@code{)}@*
    437 @ @ | @code{(delay }@svar{expression}@code{)}@*
    438 @ @ | @code{(delay-force }@svar{expression}@code{)}@*
    439 @ @ | @code{(parameterize }(@arbno{(@svar{expression}
    440         @svar{expression})}@code{)} @svar{body}@code{)}@*
    441 @ @ | @code{(guard }(@svar{identifier} @arbno{@svar{cond clause}})
    442         @svar{body}@code{)}@*
    443 @ @ | @svar{quasiquotation}@*
    444 @ @ | @code{(case-lambda }@arbno{@svar{case-lambda clause}}@code{)}
    445 
    446 @sp 1
    447 
    448 @svar{cond clause} @expansion{} @code{(}@svar{test} @svar{sequence}@code{)}
    449     | @code{(}@svar{test}@code{)}
    450     | @code{(}@svar{test} @code{=>} @svar{recipient}@code{)}
    451 
    452 @svar{recipient} @expansion{} @svar{expression}
    453 
    454 @svar{case clause} @expansion{}
    455       @code{((}@arbno{@svar{datum}}@code{)} @svar{sequence}@code{)}
    456     | @code{((}@arbno{@svar{datum}}@code{) =>} @svar{recipient}@code{)}
    457 
    458 @svar{binding spec} @expansion{} @code{(}@svar{identifier}
    459       @svar{expression}@code{)}
    460 
    461 @svar{mv binding spec} @expansion{} @code{(}@svar{formals}
    462       @svar{expression}@code{)}
    463 
    464 @svar{iteration spec} @expansion{} @code{(}@svar{identifier} @svar{init}
    465      @svar{step}@code{)}
    466    | @code{(}@svar{identifier} @svar{init}@code{)}
    467 
    468 @svar{case-lambda clause} @expansion{} @code{(}@svar{formals}
    469      @svar{body}@code{)}
    470 
    471 @svar{init} @expansion{} @svar{expression}
    472 
    473 @svar{step} @expansion{} @svar{expression}
    474 
    475 @svar{do result} @expansion{} @svar{sequence} | @svar{empty}
    476 
    477 @sp 1
    478 
    479 @svar{macro use} @expansion{} @code{(}@svar{keyword}
    480       @arbno{@svar{datum}}@code{)}
    481 
    482 @svar{keyword} @expansion{} @svar{identifier}
    483 
    484 @svar{macro block} @expansion{}
    485       @code{@code{(}let-syntax }@code{(}@arbno{@svar{syntax spec}}@code{)}
    486         @svar{body}@code{)}
    487     | @code{(letrec-syntax }@code{(}@arbno{@svar{syntax spec}}@code{)}
    488         @svar{body}@code{)}
    489 
    490 @svar{syntax spec} @expansion{} @code{(}@svar{keyword}
    491       @svar{transformer spec}@code{)}
    492 
    493 @sp 1
    494 
    495 @svar{includer} @expansion{}
    496    | @code{(include }@atleastone{@svar{string}}@code{)}
    497    | @code{(include-ci }@atleastone{@svar{string}}@code{)}
    498 
    499 @end indentedblock
    500 
    501 @node Quasiquotations
    502 @subsection Quasiquotations
    503 
    504 The following grammar for quasiquote expressions is not context-free.
    505 It is presented as a recipe for generating an infinite number of
    506 production rules. Imagine a copy of the following rules for @var{D} =
    507 1, 2, 3, @dots{}, where @var{D} is the nesting depth.
    508 
    509 @indentedblock
    510 @svar{quasiquotation} @expansion{} @svar{quasiquotation 1}
    511 
    512 @svar{qq template 0} @expansion{} @svar{expression}
    513 
    514 @svar{quasiquotation @var{D}} @expansion{}
    515       @code{`}@svar{qq template @var{D}}
    516     | @code{(quasiquote }@svar{qq template @var{D}}@code{)}
    517 
    518 @svar{qq template @var{D}} @expansion{} @svar{simple datum}
    519     | @svar{list qq template @var{D}}
    520     | @svar{vector qq template @var{D}}
    521     | @svar{unquotation @var{D}}
    522 
    523 @svar{list qq template @var{D}} @expansion{}
    524       @code{(}@arbno{@svar{qq template or splice @var{D}}}@code{)}
    525     | @code{(}@atleastone{@svar{qq template or splice @var{D}}} @code{.}
    526         @svar{qq template @var{D}}@code{)}
    527     | @code{'}@svar{qq template @var{D}}
    528     | @svar{quasiquotation @var{D}+1}
    529 
    530 @svar{vector qq template @var{D}} @expansion{}
    531       @code{@hashchar{}(}@arbno{@svar{qq template or
    532         splice @var{D}}}@code{)}
    533 
    534 @svar{unquotation @var{D}} @expansion{}
    535       @code{,}@svar{qq template @var{D}@minus{}1}
    536     | @code{(unquote }@svar{qq template @var{D}@minus{}1}@code{)}
    537 
    538 @svar{qq template or splice @var{D}} @expansion{}
    539       @svar{qq template @var{D}}
    540     | @svar{splicing unquotation @var{D}}
    541 
    542 @svar{splicing unquotation @var{D}} @expansion{}
    543       @code{,@@}@svar{qq template @var{D}@minus{}1}
    544     | @code{(unquote-splicing }@svar{qq template @var{D}@minus{}1})
    545 
    546 @end indentedblock
    547 
    548 In @svar{quasiquotation}s, a @svar{list qq template @var{D}} can
    549 sometimes be confused with either an @svar{unquotation @var{D}} or a
    550 @svar{splicing unquotation @var{D}}.
    551 
    552 The interpretation as an @svar{unquotation} or
    553 @svar{splicing unquotation @var{D}} takes precedence.
    554 
    555 @node Transformers
    556 @subsection Transformers
    557 
    558 Note: Though this grammar does not say so, a top-level
    559 @code{syntax-rules} pattern must be a list pattern, not a vector
    560 pattern or an identifier pattern.
    561 
    562 @indentedblock
    563 
    564 @svar{transformer spec} @expansion{}
    565       @code{(syntax-rules }(@arbno{@svar{identifier}}@code{)}
    566         @arbno{@svar{syntax rule}}@code{)}
    567     | @code{(syntax-rules }@svar{identifier}
    568         @code{(}@arbno{@svar{identifier}}@code{)}
    569         @arbno{@svar{syntax rule}}@code{)}
    570 
    571 @svar{syntax rule} @expansion{}
    572       @code{(}@svar{pattern} @svar{template}@code{)}
    573 
    574 @svar{pattern} @expansion{} @svar{pattern identifier}@*
    575 @ @ | @svar{underscore}@*
    576 @ @ | @code{(}@arbno{@svar{pattern}}@code{)}@*
    577 @ @ | @code{(}@atleastone{@svar{pattern}} @code{.} @svar{pattern}@code{)}@*
    578 @ @ | @code{(}@arbno{@svar{pattern}} @svar{pattern} @svar{ellipsis}
    579         @arbno{@svar{pattern}}@code{)}@*
    580 @ @ | @code{(}@arbno{@svar{pattern}} @svar{pattern} @svar{ellipsis}
    581         @arbno{@svar{pattern}} @code{.} @svar{pattern}@code{)}@*
    582 @ @ | @code{@hashchar{}(}@arbno{@svar{pattern}}@code{)}@*
    583 @ @ | @code{@hashchar{}(}@arbno{@svar{pattern}} @svar{pattern}
    584         @svar{ellipsis} @arbno{@svar{pattern}}@code{)}@*
    585 @ @ | @svar{pattern datum}
    586 
    587 @svar{pattern datum} @expansion{} @svar{string}
    588     | @svar{character}
    589     | @svar{boolean}
    590     | @svar{number}
    591     | @svar{bytevector}
    592 
    593 @svar{template} @expansion{} @svar{pattern identifier}
    594     | @code{(}@arbno{@svar{template element}}@code{)}
    595     | @code{(}@atleastone{@svar{template element}} @code{.}
    596         @svar{template}@code{)}
    597     | @code{@hashchar{}(}@arbno{@svar{template element}}@code{)}
    598     | @svar{template datum}
    599 
    600 @svar{template element} @expansion{} @svar{template}
    601     | @svar{template} @svar{ellipsis}
    602 
    603 @svar{template datum} @expansion{} @svar{pattern datum}
    604 
    605 @c Don't use @dots{} for the ellipsis identifier; this will emit an
    606 @c ellipsis character in most output formats, which is wrong here.
    607 @svar{pattern identifier} @expansion{}
    608       @svar{any identifier except @code{...}}
    609 
    610 @svar{ellipsis} @expansion{} @svar{an identifier defaulting to @code{...}}
    611 
    612 @svar{underscore} @expansion{} @svar{the identifier @code{_}}
    613 
    614 @end indentedblock
    615 
    616 @node Programs and definitions
    617 @subsection Programs and definitions
    618 
    619 @indentedblock
    620 
    621 @svar{program} @expansion{}
    622    @atleastone{@svar{import declaration}}
    623    @atleastone{@svar{command or definition}}
    624 
    625 @svar{command or definition} @expansion{} @svar{command}
    626     | @svar{definition}
    627     | @code{(begin }@atleastone{@svar{command or definition}}@code{)}
    628 
    629 @svar{definition} @expansion{}
    630       @code{(define }@svar{identifier} @svar{expression}@code{)}@*
    631 @ @ | @code{(define }(@svar{identifier} @svar{def formals}@code{)}
    632         @svar{body}@code{)}@*
    633 @ @ | @svar{syntax definition}@*
    634 @ @ | @code{(define-values }@svar{formals} @svar{body}@code{)}@*
    635 @ @ | @code{(define-record-type }@svar{identifier}
    636         @svar{constructor} @svar{identifier}
    637         @arbno{@svar{field spec}}@code{)}@*
    638 @ @ | @code{(begin }@arbno{@svar{definition}}@code{)}
    639 
    640 @svar{def formals} @expansion{} @arbno{@svar{identifier}}
    641     | @arbno{@svar{identifier}} @code{.} @svar{identifier}
    642 
    643 @svar{constructor} @expansion{}
    644       @code{(}@svar{identifier} @arbno{@svar{field name}}@code{)}
    645 
    646 @svar{field spec} @expansion{}
    647       @code{(}@svar{field name} @svar{accessor}@code{)}
    648     | @code{(}@svar{field name} @svar{accessor} @svar{mutator}@code{)}
    649 
    650 @svar{field name} @expansion{} @svar{identifier}
    651 
    652 @svar{accessor} @expansion{} @svar{identifier}
    653 
    654 @svar{mutator} @expansion{} @svar{identifier}
    655 
    656 @svar{syntax definition} @expansion{}
    657     @code{(define-syntax }@svar{keyword} @svar{transformer spec}@code{)}
    658 
    659 @end indentedblock
    660 
    661 @node Libraries formal
    662 @subsection Libraries
    663 
    664 @indentedblock
    665 
    666 @svar{library} @expansion{}
    667       @code{(define-library }@svar{library name}
    668         @arbno{@svar{library declaration}}@code{)}
    669 
    670 @svar{library name} @expansion{}
    671       @code{(}@atleastone{@svar{library name part}}@code{)}
    672 
    673 @svar{library name part} @expansion{} @svar{identifier}
    674     | @svar{uinteger 10}
    675 
    676 @svar{library declaration} @expansion{}
    677       @code{(export }@arbno{@svar{export spec}}@code{)}@*
    678 @ @   | @svar{import declaration}@*
    679 @ @   | @code{(begin }@arbno{@svar{command or definition}}@code{)}@*
    680 @ @   | @svar{includer}@*
    681 @ @   | @code{(include-library-declarations}
    682           @atleastone{@svar{string}}@code{)}@*
    683 @ @   | @code{(cond-expand}
    684           @atleastone{@svar{cond-expand clause}}@code{)}@*
    685 @ @   | @code{(cond-expand}
    686           @atleastone{@svar{cond-expand clause}}
    687           @code{(else }@arbno{@svar{library declaration}})@code{)}
    688 
    689 @svar{import declaration} @expansion{}
    690       @code{(import }@atleastone{@svar{import set}}@code{)}
    691 
    692 @svar{export spec} @expansion{} @svar{identifier}
    693    | @code{(rename }@svar{identifier} @svar{identifier}@code{)}
    694 
    695 @svar{import set} @expansion{} @svar{library name}@*
    696 @ @ | @code{(only }@svar{import set}
    697        @atleastone{@svar{identifier}}@code{)}@*
    698 @ @ | @code{(except }@svar{import set}
    699        @atleastone{@svar{identifier}}@code{)}@*
    700 @ @ | @code{(prefix }@svar{import set} @svar{identifier}@code{)}@*
    701 @ @ | @code{(rename }@svar{import set}
    702        @atleastone{(@svar{identifier} @svar{identifier})}@code{)}
    703 
    704 @svar{cond-expand clause} @expansion{}
    705    (@svar{feature requirement} @arbno{@svar{library declaration}}@code{)}
    706 
    707 @svar{feature requirement} @expansion{} @svar{identifier}
    708 @ @ | @code{(library }@svar{library name}@code{)}@*
    709 @ @ | @code{(and }@arbno{@svar{feature requirement}}@code{)}@*
    710 @ @ | @code{(or }@arbno{@svar{feature requirement}}@code{)}@*
    711 @ @ | @code{(not }@svar{feature requirement}@code{)}
    712 
    713 @end indentedblock