Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words

Lecture 5 min.



The Chomsky hierarchy is a classification of formal languages and formal grammars, according to which they are divided into 4 types by their relative complexity. It was proposed by Noam Chomsky, a linguist and professor at the Massachusetts Institute of Technology.

Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words

Classification of grammars

According to Chomsky, formal grammars can be divided into four types. For a grammar to be assigned to one type or another, all of its rules (productions) must conform to certain schemes.

Type 0 — unrestricted

A phrase-structure grammar G is an algebraic structure, an ordered quadruple (VT, VN, P, S), where :

  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words — the alphabet (set) of terminal symbols, or terminals,
  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words — the alphabet (set) of nonterminal symbols, or nonterminals,
  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words — the vocabulary Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, where Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words
  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words — the finite set of productions (rules) of the grammar, Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words
  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words — the start symbol (source).

Here Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words is the set of all strings over the alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, and Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words is the set of nonempty strings over the alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words.

Type 0 in the Chomsky classification comprises unrestricted grammars — phrase-structure grammars, that is, all formal grammars without exception. The rules can be written in the form:

Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words,

where Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words is any nonempty string containing at least one nonterminal symbol, and Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words is any string of symbols from the alphabet.

Because of their complexity, such grammars have no practical application.

Type 1 — context-sensitive

This type includes context-sensitive (CS) grammars and non-contracting grammars. For a grammar Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words all rules have the form :

  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, where Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words. Such grammars are classified as context-sensitive.
  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, where Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words. Such grammars are classified as non-contracting.

These classes of grammars are equivalent. They can be used in the analysis of natural-language texts, but they are practically never used in building compilers because of their complexity. For context-sensitive grammars the following statement has been proved: by some algorithm it is possible to determine in a finite number of steps whether a string of terminal symbols belongs to the given language or not.

Type 2 — context-free

This type includes context-free (CF) grammars. For a grammar Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words all rules have the form:

  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, where Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words (for non-contracting CF grammars) or Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words (for contracting ones), Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words. That is, the grammar allows only a nonterminal symbol to appear on the left-hand side of a rule.

CF grammars are widely used to describe the syntax of computer languages (see parsing).

Type 3 — regular

The third type comprises regular grammars (finite-state grammars), the simplest of the formal grammars. They are context-free, but with limited capabilities.

All regular grammars can be divided into two equivalent classes, which for a grammar of type III have rules of the following form:

  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words or Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, where Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words (for left-linear grammars).
  • Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words; or Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, where Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words (for right-linear grammars).

Regular grammars are used to describe the simplest constructs: identifiers, strings, constants, as well as assembly languages, command processors, and so on.

Classification of languages

Formal languages are classified according to the types of grammars that generate them. However, the same language can be generated by different grammars belonging to different types. In that case, the language is considered to belong to the simplest of them. Thus, a language described by a phrase-structure grammar, a context-sensitive grammar and a context-free grammar will be context-free.

As with grammars, the complexity of a language is determined by its type. The most complex are phrase-structure languages (natural languages can be included here), followed by CS languages, CF languages, and, the simplest of all, regular languages.

Hierarchy of languages, grammars and automata:

Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words

Alphabet of a formal language

The alphabet of a formal language is the set of atomic (indivisible) symbols of that formal language (sometimes called letters, by analogy with the alphabets of natural languages, or symbols). Words are built from the symbols of the alphabet of a formal language, and the admissible expressions of the language are specified by a formal grammar.

Most often an alphabet is considered to be a nonempty finite set. For example, the alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words underlies Morse code, and the alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words is the generally accepted set of symbols for representing information in computers. Musical notation symbols and digits are also examples of finite alphabets. In some cases infinite alphabets are also considered, for example the set of natural numbers Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, the simplest example of a countable alphabet (although natural numbers can also be regarded as words over the finite alphabet of digits).

The concept of the alphabet of a formal language is widely used in linguistics (in the branches that study formal grammars), mathematical logic (above all model theory), automata theory, artificial intelligence (including computational linguistics), and computer science (in particular, the theory of programming languages). Certain theoretical problems of constructing words and expressions of formal languages over alphabets are studied by means of general algebra and combinatorics.

Word of a formal language

A word of a formal language (also string, chain) is an arbitrary sequence of symbols from a given alphabet. The number of symbols in a word Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words is called its length and is denoted Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words. The existence of a single word of length 0 (the empty word), containing no symbols at all, may be permitted (denoted Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words, Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words or Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words).

The set of all words of length Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words over the alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words is denoted by Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words; over a finite alphabet the number of such words is exactly the size of the alphabet raised to the power Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words (Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words). The set of all words over the alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words (of arbitrary length) is denoted by Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words (the Kleene star), so that:

Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words

On words over a given alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words the operation of concatenation is defined — the sequential joining of words. The set of all words over the alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words with the operation of concatenation forms a monoid (the free monoid[en]). The set of all nonempty words over the alphabet Formal Languages and Formal Grammars: The Chomsky Hierarchy, Alphabet and Words with the operation of concatenation forms a semigroup.

See also

  • [[b8374]]

See also

created: 2021-04-17
updated: 2026-09-29
251



Was this answer useful?
Choose a quick rating so we can improve the next answer for you.
How satisfied are you?


Comments

To leave a comment

If you have any suggestion, idea, thanks or comment, feel free to write. We really value feedback and are glad to hear your opinion.
To reply

Lectures and tutorial on "Computational linguistics"

Terms: Computational linguistics