The basic technique of defining an expression editor grammar is to define individual tokens and literals that represent building blocks of the desired expression language, and compose them into larger structures made up of sequence and choice elements. These structures can in turn be composed into still more complex sequences and choices, and so on.

Because tokens and literals cannot be decomposed into smaller pieces, they are called terminal constructs (as in the terminal branches of a tree). Sequences and choices are nonterminals.

An expression grammar usually has a single top-level construct whose contained sequences and choices represent all possible expressions in the grammar.

Let’s return to our earlier example grammar:

<?xcl-stylesheet resource="atg/ui/expreditor/xcl/grammar.xsl"?>
<sequence id="example-sequence">
  <token><description>People whose</description>
    <token value="name"/>
    <token value="email"/>
    <token value="gender"/>
    <token value="eq"><description>is</description></token>
    <token value="neq"><description>is not</description></token>

This grammar’s top level construct is given the name example-sequence, and it permits the following expressions:

People whose name is ____

People whose email is ____

People whose gender is ____

People whose name is not ____

People whose email is not ____

People whose gender is not ____

The expression editor always displays a valid expression at all times; consequently, some element of a choice must always be “chosen”. There is an initial default for each choice, which is normally the first element of the choice, but this may be overridden. Thus, in our example, the first of the above possibilities will be shown when the editor is initially displayed.