A formal language is a set of finite strings over an alphabet. The alphabet specifies the symbols from which the strings are built. The strings belonging to the language are also called words.
A formal language may be specified by formation rules that determine which strings are well-formed. Such rules can give initial expressions and specify how to build further expressions from those already constructed. In this case, only expressions obtained by applying the rules belong to the language.
For example, the language of propositional calculus could be defined as follows. The alphabet
of this language is comprised of English letters with
optional indexes and the following special symbols: (NOT),
(AND),
(OR),
(implies), and
(grouping). The formation rules are then that every English
letter and every letter with
an index is a sentential formula, and if
and
are sentential formulas,
then so are
,
,
,
, and
.
Grammars specify languages through productions. A regular language can also be specified by a regular expression.
The formation rules of propositional calculus and most other formation rules can be straightforwardly transformed into grammar
productions. For example, the formation rule becomes the production
, where
is the start symbol.