Appendix
B. GIF Grammar.

A Grammar is a form of notation to represent the sequence in which certain
objects form larger objects.  A grammar is also used to represent the number of
objects that can occur at a given position.  The grammar given here represents
the sequence of blocks that form the GIF Data Stream. A grammar is given by
listing its rules.  Each rule consists of the left-hand side, followed by some
form of equals sign, followed by the right-hand side.  In a rule, the
right-hand side describes how the left-hand side is defined. The right-hand
side consists of a sequence of entities, with the possible presence of special
symbols. The following legend defines the symbols used in this grammar for GIF.

Legend:
                  <>    grammar word
                  ::=   defines symbol
                  *     zero or more occurrences
                  +     one or more occurrences
                  |     alternate element
                  []    optional element

Example:

<GIF Data Stream> ::= Header <Logical Screen> <Data>* Trailer

This rule defines the entity <GIF Data Stream> as follows. It must begin with a
Header. The Header is followed by an entity called Logical Screen, which is
defined below by another rule. The Logical Screen is followed by the entity
Data, which is also defined below by another rule. Finally, the entity Data is
followed by the Trailer.  Since there is no rule defining the Header or the
Trailer, this means that these blocks are defined in the document.  The entity
Data has a special symbol (*) following it which means that, at this position,
the entity Data may be repeated any number of times, including 0 times. For
further reading on this subject, refer to a standard text on Programming
Languages.


The Grammar.

<GIF Data Stream>         ::= Header <Logical Screen> <Data>* Trailer

<Logical Screen>          ::= Logical Screen Descriptor [Global Color Table]

<Data>                    ::= <Graphic Block> | <Special-Purpose Block>

<Graphic Block>           ::= [Graphic Control Extension] <Graphic-Rendering Block>

<Graphic-Rendering Block> ::= <Table-Based Image> | Plain Text Extension

<Table-Based Image>       ::= Image Descriptor [Local Color Table] Image Data

<Special-Purpose Block>   ::= Application Extension  | Comment Extension