Here are two statements that are true about context-free grammars:
- The union of context-free languages is context-free.
- You can't decide whether a context-free language accepts all strings.
The clever part of the proof is showing that the following is also true:
If $G$ is any context-free grammar, you can make two new languages $G_1$ and $G_2$ based on $G$ with the following properties:
3a. $G_1$ and $G_2$ are context-free.
3b. If $G$ accepts all strings, then $G_1\cup G_2$ is regular. Otherwise, $G_1\cup G_2$ is non-regular.
I won't explain the definition of $G_1$ and $G_2$ in detail; just ask you to accept their properties for now.
Taking these statements as given, the proof is intuitively like this:
- Assume you have the power to decide whether any context-free language is regular.
- Given any grammar $G$, form the grammars $G_1$ and $G_2$ using the procedure in (3).
- By (3a), $G_1$ and $G_2$ are context-free.
- So, by (1), their union $G_1 \cup G_2$ is context free.
- By your assumption, you have the power to decide whether $G_1\cup G_2$ is regular.
- By construction (3b), $G_1\cup G_2$ is regular if and only if $G$ accepts all strings.
- Therefore, you have the power to decide whether any context-free language $G$ accepts all strings.
- This is impossible, per (2). So the assumption was wrong—you can't actually decide whether any context-free language is regular.
- The problem of deciding regularity for CFLs is undecidable, Q.E.D.
Please note
Please note that the properties (1) and (2) don't directly imply that the problem is undecidable. Instead, we had a clever construction (3) that used those properties to help show a contradiction. If we had invented a different construction than the one in (3), we might have used different properties than (1) or (2).