Properties of ContextFree Languages  Examples
CS390, Spring 2020
Abstract
Practice designing and working with CFLs and with more advanced manipulations of CFGs.
1 Prove this Language is ContextFree
\[ L = \{ a^ib^ia^jb^j  i, j \geq 0\} \]
2 Prove this Language is Not ContextFree
\[ L = \{ a^ib^ia^ib^i \} \]
(Hint: This type of problem is often addressed via the pumping lemma.)
3 Converting to CNF
Consider this grammar for expressions with properly nested parentheses & brackets.
\[ \begin{align} S &\rightarrow SA  SB  \epsilon \\ A &\rightarrow ( S )  S  E \\ B &\rightarrow [ S ]  E \\ E &\rightarrow x \\ \end{align} \]
A discussion of what this grammar “means” and how to read it:
There are 4 steps in converting a grammar to Chomsky Normal Form.
See if you can do each of them in turn:

Eliminate the $\epsilon$ productions.
Rewrite the grammar so that all productions that can derive the empty string are removed.
Reveal 
Eliminate unit productions
Rewrite the grammar to remove all productions where the entire righthandside consists of a single variable.
Reveal 
Eliminate useless variables and their productions.
Rewrite the grammar to eliminate any useless variables (variables that can never be derived or that will never generate a terminal).
Reveal 
Factor the long productions to get them into the form $A \rightarrow a$ or $A \rightarrow B C$
Reveal
4 CYK parsing
Parse the string ([x])(x)
using the grammar:
\[ \begin{align} S &\rightarrow SA  C D  C E  x  SB  F G  F H \\ A &\rightarrow C D  C E  SA  x  SB  F G  F H \\ B &\rightarrow F G  F H  x \\ C &\rightarrow ( \\ D &\rightarrow S E \\ E &\rightarrow ) \\ F &\rightarrow [ \\ G &\rightarrow S H \\ H &\rightarrow ] \\ \end{align} \]