Appendix D. The grammar of CSS2

The grammar below defines the syntax of CSS2. It is in some sense,
however, a superset of CSS2 as this specification imposes additional
semantic constraints not expressed in this grammar. A conforming UA
must also adhere to the
forward-compatible parsing rules, the property and value notation,
and the unit notation. In
addition, the document language may impose restrictions, e.g. HTML
imposes restrictions on the possible values of the "class" attribute.

The grammar below is LL(1) (but note that most UA's should not use it
directly, since it doesn't express the parsing conventions, only the
CSS2 syntax). The format of the productions is optimized for human
consumption and some shorthand notation beyond Yacc (see [YACC]) is
used:

The following is the tokenizer, written in Flex (see [FLEX])
notation. The tokenizer is case-insensitive.

The two occurrences of "\377" represent the highest character
number that current versions of Flex can deal with (decimal 255). They
should be read as "\4177777" (decimal 1114111), which is the highest
possible code point in Unicode/ISO-10646.

There are some differences in the syntax specified in the CSS1
recommendation ([CSS1]), and the one above. Most of these are due
to new tokens in CSS2 that didn't exist in CSS1. Others are because
the grammar has been rewritten to be more readable. However, there are
some incompatible changes, that were felt to be errors in the CSS1
syntax. They are explained below.

CSS1 style sheets could only be in 1-byte-per-character
encodings, such as ASCII and ISO-8859-1. CSS2 has no such
limitation. In practice, there was little difficulty in extrapolating
the CSS1 tokenizer, and some UAs have accepted 2-byte encodings.

CSS1 only allowed four hex-digits after the backslash (\) to refer
to Unicode characters, CSS2 allows six. Furthermore,
CSS2 allows a whitespace character to delimit the escape
sequence. E.g., according to CSS1, the string "\abcdef" has 3 letters
(\abcd, e, and f), according to CSS2 it has only one (\abcdef).

The tab character (ASCII 9) was not allowed in strings. However,
since strings in CSS1 were only used for font names and for URLs, the
only way this can lead to incompatibility between CSS1 and CSS2 is if
a style sheet contains a font family that has a tab in its name.

CSS2 parses a number immediately followed by an identifier as a
DIMEN token (i.e., an unknown unit), CSS1 parsed it as a number and an
identifier. That means that in CSS1, the declaration 'font:
10pt/1.2serif' was correct, as was 'font: 10pt/12pt serif'; in CSS2, a
space is required before "serif". (Some UAs accepted the first
example, but not the second.)

In CSS1, a class name could start with a digit (".55ft"), unless
it was a dimension (".55in"). In CSS2, such classes are parsed as
unknown dimensions (to allow for future additions of new units). To
make ".55ft" a valid class, CSS2 requires the first digit to be
escaped (".\55ft")