Final Lecture

Closure of CFLs

We know that CFLs are closed under the regular operations (closure properties)

Q: But, how can we prove it?

A: We can construct CFGs or PDAs for them.

Suppose two CFLs, S_1 and S_2

Union:

S \to S_1 | S_2 \\

Concatenation:

S \to S_1 S_2

Star:

S \to \epsilon | S S_1

When is a Language Context-Free?

When a variable in a different context yields a different result.

aV \to ab \\ Vc \to de

For this class, since we don’t know any formal method, we roll with reasoning about the PDA’s stack.

  1. If the language cannot be done without reaching deeper into the stack, like:
  2. If language has no stack pattern, like:

tl;dr, If you can’t describe the language as “pop as like this and pop bs like that”, it’s not context-free.

Examples

\{ a^n b^{n+2} a^n \}

The last a cannot be

Are all NFAs PDAs?

Yes, just ignore the stack (e.g., a, \epsilon \to \epsilon)

Final Diagram

image