CLHS: Section 1.4.1.2.1

#

## 1.4.1.2.1 Splicing in Modified BNF Syntax

The primary extension used is the following:

[[O]]

An expression of this form appears whenever a list of elements is to be spliced into a larger structure and the elements can appear in any order. The symbol O represents a description of the syntax of some number of syntactic elements to be spliced; that description must be of the form

O1 | ... | Ol

where each Oi can be of the form S or of the form S* or of the form {S}1 . The expression [[O]] means that a list of the form

(Oi1...Oij) 1<=j

is spliced into the enclosing expression, such that if n /=m and 1<=n,m<=j, then either Oin/=Oim or Oin = Oim = Qk, where for some 1<=k <=n, Ok is of the form Qk*. Furthermore, for each Oin that is of the form {Qk}1 , that element is required to appear somewhere in the list to be spliced.

For example, the expression

`(x` [[`A` |`B`*`` |`C`]]`y)`

means that at most one `A`, any number of `B`'s, and at most one `C` can occur in any order. It is a description of any of these:

     (x y)
     (x B A C y)
     (x A B B B B B C y)
     (x C B A B B B y)

but not any of these:

     (x B B A A C C y)
     (x C B C y)

In the first case, both `A` and `C` appear too often, and in the second case `C` appears too often.

The notation [[O1 | O2 | ...]]+ adds the additional restriction that at least one item from among the possible choices must be used. For example:

`(x` [[`A` |`B`*`` |`C`]]``+`y)`

means that at most one `A`, any number of `B`'s, and at most one `C` can occur in any order, but that in any case at least one of these options must be selected. It is a description of any of these:

     (x B y)
     (x B A C y)
     (x A B B B B B C y)
     (x C B A B B B y)

but not any of these:

     (x y)
     (x B B A A C C y)
     (x C B C y)

In the first case, no item was used; in the second case, both `A` and `C` appear too often; and in the third case `C` appears too often.

Also, the expression:

`(x` [[``{`A`}1 `` |`` {`B`}1 `` |`C`]]`y)`

can generate exactly these and no others:

     (x A B C y)
     (x A C B y)
     (x A B y)
     (x B A C y)
     (x B C A y)
     (x B A y)
     (x C A B y)
     (x C B A y)

The following X3J13 cleanup issue, not part of the specification, applies to this section:

- LOOP-MISCELLANEOUS-REPAIRS:FIX

Copyright 1996-2001, Xanalys Inc. All rights reserved.