[Overview] [Previous] [Next]
Example CFGs
Example 1
We have shown that L = {anbn: n
0} is not regular. Here is a context-free grammar for this language.
G = ({S}, {a, b}, S, {S
aSb,
S
}
Example 2
We have shown that L = {anbk: k > n
0} is not regular. Here is a context-free grammar for this language.
G = ({S, B}, {a, b}, S, {S
aSb,
S
B, B
bB,
B
b}).
Example 3
The language L = {wwR: w
{a, b}*}, where each string in L is a palindrome, is not regular. Here is a context-free
grammar for this language.
G = ({S}, {a, b}, S, {S
aSa,
S
bSb, S
}).
Copyright © 1996 by David Matuszek
Last modified Feb 26, 1996