A context-free grammar is a notation for describing languages.
It is more powerful than finite automata or RE’s, but still cannot define all possible languages.
Useful for nested structures, e.g., parentheses in programming languages.
<aside> 💡 Basic Idea: use “variables” to stand for sets of strings
$$ G = (V,T,P,S) $$
Convention
- A, B, C,… and also S are variables.
- a, b, c,… are terminals.
- …, X, Y, Z are either terminals or variables.
- …, w, x, y, z are strings of terminals only.
- $\alpha$, $\beta$, $\gamma$,… are strings of terminals and/or variables.
We say $\alpha A\beta \Rightarrow \alpha \gamma \beta$, if $A \rightarrow \gamma$ is a production