Definition
Context-Free Grammar
A grammar is called context-free if every production rule in is context-free.
Equivalently: A language is called context-free there exists a pushdown automaton that accepts it.
Production
Equivalence
All production variants below yield the same generated language.
Leftmost Production
Leftmost production is process of iteratively replacing the leftmost non-terminal symbol by applying the respective production rules.
Rightmost Production
Rightmost production is process of iteratively replacing the rightmost non-terminal symbol by applying the respective production rules.
Parallel Production
Parallel production is process of iteratively replacing the all non-terminal symbols by applying the respective production rules.
Trees
A context-free grammar can also be represented by a derivation tree. The front of the tree is the word obtained by reading the leaf labels from left to right.
Derivation tree for
Consider the context-free grammar
A derivation tree for is:
The front of the tree is the word obtained by reading the leaf labels from left to right.
Examples
Grammar for
Consider the context-free grammar
where the production rules are
Then, for example,
A production is:
Palindrome over
Even length with middle separator
Grammar from Language
Let be
The context-free grammar for is given by
where and are defined as:
For instance, can be derived as follows: