PlanetMath (more info)
 Math for the people, by the people. Sponsor PlanetMath
Encyclopedia | Requests | Forums | Docs | Wiki | Random | RSS  
Login
create new user
name:
pass:
forget your password?
Main Menu
Owner confidence rating: Very high Entry average rating: Very high
[parent] context-free language (Definition)

A context-free language is a language over some alphabet that can be generated from a particular kind of a grammar known as a context-free grammar.

Formally, a context-free grammar is a formal grammar $G=(\Sigma, N, P, \sigma)$ whose productions in $P$ have the form $$X\to w,$$ where $X\in N$ and $w\in \Sigma^*$ . A context-free language is the formal language $L(G)$ generated by a context-free grammar $G$ . In other words, $$L(G):=\lbrace v\in T^*\mid \sigma\stackrel{*}{\to} v\rbrace,$$ where $T:=\Sigma-N$ is the set of terminals, and $\sigma\stackrel{*}{\to}v$ simply means that the productions in $P$ are applied a finite number of times to the starting symbol $\sigma$ so that $v$ is reached in the end.

This formal definition is not initially very enlightening. As an example, consider typical infix arithmetic notation. An expression typically consists of one or more terms, joined together by operators with varying precedence. Parentheses can be used to override operator precedence. This syntax is a context-free language. Let us describe such expressions with the operators + and - with lowest precedence, and * and / with highest precedence, where all operators are left-associative and the only other allowed symbols are integer literals and parentheses.

\begin{eqnarray} T & := & \left\{\verb.0., \verb.1., \verb.2., \verb.3., \verb.4., \verb.5., \verb.6., \verb.7., \verb.8., \verb.9., \verb.(., \verb.)., \verb.+., \verb.-., \verb.*., \verb./. \right\} \nonumber \\ N & := & \left\{ S, A, B, C, D \right\} \nonumber \\ P & := & \{ (S, A), (S, S\verb.+.A), (S, S\verb.-.A), \nonumber \\ && (A, B), (A, A\verb.*.B), (A, A\verb./.B), \nonumber \\ && (B, C), (B, \verb.(.S\verb.).), \nonumber (C, D), (C, CD), \nonumber \\ & & (D, \verb.0.), (D, \verb.1.), (D, \verb.2.), (D, \verb.3.), (D, \verb.4.), (D, \verb.5.), (D, \verb.6.), (D, \verb.7.), (D, \verb.8.), (D, \verb.9.) \} \nonumber \\ \sigma & := & S \nonumber \end{eqnarray} It can be shown that the languages of the classical propositional logic and predicate logic are both context-free.

Context-free grammars are also known as Type-2 grammars in the Chomsky hierarchy. The Chomsky hierarchy specifies Type-2 grammars as consisting only of production rules of the form $A \to \gamma$ , where $A$ is a non-terminal and $\gamma$ is a string of terminals and non-terminals.

Remarks.

  1. A context-free grammar can be represented by a pushdown automaton. The automaton serves both as an acceptor for the language (that is, it can decide whether or not any arbitrary sentence is in the language) and as a generator for the language (that is, it can generate any finite sentence in the language in finite time).
  2. The syntaxes of most programming languages are context-free grammars (or very close to it). A very useful subset of context-free languages are regular languages.
  3. A context-free grammar $G$ is context-sensitive if none of its productions has the form $X\to \lambda$ , where $\lambda$ is the empty word.
  4. The family of context-free languages has the following closure properties: union, concatenation, Kleene star, homomorphism, inverse homomorphism, reversal, and intersection with a regular language. However, it is not closed under intersection, set difference, and complementation.

Bibliography

1
S. Ginsburg The Mathematical Theory of Context-Free Languages. McGraw-Hill, New York (1966).




"context-free language" is owned by CWoo. [ full author list (3) | owner history (2) ]
(view preamble | get metadata)

View style:

See Also: language, regular language, deterministic finite automaton, non-deterministic finite automaton, non-deterministic pushdown automaton, context-sensitive language, deterministic pushdown automaton

Other names:  type-2 language, type-2 grammar
Also defines:  context-free, context-free grammar
Keywords:  syntax, grammar, formal language, Chomsky

This object's parent.

Attachments:
Chomsky normal form (Definition) by rspuzio
Backus-Naur form (Definition) by CWoo
leftmost derivation (Definition) by CWoo
Greibach normal form (Definition) by CWoo
Chomsky-Schützenberger theorem (Theorem) by CWoo
Parikh's theorem (Theorem) by CWoo
derivation tree (Definition) by CWoo
Log in to rate this entry.
(view current ratings)

Cross-references: set difference, closed under, intersection, reversal, inverse, homomorphism, Kleene star, concatenation, union, closure properties, empty word, context-sensitive, regular languages, subset, useful, generate, generator, sentence, decide, acceptor, automaton, pushdown automaton, string, non-terminal, Chomsky hierarchy, logic, predicate, propositional logic, literals, integer, syntax, operator precedence, operators, terms, expression, infix arithmetic, starting symbol, number, finite, terminals, generated by, formal language, productions, formal grammar, alphabet, language
There are 38 references to this entry.

This is version 30 of context-free language, born on 2002-02-23, modified 2009-08-19.
Object id is 2546, canonical name is ContextFreeLanguage.
Accessed 25680 times total.

Classification:
AMS MSC68Q45 (Computer science :: Theory of computing :: Formal languages and automata)
 68Q42 (Computer science :: Theory of computing :: Grammars and rewriting systems)

Pending Errata and Addenda
None.
[ View all 11 ]
Discussion
Style: Expand: Order:
forum policy
theorem about single-character language? by MaXxX on 2002-12-04 16:58:53
I can't find it anywhere - the proof for the theorem that a CFG over a single-character alphabet is regular... Can anyone help..?
[ reply | up ]

Interact
post | correct | update request | add derivation | add example | add (any)